Skip to content

Commit

Permalink
Allow multiple allies to pass by
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Dec 16, 2023
1 parent fd8a3f7 commit 498fbca
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
10 changes: 9 additions & 1 deletion IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ public void RandomizeRoom(RandomizedRdt rdt, Rng rng)
cb.AvailableAotIds.Enqueue(id);
}

var localFlags = Enumerable.Range(25, 32 - 25)
var usedLocalFlags = rdt.AllOpcodes
.Select(x => x as CkOpcode)
.Where(x => x != null && x.BitArray == 5)
.Select(x => x?.Index ?? 0)
.ToHashSet();
usedLocalFlags.Add(23); // plot lock
usedLocalFlags.Add(24); // temp
var localFlags = Enumerable.Range(0, 32)
.Where(x => !usedLocalFlags.Contains((byte)x))
.Select(x => new ReFlag(CutsceneBuilder.FG_ROOM, (byte)x))
.ToArray();

Expand Down
61 changes: 49 additions & 12 deletions IntelOrca.Biohazard.BioRand/Events/Plots/AllyPassByPlot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;

namespace IntelOrca.Biohazard.BioRand.Events.Plots
{
Expand All @@ -17,28 +19,63 @@ internal class AllyPassByPlot : IPlot
.Shuffle(rng)
.Take(2)
.ToArray();
var ally = builder.AllocateAlly();
var entrance = doors[0];
var exit = doors[1];

var count = rng.Next(1, 4);
var allies = Enumerable
.Range(0, count)
.Select(x => builder.AllocateAlly())
.ToArray();
var allyFlags = Enumerable
.Range(0, count)
.Select(x => builder.AllocateLocalFlag())
.ToArray();

var plotFlag = builder.AllocateGlobalFlag();
return new CsPlot(
new SbProcedure(
new SbCommentNode($"[plot] ally pass by {{ flag {plotFlag.Flag} }}",
new SbIf(plotFlag, false,
new SbAlly(ally, REPosition.OutOfBounds),
new SbSetEntityCollision(ally, false),
new SbContainerNode(
allies.Select(x => new SbAlly(x, REPosition.OutOfBounds)).ToArray()),
new SbContainerNode(
allies.Select(x => new SbSetEntityCollision(x, false)).ToArray()),
new SbFork(
new SbProcedure(
builder.CreateTrigger(doors[0].Cuts),
new SbSetFlag(plotFlag),
new SbLockPlot(
new SbCommentNode($"[action] ally enter at {{ {doors[0]} }}",
new SbDoor(doors[0]),
// new SbWaitForCut(doors[0].Cuts, false),
new SbMoveEntity(ally, doors[0].Position),
new SbCommentNode($"[action] ally travel to {{ {doors[1]} }}",
builder.Travel(ally, doors[0], doors[1], PlcDestKind.Run, overrideDestination: doors[1].Position.Reverse())),
new SbMoveEntity(ally, REPosition.OutOfBounds),
new SbDoor(doors[1]),
new SbSleep(4 * 30)))))))));
new SbContainerNode(
allies
.Select(ally => DoAlly(builder, Array.IndexOf(allies, ally), allies.Length))
.ToArray()),
new SbContainerNode(
allyFlags.Select(x => new SbWaitForFlag(x.Flag)).ToArray())))))))));

SbNode DoAlly(PlotBuilder builder, int index, int count)
{
var ally = allies[index];
var flag = allyFlags[index];
var result = new List<SbNode>();
if (index == 0)
{
result.Add(new SbDoor(entrance));
}
result.Add(new SbSleep(index * 15));
result.Add(new SbMoveEntity(ally, entrance.Position));
result.Add(new SbCommentNode($"[action] ally travel to {{ {exit} }}",
builder.Travel(ally, entrance, exit, PlcDestKind.Run, overrideDestination: exit.Position.Reverse())));
result.Add(new SbMoveEntity(ally, REPosition.OutOfBounds));
if (index == count - 1)
{
result.Add(new SbDoor(exit));
}
result.Add(new SbSleep(4 * 30));
result.Add(new SbSetFlag(flag));
return new SbFork(new SbProcedure(result.ToArray()));
}
}
}
}
2 changes: 1 addition & 1 deletion biohazard-utils

0 comments on commit 498fbca

Please sign in to comment.