Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classic/remastered environment tags #683

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions TRDataControl/Environment/EMEditorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,10 @@ public void AlternateTextures()
}

public void SetCommunityPatch(bool isCommunityPatch)
{
All?.SetCommunityPatch(isCommunityPatch);
ConditionalAll?.ForEach(s => s.SetCommunityPatch(isCommunityPatch));
Any?.ForEach(s => s.SetCommunityPatch(isCommunityPatch));
AllWithin?.ForEach(a => a.ForEach(s => s.SetCommunityPatch(isCommunityPatch)));
ConditionalAllWithin?.ForEach(s => s.SetCommunityPatch(isCommunityPatch));
OneOf?.ForEach(s => s.SetCommunityPatch(isCommunityPatch));
ConditionalOneOf?.ForEach(s => s.SetCommunityPatch(isCommunityPatch));
Mirrored?.SetCommunityPatch(isCommunityPatch);
}
=> Scan(e => e.SetCommunityPatch(isCommunityPatch));

public void SetRemastered(bool isRemastered)
=> Scan(e => e.SetRemastered(isRemastered));

public List<BaseEMFunction> FindAll(Predicate<BaseEMFunction> predicate = null)
{
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Environment/Helpers/EMOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class EMOptions
{
public bool EnableHardMode { get; set; }
public IEnumerable<EMTag> ExcludedTags { get; set; }
public List<EMTag> ExcludedTags { get; set; }
public EMExclusionMode ExclusionMode { get; set; }
}
2 changes: 2 additions & 0 deletions TRDataControl/Environment/Helpers/EMTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public enum EMTag
GeneralBugFix,
ShortcutFix,
KeyItemFix,
RemasteredOnly,
ClassicOnly,
}
5 changes: 4 additions & 1 deletion TRDataControl/Environment/Model/BaseEMFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class BaseEMFunction
public BaseEMFunction HardVariant { get; set; }
public List<EMTag> Tags { get; set; }

protected bool _isCommunityPatch;
protected bool _isCommunityPatch, _isRemastered;

public abstract void ApplyToLevel(TR1Level level);
public abstract void ApplyToLevel(TR2Level level);
Expand All @@ -23,6 +23,9 @@ public abstract class BaseEMFunction
public void SetCommunityPatch(bool isCommunityPatch)
=> _isCommunityPatch = isCommunityPatch;

public void SetRemastered(bool isRemasterd)
=> _isRemastered = isRemasterd;

/// <summary>
/// Gets the expected vertices for a flat tile.
/// asCeiling = true => looking up
Expand Down
92 changes: 47 additions & 45 deletions TRRandomizerCore/Randomizers/Shared/EnvironmentPicker.cs
Original file line number Diff line number Diff line change
@@ -1,94 +1,96 @@
using TRDataControl.Environment;
using TRGE.Core;
using TRRandomizerCore.Editors;
using TRRandomizerCore.Helpers;

namespace TRRandomizerCore.Randomizers;

