Skip to content

Commit

Permalink
Add item rando support
Browse files Browse the repository at this point in the history
Routes and invalid item locations defined for TRUB. Key item IDs defined and adjustments made to always calculate the correct base for level sequencing regardless of game mode.
Updated location generation to skip over triggers for Thor's hammer - we just assume the trigger is below the hammer head for ease. Fixed a couple of routing issues in Folly too.
  • Loading branch information
lahm86 committed Dec 1, 2023
1 parent d04bc04 commit 5256c64
Show file tree
Hide file tree
Showing 9 changed files with 3,479 additions and 48 deletions.
2 changes: 1 addition & 1 deletion LocationExport/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void Main(string[] args)
}
else if (levelType == "TR1")
{
foreach (string lvl in TR1LevelNames.AsList)
foreach (string lvl in TR1LevelNames.AsListWithGold)
{
if (File.Exists(lvl))
{
Expand Down
8 changes: 8 additions & 0 deletions Resources/trview/plugins/key_items/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ m_KeyNames[1][22183] = "P1 Fuse (conveyor)"
m_KeyNames[1][22148] = "P1 Fuse (Cowboy)"
m_KeyNames[1][22146] = "P1 Fuse (Cowboy, alt)"
m_KeyNames[1][22216] = "P2 Pyramid Key"
m_KeyNames[1][25192] = "K1 Gold Key"
m_KeyNames[1][26146] = "K1 Ornate Key (near pyramid)"
m_KeyNames[1][26196] = "K1 Ornate Key (croc pool)"
m_KeyNames[1][26192] = "K1 Ornate Key (tiers south)"
m_KeyNames[1][26303] = "K1 Ornate Key (tiers north)"
m_KeyNames[1][26269] = "K1 Ornate Key (cubby south)"
m_KeyNames[1][26365] = "K1 Ornate Key (cubby north)"
m_KeyNames[1][26206] = "K1 Ornate Key (cat statue)"

-- TR2
m_KeyNames[2] = {}
Expand Down
12 changes: 12 additions & 0 deletions TRLevelControl/Model/Base/Enums/TR1Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,16 @@ public enum TR1Type
AtlantisKeyItemBase = 23000,

PyramidKeyItemBase = 24000,

EgyptKeyItemBase = 25000,
Egypt_K1_GoldKey = 25192,

CatKeyItemBase = 26000,
Cat_K1_OrnateKeyPyramid = 26146,
Cat_K1_OrnateKeyCrocPool = 26196,
Cat_K1_OrnateKeyTierSouth = 26192,
Cat_K1_OrnateKeyTierNorth = 26303,
Cat_K1_OrnateKeyCubbySouth = 26269,
Cat_K1_OrnateKeyCubbyNorth = 26365,
Cat_K1_OrnateKeyCatStatue = 26206,
}
12 changes: 11 additions & 1 deletion TRRandomizerCore/Helpers/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public static class CollectionExtensions
{
private const int _defaultShuffleCount = 5;

public static List<T> RandomSelection<T>(this List<T> list, Random rand, int count, bool allowDuplicates = false, ISet<T> exclusions = null)
{
count = Math.Abs(count);
Expand Down Expand Up @@ -43,7 +45,15 @@ public static List<T> RandomSelection<T>(this List<T> list, Random rand, int cou
return resultSet;
}

public static void Shuffle<T>(this List<T> list, Random rand)
public static void Shuffle<T>(this List<T> list, Random rand, int count = _defaultShuffleCount)
{
for (int i = 0; i < count; i++)
{
ShuffleImpl(list, rand);
}
}

private static void ShuffleImpl<T>(List<T> list, Random rand)
{
List<T> iterList = new(list);
list.Clear();
Expand Down
32 changes: 15 additions & 17 deletions TRRandomizerCore/Randomizers/TR1/TR1ItemRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,6 @@ public class TR1ItemRandomizer : BaseTR1Randomizer
= 11, // Default = 7
[TR1LevelNames.MIDAS]
= 4, // Default = 12
[TR1LevelNames.CISTERN]
= 0, // Default = 16
[TR1LevelNames.TIHOCAN]
= 0, // Default = 16
[TR1LevelNames.KHAMOON]
= 0, // Default = 18
[TR1LevelNames.OBELISK]
= 0, // Default = 26
[TR1LevelNames.SANCTUARY]
= 0, // Default = 22
[TR1LevelNames.MINES]
= 0, // Default = 16
[TR1LevelNames.ATLANTIS]
= 0, // Default = 44
[TR1LevelNames.PYRAMID]
= 0, // Default = 21
};

private readonly Dictionary<string, List<Location>> _excludedLocations;
Expand Down Expand Up @@ -411,6 +395,7 @@ private void RandomizeKeyItems(TR1CombinedLevel level)
level.Data.Entities.AddRange(TihocanEndItems);
}

int sequence = GetKeyItemLevelSequence(level);
for (int i = 0; i < level.Data.Entities.Count; i++)
{
TR1Entity entity = level.Data.Entities[i];
Expand All @@ -422,7 +407,7 @@ private void RandomizeKeyItems(TR1CombinedLevel level)

bool hasPickupTrigger = LocationUtilities.HasPickupTriger(entity, i, level.Data, floorData);
_picker.RandomizeKeyItemLocation(entity, hasPickupTrigger,
level.Script.OriginalSequence, level.Data.Rooms[entity.Room].Info);
sequence, level.Data.Rooms[entity.Room].Info);

if (Settings.AllowEnemyKeyDrops && !hasPickupTrigger)
{
Expand All @@ -431,6 +416,19 @@ private void RandomizeKeyItems(TR1CombinedLevel level)
}
}

private int GetKeyItemLevelSequence(TR1CombinedLevel level)
{
int sequence = level.Script.OriginalSequence;
if (Settings.GameMode != GameMode.Normal && level.IsExpansion)
{
// The original sequence is always 1-based regardless of how we have
// combined, so we need to manually shift. This ensures there are no
// clashes in TR1Type between regular and expansion levels.
sequence += TR1LevelNames.AsList.Count;
}
return sequence;
}

private void TestEnemyItemDrop(TR1CombinedLevel level, TR1Entity entity, FDControl floorData)
{
TRRoomSector sectorFunc(Location loc) =>
Expand Down
Loading

0 comments on commit 5256c64

Please sign in to comment.