-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Diagnostics; | ||
using TRGE.Core; | ||
using TRLevelControl.Model; | ||
|
||
namespace TRRandomizerCore.Processors; | ||
|
||
public class BaseTRRSequenceProcessor<E, T> | ||
where E : TREntity<T> | ||
where T : Enum | ||
{ | ||
public Func<T, bool> IsMediType { get; set; } | ||
|
||
public void AdjustMedipacks(TRRScriptedLevel levelScript, List<E> currentItems, List<E> originalItems, E dummyItem, FDControl floorData) | ||
{ | ||
// In NG+, the game will convert medipacks to ammo, but this is based on the items' indices | ||
// in the level's original slot. So we need to guarantee that the items match up in the new | ||
// slot to avoid the wrong things being converted. | ||
if (levelScript.Sequence == levelScript.OriginalSequence) | ||
{ | ||
return; | ||
} | ||
|
||
List<int> ogIndices = GetMediIndices(originalItems); | ||
Queue<int> swappableIndices = new(GetMediIndices(currentItems).Except(ogIndices)); | ||
foreach (int index in ogIndices) | ||
{ | ||
while (currentItems.Count <= index) | ||
{ | ||
currentItems.Add(dummyItem); | ||
} | ||
|
||
E entity = currentItems[index]; | ||
if (IsMediType(entity.TypeID)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (swappableIndices.Count == 0) | ||
{ | ||
swappableIndices.Enqueue(currentItems.Count); | ||
currentItems.Add(dummyItem); | ||
} | ||
int swapIndex = swappableIndices.Dequeue(); | ||
currentItems[index] = currentItems[swapIndex]; | ||
currentItems[swapIndex] = entity; | ||
|
||
floorData.GetEntityActionItems(index) | ||
.ForEach(a => a.Parameter = (short)swapIndex); | ||
} | ||
|
||
// Sanity check | ||
ogIndices.ForEach(i => Debug.Assert(currentItems[i] == dummyItem | ||
|| IsMediType(currentItems[i].TypeID))); | ||
} | ||
|
||
private List<int> GetMediIndices(List<E> items) | ||
{ | ||
return items.FindAll(e => IsMediType(e.TypeID)) | ||
.Select(e => items.IndexOf(e)) | ||
.ToList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using TRGE.Core; | ||
using TRLevelControl.Helpers; | ||
using TRLevelControl.Model; | ||
using TRRandomizerCore.Editors; | ||
using TRRandomizerCore.Levels; | ||
using TRRandomizerCore.Utilities; | ||
|
||
namespace TRRandomizerCore.Processors; | ||
|
||
public class TR1RSequenceProcessor : TR1RLevelProcessor | ||
{ | ||
private static readonly TR1Entity _dummyItem = new() | ||
{ | ||
TypeID = TR1Type.CameraTarget_N, | ||
Invisible = true, | ||
}; | ||
|
||
private BaseTRRSequenceProcessor<TR1Entity, TR1Type> _processor; | ||
|
||
public RandomizerSettings Settings { get; set; } | ||
|
||
public void Run() | ||
{ | ||
_processor = new() | ||
{ | ||
IsMediType = t => TR1TypeUtilities.IsMediType(t), | ||
}; | ||
Process(AdjustLevel); | ||
} | ||
|
||
private void AdjustLevel(TR1RCombinedLevel level) | ||
{ | ||
TRRScriptedLevel mimickedLevelScript = Levels.Find(l => l.OriginalSequence == level.Script.Sequence); | ||
TR1Level mimickedLevel = LoadLevelData(Path.Combine(BackupPath, mimickedLevelScript.LevelFileBaseName)); | ||
|
||
TR1Entity dummyItem = (TR1Entity)_dummyItem.Clone(); | ||
dummyItem.SetLocation(level.Data.Entities.Find(e => e.TypeID == TR1Type.Lara).GetLocation()); | ||
|
||
_processor.AdjustMedipacks(level.Script, level.Data.Entities, mimickedLevel.Entities, dummyItem, level.Data.FloorData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using TRGE.Core; | ||
using TRLevelControl.Helpers; | ||
using TRLevelControl.Model; | ||
using TRRandomizerCore.Editors; | ||
using TRRandomizerCore.Levels; | ||
using TRRandomizerCore.Utilities; | ||
|
||
namespace TRRandomizerCore.Processors; | ||
|
||
public class TR2RSequenceProcessor : TR2RLevelProcessor | ||
{ | ||
private static readonly TR2Entity _dummyItem = new() | ||
{ | ||
TypeID = TR2Type.CameraTarget_N, | ||
Invisible = true, | ||
}; | ||
|
||
private BaseTRRSequenceProcessor<TR2Entity, TR2Type> _processor; | ||
|
||
public RandomizerSettings Settings { get; set; } | ||
|
||
public void Run() | ||
{ | ||
_processor = new() | ||
{ | ||
IsMediType = t => TR2TypeUtilities.IsMediType(t), | ||
}; | ||
Process(AdjustLevel); | ||
} | ||
|
||
private void AdjustLevel(TR2RCombinedLevel level) | ||
{ | ||
TRRScriptedLevel mimickedLevelScript = Levels.Find(l => l.OriginalSequence == level.Script.Sequence); | ||
TR2Level mimickedLevel = LoadLevelData(Path.Combine(BackupPath, mimickedLevelScript.LevelFileBaseName)); | ||
|
||
TR2Entity dummyItem = (TR2Entity)_dummyItem.Clone(); | ||
dummyItem.SetLocation(level.Data.Entities.Find(e => e.TypeID == TR2Type.Lara).GetLocation()); | ||
|
||
_processor.AdjustMedipacks(level.Script, level.Data.Entities, mimickedLevel.Entities, dummyItem, level.Data.FloorData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters