DieFeM

Cleanup Duplicated Worldspace.pas

Sep 10th, 2020
1,009
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.   Removes unique npc, preculling and location data from the duplicated worldspace.
  3. }
  4. unit CleanupDuplicatedWorldspace;
  5.  
  6. function CheckHasFlag(elem: IInterface; flagName: string): boolean;
  7. var
  8.   sl: TStringList;
  9.   i: Integer;
  10.   f, f2: Cardinal;
  11.   val: boolean;
  12. begin
  13.   val := false;
  14.   sl := TStringList.Create;
  15.   sl.Text := FlagValues(elem);
  16.   f := GetNativeValue(elem);
  17.   for i := 0 to Pred(sl.Count) do
  18.     if SameText(sl[i], flagName) then begin
  19.       f2 := f or (1 shl i);
  20.       if f = f2 then
  21.         val := true;
  22.       Break;
  23.     end;
  24.   sl.Free;
  25.   Result := val;
  26. end;
  27.  
  28. // called for every record selected in xEdit
  29. function Process(e: IInterface): integer;
  30. var
  31.   el: IInterface;
  32. begin
  33.   if Signature(e) = 'CELL' then begin
  34.     //AddMessage('Processing CELL: ' + FullPath(e));
  35.     if ElementExists(e, 'PCMB') then begin
  36.       el := ElementByPath(e, 'PCMB');
  37.       if Assigned(el) then
  38.         RemoveElement(e, el);
  39.     end;
  40.     if ElementExists(e, 'XPRI') then begin
  41.       el := ElementByPath(e, 'XPRI');
  42.       if Assigned(el) then
  43.         RemoveElement(e, el);
  44.     end;
  45.     if ElementExists(e, 'XCRI') then begin
  46.       el := ElementByPath(e, 'XCRI');
  47.       if Assigned(el) then
  48.         RemoveElement(e, el);
  49.     end;
  50.     if ElementExists(e, 'VISI') then begin
  51.       el := ElementByPath(e, 'VISI');
  52.       if Assigned(el) then
  53.         RemoveElement(e, el);
  54.     end;
  55.     if ElementExists(e, 'RVIS') then begin
  56.       el := ElementByPath(e, 'RVIS');
  57.       if Assigned(el) then
  58.         RemoveElement(e, el);
  59.     end;
  60.     if ElementExists(e, 'XLCN') then begin
  61.       el := ElementByPath(e, 'XLCN');
  62.       if Assigned(el) then
  63.         RemoveElement(e, el);
  64.     end;
  65.   end;
  66.   if Signature(e) = 'ACHR' then begin
  67.     el := LinksTo(ElementByName(e, 'NAME - Base'));
  68.     if CheckHasFlag(ElementByPath(el, 'ACBS - Configuration\Flags'), 'Unique') then begin
  69.       AddMessage('Removing: ' + Name(e));
  70.       RemoveNode(e);
  71.     end;
  72.   end;
  73.   Result := 0;
  74. end;
  75.  
  76. end.
  77.  
RAW Paste Data