From afc59609f358866ae43da05b9637a489a278155c Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 8 Dec 2023 14:51:19 +0000 Subject: [PATCH] Add noise plot --- .../Events/CutsceneRandomiser.cs | 7 ++++- .../Events/PlotBuilder.cs | 6 ++-- .../Events/Plots/NoisePlot.cs | 29 +++++++++++++++++++ .../VoiceRandomiser.cs | 24 +++++++++++++-- 4 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 IntelOrca.Biohazard.BioRand/Events/Plots/NoisePlot.cs diff --git a/IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs b/IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs index 56722474..ac253bad 100644 --- a/IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs +++ b/IntelOrca.Biohazard.BioRand/Events/CutsceneRandomiser.cs @@ -181,6 +181,10 @@ public void RandomizeRoom(RandomizedRdt rdt, Rng rng) { ChainRandomPlot(plots, plotBuilder); } + if (rng.NextProbability(25)) + { + ChainRandomPlot(plots, plotBuilder); + } if (enemyType != null) { if (enemyType != Re2EnemyIds.ZombieArms && @@ -442,7 +446,8 @@ private void InitialisePlots() new EnemyFromDarkPlot(), new EnemyWalksInPlot(), new AllyWaitPlot(), - new AllyPassByPlot() + new AllyPassByPlot(), + new NoisePlot() }; } diff --git a/IntelOrca.Biohazard.BioRand/Events/PlotBuilder.cs b/IntelOrca.Biohazard.BioRand/Events/PlotBuilder.cs index 1e67b50d..49b9d53f 100644 --- a/IntelOrca.Biohazard.BioRand/Events/PlotBuilder.cs +++ b/IntelOrca.Biohazard.BioRand/Events/PlotBuilder.cs @@ -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) { @@ -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))); diff --git a/IntelOrca.Biohazard.BioRand/Events/Plots/NoisePlot.cs b/IntelOrca.Biohazard.BioRand/Events/Plots/NoisePlot.cs new file mode 100644 index 00000000..5bb90f51 --- /dev/null +++ b/IntelOrca.Biohazard.BioRand/Events/Plots/NoisePlot.cs @@ -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")))))))))))); + } + } +} diff --git a/IntelOrca.Biohazard.BioRand/VoiceRandomiser.cs b/IntelOrca.Biohazard.BioRand/VoiceRandomiser.cs index d47ebe72..664fd2e3 100644 --- a/IntelOrca.Biohazard.BioRand/VoiceRandomiser.cs +++ b/IntelOrca.Biohazard.BioRand/VoiceRandomiser.cs @@ -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) { @@ -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(); } @@ -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)