Skip to content

Commit

Permalink
Add noise plot
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Dec 8, 2023
1 parent 6070084 commit afc5960
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
7 changes: 6 additions & 1 deletion IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public void RandomizeRoom(RandomizedRdt rdt, Rng rng)
{
ChainRandomPlot<AllyPassByPlot>(plots, plotBuilder);
}
if (rng.NextProbability(25))
{
ChainRandomPlot<NoisePlot>(plots, plotBuilder);
}
if (enemyType != null)
{
if (enemyType != Re2EnemyIds.ZombieArms &&
Expand Down Expand Up @@ -442,7 +446,8 @@ private void InitialisePlots()
new EnemyFromDarkPlot(),
new EnemyWalksInPlot(),
new AllyWaitPlot(),
new AllyPassByPlot()
new AllyPassByPlot(),
new NoisePlot()
};
}

Expand Down
6 changes: 3 additions & 3 deletions IntelOrca.Biohazard.BioRand/Events/PlotBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private int TakeEnemyCountForEvent(int min = 1, int max = int.MaxValue)
return count;
}

public SbNode Voice(ICsHero[] participants) => Voice(participants, participants);
public SbNode Voice(ICsHero[] participants, ICsHero[] speakers)
public SbNode Voice(ICsHero[] participants, string? kind = null) => Voice(participants, participants, kind);
public SbNode Voice(ICsHero[] participants, ICsHero[] speakers, string? kind = null)
{
if (_voiceRandomiser == null)
{
Expand All @@ -162,7 +162,7 @@ public SbNode Voice(ICsHero[] participants, ICsHero[] speakers)
{
var participantsActors = participants.Select(x => x.Actor).ToArray();
var speakerActors = speakers.Select(x => x.Actor).ToArray();
var result = _voiceRandomiser.AllocateConversation(Rng, _rdt.RdtId, 1, speakerActors, participantsActors);
var result = _voiceRandomiser.AllocateConversation(Rng, _rdt.RdtId, 1, speakerActors, participantsActors, kind);
return new SbContainerNode(
new SbVoice(result[0]),
new SbSleep(Rng.Next(5, 30)));
Expand Down
29 changes: 29 additions & 0 deletions IntelOrca.Biohazard.BioRand/Events/Plots/NoisePlot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace IntelOrca.Biohazard.BioRand.Events.Plots
{
internal class NoisePlot : IPlot
{
public CsPlot? BuildPlot(PlotBuilder builder)
{
var rng = builder.Rng;
var door = builder.PoiGraph.GetRandomPoi(rng, x => x.HasTag("door"));
if (door == null)
return null;

var plotFlag = builder.AllocateGlobalFlag();
return new CsPlot(
new SbProcedure(
new SbCommentNode($"[plot] noise {{ flag {plotFlag.Flag} }}",
new SbIf(plotFlag, false,
new SbFork(
new SbProcedure(
builder.CreateTrigger(),
new SbSetFlag(plotFlag),
new SbLockPlot(
new SbCommentNode($"[action] noise heard at {{ {door} }}",
new SbCutsceneBars(
new SbFreezeAllEnemies(
new SbCut(door.Cut,
builder.Voice(new ICsHero[0], "jumpscare"))))))))))));
}
}
}
24 changes: 21 additions & 3 deletions IntelOrca.Biohazard.BioRand/VoiceRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,20 @@ public void Randomise()
RandomizeRooms(_rng.NextFork());
}

public int[] AllocateConversation(Rng rng, RdtId rdtId, int count, string[] speakers, string[] actors)
public int[] AllocateConversation(Rng rng, RdtId rdtId, int count, string[] speakers, string[] actors, string? kind = null)
{
if (IsOmnipresentKind(kind) && speakers.Length == 0)
{
var pc = _playerActors[0];
var randomActor = GetRandomActor(_rng, pc, kind!);
if (randomActor == null)
{
return new int[0];
}

speakers = new[] { randomActor };
}

var stage = rdtId.Stage;
while (_newStageVoiceCount.Count <= stage)
{
Expand All @@ -229,7 +241,13 @@ public int[] AllocateConversation(Rng rng, RdtId rdtId, int count, string[] spea
voiceSample.Path = $"pl{_config.Player}/voice/stage{stage + 1}/v{vId + i:000}.sap";
voiceSample.Player = _config.Player;
voiceSample.Cutscene = cutscene;
RandomizeVoice(rng, voiceSample, "n/a", _rng.NextOf(speakers), null, actors);
RandomizeVoice(
rng,
voiceSample,
"n/a",
speakers.Length == 0 ? "unknown" : _rng.NextOf(speakers),
kind,
actors);
}
return Enumerable.Range(vId, count).ToArray();
}
Expand Down Expand Up @@ -375,7 +393,7 @@ private void RandomizeVoices(RdtId rdtId, Rng rng, int cutscene, string pc, Dict

private static bool IsOmnipresentKind(string? kind)
{
return kind == "radio" || kind == "narrator" || kind == "announcer";
return kind == "radio" || kind == "narrator" || kind == "announcer" || kind == "jumpscare";
}

private string? GetRandomActor(Rng rng, string pc, string kind)
Expand Down

0 comments on commit afc5960

Please sign in to comment.