Skip to content

Commit

Permalink
LostArtefacts#272 Excludable Enemies
Browse files Browse the repository at this point in the history
- Adds support to allow choosing which enemies are available in the randomization pool. This does work mainly on "best effort", but exclusion priority can be defined so that enemies that the randomizer has a chance to focus on excluding any that are particularly undesirable. An option is in place to show a warning message if an excluded enemy has ended up in the game.
- Ensures skidoo drivers are limited if they are heavily present in any level.
- Rotates an enemy in Floaters if the type is flamethrower for a better chance of killing him.
  • Loading branch information
lahm86 committed Apr 25, 2022
1 parent 4cd4494 commit 5e8561a
Show file tree
Hide file tree
Showing 27 changed files with 1,204 additions and 130 deletions.
Binary file modified Deps/TRGE.Core.dll
Binary file not shown.
14 changes: 14 additions & 0 deletions TRLevelReader/Helpers/TR2EntityUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ public static List<TR2Entities> GetEntityFamily(TR2Entities entity)
return new List<TR2Entities> { entity };
}

public static List<TR2Entities> RemoveAliases(IEnumerable<TR2Entities> entities)
{
List<TR2Entities> ents = new List<TR2Entities>();
foreach (TR2Entities ent in entities)
{
TR2Entities normalisedEnt = TranslateEntityAlias(ent);
if (!ents.Contains(normalisedEnt))
{
ents.Add(normalisedEnt);
}
}
return ents;
}

public static List<TR2Entities> GetLaraTypes()
{
return new List<TR2Entities>
Expand Down
14 changes: 14 additions & 0 deletions TRLevelReader/Helpers/TR3EntityUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public static TR3Entities GetAliasForLevel(string lvl, TR3Entities entity)
return entity;
}

public static List<TR3Entities> RemoveAliases(IEnumerable<TR3Entities> entities)
{
List<TR3Entities> ents = new List<TR3Entities>();
foreach (TR3Entities ent in entities)
{
TR3Entities normalisedEnt = TranslateEntityAlias(ent);
if (!ents.Contains(normalisedEnt))
{
ents.Add(normalisedEnt);
}
}
return ents;
}

public static List<TR3Entities> GetLaraTypes()
{
return new List<TR3Entities>
Expand Down
18 changes: 18 additions & 0 deletions TRRandomizerCore/Editors/RandomizerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using TRRandomizerCore.Helpers;
using TRGE.Core;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;

namespace TRRandomizerCore.Editors
{
Expand Down Expand Up @@ -54,6 +56,12 @@ public class RandomizerSettings
public bool DocileBirdMonsters { get; set; }
public RandoDifficulty RandoEnemyDifficulty { get; set; }
public bool MaximiseDragonAppearance { get; set; }
public bool UseEnemyExclusions { get; set; }
public List<short> ExcludedEnemies { get; set; }
public Dictionary<short, string> ExcludableEnemies { get; set; }
public bool ShowExclusionWarnings { get; set; }
public List<short> IncludedEnemies => ExcludableEnemies.Keys.Except(ExcludedEnemies).ToList();
public bool OneEnemyMode => IncludedEnemies.Count == 1;
public bool GlitchedSecrets { get; set; }
public bool UseRewardRoomCameras { get; set; }
public bool PersistOutfits { get; set; }
Expand Down Expand Up @@ -124,6 +132,13 @@ public void ApplyConfig(Config config)
DocileBirdMonsters = config.GetBool(nameof(DocileBirdMonsters));
RandoEnemyDifficulty = (RandoDifficulty)config.GetEnum(nameof(RandoEnemyDifficulty), typeof(RandoDifficulty), RandoDifficulty.Default);
MaximiseDragonAppearance = config.GetBool(nameof(MaximiseDragonAppearance));
UseEnemyExclusions = config.GetBool(nameof(UseEnemyExclusions));
ShowExclusionWarnings = config.GetBool(nameof(ShowExclusionWarnings));
ExcludedEnemies = config.GetString(nameof(ExcludedEnemies))
.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => short.Parse(s))
.Where(s => ExcludableEnemies.ContainsKey(s))
.ToList();

RandomizeTextures = config.GetBool(nameof(RandomizeTextures));
TextureSeed = config.GetInt(nameof(TextureSeed), defaultSeed);
Expand Down Expand Up @@ -219,6 +234,9 @@ public void StoreConfig(Config config)
config[nameof(DocileBirdMonsters)] = DocileBirdMonsters;
config[nameof(RandoEnemyDifficulty)] = RandoEnemyDifficulty;
config[nameof(MaximiseDragonAppearance)] = MaximiseDragonAppearance;
config[nameof(ExcludedEnemies)] = string.Join(",", ExcludedEnemies);
config[nameof(UseEnemyExclusions)] = UseEnemyExclusions;
config[nameof(ShowExclusionWarnings)] = ShowExclusionWarnings;

config[nameof(RandomizeTextures)] = RandomizeTextures;
config[nameof(TextureSeed)] = TextureSeed;
Expand Down
16 changes: 14 additions & 2 deletions TRRandomizerCore/Editors/TR2RandoEditor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TRGE.Coord;
using TRGE.Core;
using TRLevelReader.Helpers;
using TRRandomizerCore.Processors;
using TRRandomizerCore.Randomizers;
using TRRandomizerCore.Textures;
Expand All @@ -17,7 +20,10 @@ public TR2RandoEditor(TRDirectoryIOArgs args, TREdition edition)

protected override void ApplyConfig(Config config)
{
Settings = new RandomizerSettings();
Settings = new RandomizerSettings
{
ExcludableEnemies = JsonConvert.DeserializeObject<Dictionary<short, string>>(File.ReadAllText(@"Resources\TR2\Restrictions\excludable_enemies.json"))
};
Settings.ApplyConfig(config);
}

Expand Down Expand Up @@ -48,6 +54,12 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
TR23ScriptEditor tr23ScriptEditor = scriptEditor as TR23ScriptEditor;
string wipDirectory = _io.WIPOutputDirectory.FullName;

if (Settings.DevelopmentMode)
{
(tr23ScriptEditor.Script as TR23Script).LevelSelectEnabled = true;
scriptEditor.SaveScript();
}

// Texture monitoring is needed between enemy and texture randomization
// to track where imported enemies are placed.
using (TR2TextureMonitorBroker textureMonitor = new TR2TextureMonitorBroker())
Expand Down
9 changes: 6 additions & 3 deletions TRRandomizerCore/Editors/TR3RandoEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TRGE.Coord;
Expand All @@ -20,7 +20,10 @@ public TR3RandoEditor(TRDirectoryIOArgs args, TREdition edition)

protected override void ApplyConfig(Config config)
{
Settings = new RandomizerSettings();
Settings = new RandomizerSettings
{
ExcludableEnemies = JsonConvert.DeserializeObject<Dictionary<short, string>>(File.ReadAllText(@"Resources\TR3\Restrictions\excludable_enemies.json"))
};
Settings.ApplyConfig(config);
}

Expand Down
3 changes: 2 additions & 1 deletion TRRandomizerCore/Helpers/TRRandomizationCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum TRRandomizationCategory
PreRandomize,
Randomize,
Commit,
Cancel
Cancel,
Warning
}
}
2 changes: 2 additions & 0 deletions TRRandomizerCore/Helpers/TRRandomizationEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private static TRRandomizationCategory ConvertCategory(TRSaveCategory category)
return TRRandomizationCategory.Cancel; // The operation has been cancelled externally
case TRSaveCategory.Commit:
return TRRandomizationCategory.Commit; // TRGE is commiting the changes to the original data directory
case TRSaveCategory.Warning:
return TRRandomizationCategory.Warning; // A processor wants to send a warning message
default:
return TRRandomizationCategory.None;
}
Expand Down
21 changes: 21 additions & 0 deletions TRRandomizerCore/Levels/TR2CombinedLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,26 @@ public int GetMaximumEntityLimit()

return limit;
}

public int GetActualEntityCount()
{
int count = 0;
foreach (TR2Entity entity in Data.Entities)
{
switch ((TR2Entities)entity.TypeID)
{
case TR2Entities.MercSnowmobDriver:
count += 2;
break;
case TR2Entities.MarcoBartoli:
count += 7;
break;
default:
count++;
break;
}
}
return count;
}
}
}
8 changes: 8 additions & 0 deletions TRRandomizerCore/Processors/AbstractLevelProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ internal void SetMessage(string text)
}
}

internal void SetWarning(string text)
{
lock (_monitorLock)
{
SaveMonitor.FireSaveStateChanged(category: TRSaveCategory.Warning, customDescription: text);
}
}

public void HandleException(Exception e)
{
lock (_monitorLock)
Expand Down
Loading

0 comments on commit 5e8561a

Please sign in to comment.