public class EnvironmentPicker
{
private readonly Random _generator;
private readonly RandomizerSettings _settings;
private readonly TREdition _gfEdition;

public EMOptions Options { get; set; }
public Random Generator { get; set; }

public EnvironmentPicker(bool hardMode)
public EnvironmentPicker(Random generator, RandomizerSettings settings, TREdition gfEdition)
{
Options = new EMOptions
Options = new()
{
EnableHardMode = hardMode,
ExcludedTags = new List<EMTag>()
EnableHardMode = settings.HardEnvironmentMode,
ExcludedTags = new()
};
}

public void LoadTags(RandomizerSettings settings, bool isCommunityPatch)
{
List<EMTag> excludedTags = new();
if (!settings.AddReturnPaths)
_generator = generator;
_settings = settings;
_gfEdition = gfEdition;

ResetTags();

if (!_settings.AddReturnPaths)
{
excludedTags.Add(EMTag.ReturnPath);
Options.ExcludedTags.Add(EMTag.ReturnPath);
}
if (!settings.FixOGBugs)
if (!_settings.FixOGBugs)
{
excludedTags.Add(EMTag.GeneralBugFix);
Options.ExcludedTags.Add(EMTag.GeneralBugFix);
}
if (!settings.BlockShortcuts)
if (!_settings.BlockShortcuts)
{
excludedTags.Add(EMTag.ShortcutFix);
Options.ExcludedTags.Add(EMTag.ShortcutFix);
}
if (!settings.RandomizeLadders)
if (!_settings.RandomizeLadders)
{
excludedTags.Add(EMTag.LadderChange);
Options.ExcludedTags.Add(EMTag.LadderChange);
}
if (!settings.RandomizeWaterLevels)
if (!_settings.RandomizeWaterLevels)
{
excludedTags.Add(EMTag.WaterChange);
Options.ExcludedTags.Add(EMTag.WaterChange);
}
if (!settings.RandomizeSlotPositions)
if (!_settings.RandomizeSlotPositions)
{
excludedTags.Add(EMTag.SlotChange);
Options.ExcludedTags.Add(EMTag.SlotChange);
}
if (!settings.RandomizeTraps)
if (!_settings.RandomizeTraps)
{
excludedTags.Add(EMTag.TrapChange);
Options.ExcludedTags.Add(EMTag.TrapChange);
}
if (!settings.RandomizeChallengeRooms)
if (!_settings.RandomizeChallengeRooms)
{
excludedTags.Add(EMTag.PuzzleRoom);
Options.ExcludedTags.Add(EMTag.PuzzleRoom);
}
if (!settings.RandomizeItems || !settings.IncludeKeyItems)
if (!_settings.RandomizeItems || !_settings.IncludeKeyItems)
{
excludedTags.Add(EMTag.KeyItemFix);
Options.ExcludedTags.Add(EMTag.KeyItemFix);
}

// If we're using a community patch, exclude mods that
// only apply to non-community patch and vice-versa.
excludedTags.Add(isCommunityPatch
? EMTag.NonCommunityPatchOnly
: EMTag.CommunityPatchOnly);

Options.ExcludedTags = excludedTags;
}

public void ResetTags(bool isCommunityPatch)
public void ResetTags()
{
Options.ExcludedTags = new List<EMTag>
// If we're using a community patch, exclude mods that only apply to non-community patch and vice-versa.
// Same idea for classic/remastered only.
Options.ExcludedTags = new()
{
isCommunityPatch
? EMTag.NonCommunityPatchOnly
: EMTag.CommunityPatchOnly
_gfEdition.IsCommunityPatch
? EMTag.NonCommunityPatchOnly
: EMTag.CommunityPatchOnly,
_gfEdition.Remastered
? EMTag.ClassicOnly
: EMTag.RemasteredOnly
};
}

public List<EMEditorSet> GetRandomAny(EMEditorMapping mapping)
{
List<EMEditorSet> sets = new();

List<EMEditorSet> sets = new();
List<EMEditorSet> pool = Options.EnableHardMode
? mapping.Any
: mapping.Any.FindAll(e => !e.IsHard);

if (pool.Count > 0)
{
// Pick a random number of packs to apply, but at least 1
sets = pool.RandomSelection(Generator, Generator.Next(1, pool.Count + 1));
sets = pool.RandomSelection(_generator, _generator.Next(1, pool.Count + 1));
}

return sets;
Expand All @@ -99,7 +101,7 @@ public EMEditorSet GetModToRun(List<EMEditorSet> modList)
if (Options.EnableHardMode)
{
// Anything goes.
return modList[Generator.Next(0, modList.Count)];
return modList[_generator.Next(0, modList.Count)];
}

if (modList.Any(e => !e.IsHard))
Expand All @@ -108,7 +110,7 @@ public EMEditorSet GetModToRun(List<EMEditorSet> modList)
EMEditorSet set;
do
{
set = modList[Generator.Next(0, modList.Count)];
set = modList[_generator.Next(0, modList.Count)];
}
while (set.IsHard);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ private void ApplyMappingToLevel(TR1CombinedLevel level, EMEditorMapping mapping
level.Data.SoundEffects[TR1SFX.PendulumBlades] = vilcabamba.SoundEffects[TR1SFX.PendulumBlades];
}

EnvironmentPicker picker = new(Settings.HardEnvironmentMode)
{
Generator = _generator
};
picker.LoadTags(Settings, true);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;

// These are applied whether or not environment randomization is enabled,
Expand Down Expand Up @@ -224,9 +220,9 @@ private static void UpdateDoppelgangerScript(TR1CombinedLevel level)
private void FinalizeEnvironment(TR1CombinedLevel level)
{
EMEditorMapping mapping = EMEditorMapping.Get(GetResourcePath($@"TR1\Environment\{level.Name}-Environment.json"));
EnvironmentPicker picker = new(Settings.HardEnvironmentMode);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;
picker.ResetTags(true);
picker.ResetTags();

if (mapping != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public void FinalizeEnvironment()
}

private EMEditorMapping GetMapping(TR1RCombinedLevel level)
=> EMEditorMapping.Get(GetResourcePath($@"TR1\Environment\{level.Name}-Environment.json"));
{
EMEditorMapping mapping = EMEditorMapping.Get(GetResourcePath($@"TR1\Environment\{level.Name}-Environment.json"));
mapping?.SetRemastered(true);
return mapping;
}

private void RandomizeEnvironment(TR1RCombinedLevel level)
{
Expand All @@ -52,24 +56,18 @@ private void RandomizeEnvironment(TR1RCombinedLevel level)

private void ApplyMappingToLevel(TR1RCombinedLevel level, EMEditorMapping mapping)
{
EnvironmentPicker picker = new(Settings.HardEnvironmentMode)
{
Generator = _generator
};
picker.LoadTags(Settings, true);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;

mapping.All.ApplyToLevel(level.Data, picker.Options);

// No further mods supported yet
}

private void FinalizeEnvironment(TR1RCombinedLevel level)
{
EMEditorMapping mapping = GetMapping(level);
EnvironmentPicker picker = new(Settings.HardEnvironmentMode);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;
picker.ResetTags(true);
picker.ResetTags();

if (mapping != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ private void RandomizeEnvironment(TR2CombinedLevel level)

private void ApplyMappingToLevel(TR2CombinedLevel level, EMEditorMapping mapping)
{
EnvironmentPicker picker = new(Settings.HardEnvironmentMode)
{
Generator = _generator
};
picker.LoadTags(Settings, ScriptEditor.Edition.IsCommunityPatch);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;

mapping.All.ApplyToLevel(level.Data, picker.Options);
Expand Down Expand Up @@ -168,9 +164,8 @@ private void ApplyMappingToLevel(TR2CombinedLevel level, EMEditorMapping mapping
private void FinalizeEnvironment(TR2CombinedLevel level)
{
EMEditorMapping mapping = EMEditorMapping.Get(GetResourcePath($@"TR2\Environment\{level.Name}-Environment.json"));
EnvironmentPicker picker = new(Settings.HardEnvironmentMode);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;
picker.ResetTags(ScriptEditor.Edition.IsCommunityPatch);

if (mapping != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public void FinalizeEnvironment()
}

private EMEditorMapping GetMapping(TR2RCombinedLevel level)
=> EMEditorMapping.Get(GetResourcePath($@"TR2\Environment\{level.Name}-Environment.json"));
{
EMEditorMapping mapping = EMEditorMapping.Get(GetResourcePath($@"TR2\Environment\{level.Name}-Environment.json"));
mapping?.SetRemastered(true);
return mapping;
}

private void RandomizeEnvironment(TR2RCombinedLevel level)
{
Expand All @@ -52,24 +56,17 @@ private void RandomizeEnvironment(TR2RCombinedLevel level)

private void ApplyMappingToLevel(TR2RCombinedLevel level, EMEditorMapping mapping)
{
EnvironmentPicker picker = new(Settings.HardEnvironmentMode)
{
Generator = _generator
};
picker.LoadTags(Settings, true);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;

mapping.All.ApplyToLevel(level.Data, picker.Options);

// No further mods supported yet
}

private void FinalizeEnvironment(TR2RCombinedLevel level)
{
EMEditorMapping mapping = GetMapping(level);
EnvironmentPicker picker = new(Settings.HardEnvironmentMode);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;
picker.ResetTags(true);

if (mapping != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ private void RandomizeEnvironment(TR3CombinedLevel level)

private void ApplyMappingToLevel(TR3CombinedLevel level, EMEditorMapping mapping)
{
EnvironmentPicker picker = new(Settings.HardEnvironmentMode)
{
Generator = _generator
};
picker.LoadTags(Settings, ScriptEditor.Edition.IsCommunityPatch);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;

mapping.All.ApplyToLevel(level.Data, picker.Options);
Expand Down Expand Up @@ -172,9 +168,8 @@ private void ApplyMappingToLevel(TR3CombinedLevel level, EMEditorMapping mapping
private void FinalizeEnvironment(TR3CombinedLevel level)
{
EMEditorMapping mapping = EMEditorMapping.Get(GetResourcePath($@"TR3\Environment\{level.Name}-Environment.json"));
EnvironmentPicker picker = new(Settings.HardEnvironmentMode);
EnvironmentPicker picker = new(_generator, Settings, ScriptEditor.Edition);
picker.Options.ExclusionMode = EMExclusionMode.Individual;
picker.ResetTags(ScriptEditor.Edition.IsCommunityPatch);

if (mapping != null)
{
Expand Down
Loading
Loading