Skip to content

Commit

Permalink
Exclude TRR monkey item drops (LostArtefacts#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Sep 29, 2024
1 parent a1a011f commit 60708fb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- fixed dark pickup sprites in TR2R OG graphics (#760)
- fixed gun pickup sprites not showing properly in TR2R Floating Islands and Dragon's Lair OG graphics (#760)
- fixed all placement issues with underwater corner secrets in TR1-3 (#763)
- fixed monkey item drops causing crashes in TR3R (#768)
- removed support for 32-bit (#759)

## [V1.9.2](https://github.com/LostArtefacts/TR-Rando/compare/V1.9.1...V1.9.2) - 2024-08-20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TRRandomizerCore.Helpers;
using TRRandomizerCore.Levels;
using TRRandomizerCore.Textures;
using TRRandomizerCore.Utilities;

namespace TRRandomizerCore.Randomizers;

Expand Down Expand Up @@ -192,35 +193,6 @@ private void FinalizeEnvironment(TR3CombinedLevel level)
monitor.UseMirroring = true;
}

CheckMonkeyPickups(level);
}

private static void CheckMonkeyPickups(TR3CombinedLevel level)
{
// Do a global check for monkeys that may be sitting on more than one pickup.
// This has to happen after item, enemy and environment rando to account for
// any shifted, converted and added items.
List<TR3Entity> monkeys = level.Data.Entities.FindAll(e => e.TypeID == TR3Type.Monkey);
foreach (TR3Entity monkey in monkeys)
{
List<TR3Entity> pickups = level.Data.Entities.FindAll(e =>
e.X == monkey.X &&
e.Y == monkey.Y &&
e.Z == monkey.Z &&
TR3TypeUtilities.IsAnyPickupType(e.TypeID)).ToList();

if (pickups.Count == 1)
{
continue;
}

// Leave one item to drop, favouring key items. The others will be shifted
// slightly so the monkey doesn't pick them up.
pickups.Sort((e1, e2) => TR3TypeUtilities.IsKeyItemType(e1.TypeID) ? 1 : -1);
for (int i = 0; i < pickups.Count - 1; i++)
{
++pickups[i].X;
}
}
TR3EnemyUtilities.CheckMonkeyPickups(level.Data, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using TRDataControl.Environment;
using TRGE.Core;
using TRRandomizerCore.Levels;
using TRRandomizerCore.Utilities;

namespace TRRandomizerCore.Randomizers;

Expand Down Expand Up @@ -75,5 +76,7 @@ private void FinalizeEnvironment(TR3RCombinedLevel level)
mod.ApplyToLevel(level.Data, picker.Options);
}
}

TR3EnemyUtilities.CheckMonkeyPickups(level.Data, true);
}
}
33 changes: 33 additions & 0 deletions TRRandomizerCore/Utilities/TR3EnemyUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,37 @@ static TR3EnemyUtilities()
File.ReadAllText(@"Resources\TR3\Restrictions\enemy_restrictions_pathing.json")
);
}

public static void CheckMonkeyPickups(TR3Level level, bool remastered)
{
// Do a global check for monkeys that may be sitting on more than one pickup.
// This has to happen after item, enemy and environment rando to account for
// any shifted, converted and added items.
foreach (TR3Entity monkey in level.Entities.Where(e => e.TypeID == TR3Type.Monkey))
{
List<TR3Entity> pickups = level.Entities.FindAll(e =>
e.X == monkey.X &&
e.Y == monkey.Y &&
e.Z == monkey.Z &&
TR3TypeUtilities.IsAnyPickupType(e.TypeID));

if (remastered)
{
// For TRR, we exclude all monkey pickups because the behaviour can lead to crashes.
pickups.ForEach(e => ++e.X);
}
else if (pickups.Count <= 1)
{
continue;
}

// Leave one item to drop, favouring key items. The others will be shifted
// slightly so the monkey doesn't pick them up.
pickups.Sort((e1, e2) => TR3TypeUtilities.IsKeyItemType(e1.TypeID) ? 1 : -1);
for (int i = 0; i < pickups.Count - 1; i++)
{
++pickups[i].X;
}
}
}
}

0 comments on commit 60708fb

Please sign in to comment.