Skip to content

Commit

Permalink
Add initial work for CV generation
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Dec 27, 2023
1 parent 133fb8e commit 1ee786d
Show file tree
Hide file tree
Showing 19 changed files with 1,568 additions and 132 deletions.
9 changes: 6 additions & 3 deletions IntelOrca.Biohazard.BioRand.Tests/TestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ internal static class TestInfo
{
public static string GetInstallPath(int game)
{
var fileName = $"re{game + 1}";
if (game == 3)
fileName = "recvx";
var places = new[]
{
$@"D:\games\re{game + 1}",
$@"F:\games\re{game + 1}",
$@"M:\games\re{game + 1}"
$@"D:\games\re{fileName}",
$@"F:\games\re{fileName}",
$@"M:\games\re{fileName}"
};

foreach (var place in places)
Expand Down
59 changes: 38 additions & 21 deletions IntelOrca.Biohazard.BioRand/BaseRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ private Dictionary<RdtId, ulong> GetRdtChecksums(string dataPath, int player, Rd
return result;
}

protected virtual RandomizedRdt ReadRdt(FileRepository fileRepository, RdtId rdtId, string path, string modPath)
{
var rdtBytes = fileRepository.GetBytes(path);
var rdt = GameDataReader.ReadRdt(BiohazardVersion, rdtId, rdtBytes, path, modPath);
return rdt;
}

private GameData ReadGameData(FileRepository fileRepository, int player, RdtId[] rdtIds, bool mod)
{
var rdts = new List<RandomizedRdt>();
Expand All @@ -168,8 +175,7 @@ private GameData ReadGameData(FileRepository fileRepository, int player, RdtId[]
try
{
var srcPath = mod ? modRdtPath : rdtPath;
var rdtBytes = fileRepository.GetBytes(srcPath);
var rdt = GameDataReader.ReadRdt(BiohazardVersion, rdtId, rdtBytes, srcPath, modRdtPath);
var rdt = ReadRdt(fileRepository, rdtId, srcPath, modRdtPath);
rdts.Add(rdt);
}
catch
Expand All @@ -193,13 +199,18 @@ public void Generate(RandoConfig config, IRandoProgress progress)

var reConfig = InstallConfig;
var installPath = reConfig.GetInstallPath(BiohazardVersion);
if (BiohazardVersion == BioVersion.BiohazardCv)
{
installPath = Path.GetDirectoryName(installPath);
}

var originalDataPath = GetDataPath(installPath);
var modPath = Path.Combine(installPath, @"mod_biorand");
var fileRepo = new FileRepository(originalDataPath, modPath);
if (reConfig!.IsEnabled(BioVersion.Biohazard3))
{
var dataPath = GetDataPath(reConfig.GetInstallPath(BioVersion.Biohazard3));
var re3randomizer = new Re3Randomiser(reConfig, null);
var dataPath = re3randomizer.GetDataPath(reConfig.GetInstallPath(BioVersion.Biohazard3));
re3randomizer.AddArchives(dataPath, fileRepo);
}

Expand Down Expand Up @@ -339,19 +350,23 @@ public void GenerateRdts(RandoConfig config, IRandoProgress progress, FileReposi
using (progress.BeginTask(config.Player, $"Changing player character"))
playerActors = ChangePlayerCharacters(config, logger, gameData, fileRepository);

var voiceRandomiser = new VoiceRandomiser(
BiohazardVersion,
logger,
fileRepository,
config,
fileRepository.DataPath,
fileRepository.ModPath,
gameData,
map,
randomVoices,
NpcHelper,
DataManager,
playerActors);
VoiceRandomiser? voiceRandomiser = null;
if (config.RandomNPCs || config.RandomEvents)
{
voiceRandomiser = new VoiceRandomiser(
BiohazardVersion,
logger,
fileRepository,
config,
fileRepository.DataPath,
fileRepository.ModPath,
gameData,
map,
randomVoices,
NpcHelper,
DataManager,
playerActors);
}

NPCRandomiser? npcRandomiser = null;
if (config.RandomNPCs)
Expand All @@ -370,21 +385,21 @@ public void GenerateRdts(RandoConfig config, IRandoProgress progress, FileReposi
NpcHelper,
DataManager,
playerActors,
voiceRandomiser);
voiceRandomiser!);
var selectedActors = GetSelectedActors(config);
if (selectedActors.Length == 0)
{
throw new BioRandUserException("No NPCs selected.");
}
npcRandomiser.SelectedActors.AddRange(selectedActors);
RandomizeNPCs(config, npcRandomiser, voiceRandomiser);
RandomizeNPCs(config, npcRandomiser, voiceRandomiser!);
npcRandomiser.Randomise();
}
}

if (config.RandomCutscenes)
{
voiceRandomiser.Randomise();
voiceRandomiser!.Randomise();
}

EnemyRandomiser? enemyRandomiser = null;
Expand Down Expand Up @@ -763,19 +778,21 @@ private void CreateBackgrounds(RandoConfig config, FileRepository fileRepository
{
try
{
var src = DataManager.GetData(BiohazardVersion, "bg.png");
if (BiohazardVersion == BioVersion.Biohazard1)
{
var src = DataManager.GetData(BiohazardVersion, "bg.png");
CreateBackgroundRaw(config, src, fileRepository.GetModPath("data/title.pix"));
CreateBackgroundPng(config, src, fileRepository.GetModPath("type.png"));
}
else if (BiohazardVersion == BioVersion.Biohazard2)
{
var src = DataManager.GetData(BiohazardVersion, "bg.png");
CreateBackgroundPng(config, src, fileRepository.GetModPath("common/data/title_bg.png"));
CreateBackgroundPng(config, src, fileRepository.GetModPath("common/data/type00.png"));
}
else
else if (BiohazardVersion == BioVersion.Biohazard3)
{
var src = DataManager.GetData(BiohazardVersion, "bg.png");
CreateBackgroundRaw(config, src, fileRepository.GetModPath("data/etc/type00.pix"));
CreateBackgroundTim(config, src, fileRepository.GetModPath("data_j/etc2/titlej.dat"));
CreateBackgroundTim(config, src, fileRepository.GetModPath("data_j/etc2/titletgs.dat"));
Expand Down
3 changes: 3 additions & 0 deletions IntelOrca.Biohazard.BioRand/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public string GetPath(BioVersion version, string path)
return GetPath("re2", path);
case BioVersion.Biohazard3:
return GetPath("re3", path);
case BioVersion.BiohazardCv:
return GetPath("recv", path);
default:
throw new NotImplementedException();
}
Expand Down Expand Up @@ -131,6 +133,7 @@ private string GetSubPath(BioVersion version, string basePath)
BioVersion.Biohazard1 => Path.Combine("re1", basePath),
BioVersion.Biohazard2 => Path.Combine("re2", basePath),
BioVersion.Biohazard3 => Path.Combine("re3", basePath),
BioVersion.BiohazardCv => Path.Combine("recv", basePath),
_ => throw new NotImplementedException(),
};
}
Expand Down
23 changes: 20 additions & 3 deletions IntelOrca.Biohazard.BioRand/EnemyRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void GatherEsps()
{
foreach (var rdt in _gameData.Rdts)
{
var embeddedEffects = rdt.RdtFile.EmbeddedEffects;
var embeddedEffects = GetEmbeddedEffects(rdt.RdtFile);
for (var i = 0; i < embeddedEffects.Count; i++)
{
var ee = embeddedEffects[i];
Expand Down Expand Up @@ -486,7 +486,7 @@ private void AddRequiredEsps(RandomizedRdt rdt, byte enemyType)
return;

var rdtFile = rdt.RdtFile;
var embeddedEffects = rdtFile.EmbeddedEffects;
var embeddedEffects = GetEmbeddedEffects(rdtFile);
var missingIds = espIds.Except(embeddedEffects.Ids).ToArray();
if (missingIds.Length == 0)
return;
Expand All @@ -499,7 +499,7 @@ private void AddRequiredEsps(RandomizedRdt rdt, byte enemyType)
}

var rdtBuilder = rdtFile.ToBuilder();
rdtBuilder.EmbeddedEffects = new EmbeddedEffectList(rdtFile.Version, existingEffects.ToArray());
SetEmbeddedEffects(rdtBuilder, new EmbeddedEffectList(rdtFile.Version, existingEffects.ToArray()));
if (rdt.Version == BioVersion.Biohazard3)
{
var bb = (Rdt2.Builder)rdtBuilder;
Expand Down Expand Up @@ -807,6 +807,23 @@ private void DetachPartner(RdtId rdtId)
}
}

private EmbeddedEffectList GetEmbeddedEffects(IRdt rdt)
{
if (rdt is Rdt2 rdt2)
{
return rdt2.EmbeddedEffects;
}
throw new NotSupportedException();
}

private void SetEmbeddedEffects(IRdtBuilder builder, EmbeddedEffectList value)
{
if (builder is Rdt2.Builder builder2)
{
builder2.EmbeddedEffects = value;
}
}

public struct EnemyPosition : IEquatable<EnemyPosition>
{
public RdtId RdtId { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions IntelOrca.Biohazard.BioRand/RECV/ReCvDoorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace IntelOrca.Biohazard.BioRand.RECV
{
internal class ReCvDoorHelper : IDoorHelper
{
public byte[] GetReservedLockIds() => new byte[0];

public void Begin(RandoConfig config, GameData gameData, Map map)
{
}

public void End(RandoConfig config, GameData gameData, Map map)
{
}
}
}
84 changes: 84 additions & 0 deletions IntelOrca.Biohazard.BioRand/RECV/ReCvEnemyHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using IntelOrca.Biohazard.Script.Opcodes;

namespace IntelOrca.Biohazard.BioRand.RECV
{
internal class ReCvEnemyHelper : IEnemyHelper
{
public void BeginRoom(RandomizedRdt rdt)
{
}

public string GetEnemyName(byte type)
{
switch (type)
{
case ReCvEnemyIds.Zombie:
return "ZOMBIE";
default:
return $"EM_{type:X2}";
}
}

public int GetEnemyTypeLimit(RandoConfig config, int difficulty, byte type)
{
var limit = new byte[] { 4, 8, 12, 16 };
var index = Math.Min(limit.Length - 1, difficulty);
return limit[index];
}

public SelectableEnemy[] GetSelectableEnemies() => new[]
{
new SelectableEnemy("Bat", "Black", ReCvEnemyIds.Bat),
new SelectableEnemy("Zombie", "LightGray", ReCvEnemyIds.Zombie),
new SelectableEnemy("Hunter", "IndianRed", ReCvEnemyIds.Hunter),
new SelectableEnemy("Bandersnatch", "Cyan", ReCvEnemyIds.Bandersnatch),
new SelectableEnemy("Zombie Dog", "Black", ReCvEnemyIds.ZombieDog)
};

public bool IsEnemy(byte type)
{
return type < ReCvEnemyIds.Unknown43;
}

public bool IsUniqueEnemyType(byte type)
{
switch (type)
{
case ReCvEnemyIds.Bat:
case ReCvEnemyIds.Hunter:
case ReCvEnemyIds.Bandersnatch:
case ReCvEnemyIds.Zombie:
case ReCvEnemyIds.ZombieDog:
return false;
default:
return true;
}
}

public void SetEnemy(RandoConfig config, Rng rng, SceEmSetOpcode enemy, MapRoomEnemies enemySpec, byte enemyType)
{
}

public bool ShouldChangeEnemy(RandoConfig config, SceEmSetOpcode enemy)
{
return false;
}

public bool SupportsEnemyType(RandoConfig config, RandomizedRdt rdt, bool hasEnemyPlacements, byte enemyType)
{
return true;
}

public bool IsZombie(byte type) => type == ReCvEnemyIds.Zombie;

public byte[] GetReservedEnemyIds() => new byte[] { };

public byte[] GetEnemyDependencies(byte enemyType) => new byte[0];

public byte[] GetRequiredEsps(byte enemyType)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 1ee786d

Please sign in to comment.