Skip to content

Commit

Permalink
Fix boat bug
Browse files Browse the repository at this point in the history
If a secret depends on a vehicle, this was throwing an NPE.
  • Loading branch information
lahm86 committed Jun 1, 2024
1 parent 6a6b15d commit 23aa7f1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions TRRandomizerCore/Randomizers/TR2/Classic/TR2ItemRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,34 @@ private void AdjustSeraphContinuity(TR2CombinedLevel level)
private void RandomizeVehicles(TR2CombinedLevel level)
{
Dictionary<TR2Type, Queue<Location>> vehicleLocations = new();
void StoreLocation(TR2Type type)
{
Location location = VehicleUtilities.GetRandomLocation(level.Name, level.Data, type, _generator);
if (location == null)
{
return;
}

if (!vehicleLocations.ContainsKey(type))
{
vehicleLocations[type] = new();
}
vehicleLocations[type].Enqueue(location);
}

if (VehicleUtilities.HasLocations(level.Name, TR2Type.Boat))
{
vehicleLocations[TR2Type.Boat] = new();
int boatCount = Math.Max(1, level.Data.Entities.Count(e => e.TypeID == TR2Type.Boat));
for (int i = 0; i < boatCount; i++)
{
vehicleLocations[TR2Type.Boat].Enqueue(VehicleUtilities.GetRandomLocation(level.Name, level.Data, TR2Type.Boat, _generator));
StoreLocation(TR2Type.Boat);
}
}

if (level.IsAssault)
{
// Regular skidoo rando comes with enemy rando currently
vehicleLocations[TR2Type.RedSnowmobile] = new();
vehicleLocations[TR2Type.RedSnowmobile].Enqueue(VehicleUtilities.GetRandomLocation(level.Name, level.Data, TR2Type.RedSnowmobile, _generator));
StoreLocation(TR2Type.RedSnowmobile);
}

if (vehicleLocations.Count == 0)
Expand Down

0 comments on commit 23aa7f1

Please sign in to comment.