Skip to content

Commit

Permalink
Merge pull request #66 from tinyhoot/v0.10
Browse files Browse the repository at this point in the history
Update to v0.10
  • Loading branch information
tinyhoot authored Jan 26, 2023
2 parents 61cd193 + 0506536 commit 3519fec
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 130 deletions.
64 changes: 32 additions & 32 deletions DataFiles/recipeInformation.csv
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Tank,Equipment,0,,35,3,,
Beacon,Deployables,0,,25,,BeaconFragment,14
Constructor,Deployables,100,,215,,ConstructorFragment,14
CyclopsDecoy,Deployables,0,,60,,,
GravSphere,Deployables,0,,60,,GravSphereFragment,14
Gravsphere,Deployables,0,,60,,GravSphereFragment,14
SmallStorage,Deployables,0,,45,,,
SeaGlide,Deployables,100,,90,,SeaGlideFragment,10
SeaMoth,Vehicles,100,Constructor,275,,SeaMothFragment,90
ExoSuit,Vehicles,300,Constructor,475,,ExosuitFragment,179
Seaglide,Deployables,100,,90,,SeaGlideFragment,10
Seamoth,Vehicles,100,Constructor,275,,SeaMothFragment,90
Exosuit,Vehicles,300,Constructor,475,,ExosuitFragment,179
Cyclops,Vehicles,300,Constructor,800,,CyclopsHullFragment;CyclopsEngineFragment;CyclopsBridgeFragment,250
RocketBase,Rocket,0,Constructor,325,,,
RocketBaseLadder,Rocket,0,RocketBase,185,,,
Expand Down Expand Up @@ -218,33 +218,33 @@ SpikePlantSeed,Seeds,30,Knife,10,,,
SpottedLeavesPlantSeed,Seeds,180,Knife,20,,,
TreeMushroomPiece,Seeds,150,Knife,15,,,
WhiteMushroomSpore,Seeds,180,Knife,20,,,
BoneShark,Eggs,180,BaseWaterPark,30,,,
BoneSharkEgg,Eggs,180,BaseWaterPark,30,,,
CrabSnake,Eggs,200,BaseWaterPark,40,,,
CrabSnakeEgg,Eggs,200,BaseWaterPark,40,,,
CrabSquid,Eggs,250,BaseWaterPark,40,,,
CrabSquidEgg,Eggs,250,BaseWaterPark,40,,,
Crash,Eggs,20,BaseWaterPark,15,,,
CrashEgg,Eggs,20,BaseWaterPark,15,,,
CuteFish,Eggs,500,BaseWaterPark,100,1,,
CuteFishEgg,Eggs,500,BaseWaterPark,100,1,,
Gasopod,Eggs,20,BaseWaterPark,15,,,
GasopodEgg,Eggs,20,BaseWaterPark,15,,,
JellyRay,Eggs,180,BaseWaterPark,30,,,
JellyRayEgg,Eggs,180,BaseWaterPark,30,,,
LavaLizard,Eggs,1200,BaseWaterPark,40,,,
LavaLizardEgg,Eggs,1200,BaseWaterPark,40,,,
Mesmer,Eggs,200,BaseWaterPark,20,,,
MesmerEgg,Eggs,200,BaseWaterPark,20,,,
RabbitRay,Eggs,20,BaseWaterPark,15,,,
RabbitRayEgg,Eggs,20,BaseWaterPark,15,,,
SandShark,Eggs,80,BaseWaterPark,20,,,
SandSharkEgg,Eggs,80,BaseWaterPark,20,,,
Shocker,Eggs,200,BaseWaterPark,40,,,
ShockerEgg,Eggs,200,BaseWaterPark,40,,,
SpadeFishEgg,Eggs,160,BaseWaterPark,15,,,
Stalker,Eggs,100,BaseWaterPark,20,,,
StalkerEgg,Eggs,100,BaseWaterPark,20,,,
BoneSharkEgg,Eggs,180,,30,,,
CrabSnakeEgg,Eggs,200,,40,,,
CrabSquidEgg,Eggs,250,,40,,,
CrashEgg,Eggs,20,,15,,,
CuteFishEgg,Eggs,500,,100,1,,
GasopodEgg,Eggs,20,,15,,,
JellyRayEgg,Eggs,180,,30,,,
LavaLizardEgg,Eggs,1200,,40,,,
MesmerEgg,Eggs,200,,20,,,
RabbitRayEgg,Eggs,20,,15,,,
SandSharkEgg,Eggs,80,,20,,,
ShockerEgg,Eggs,200,,40,,,
SpadeFishEgg,Eggs,160,,15,,,
StalkerEgg,Eggs,100,,20,,,
BoneShark,EggsHatched,180,BaseWaterPark,30,,,
CrabSnake,EggsHatched,200,BaseWaterPark,40,,,
CrabSquid,EggsHatched,250,BaseWaterPark,40,,,
Crash,EggsHatched,20,BaseWaterPark,15,,,
CuteFish,EggsHatched,500,BaseWaterPark,100,1,,
Gasopod,EggsHatched,20,BaseWaterPark,15,,,
JellyRay,EggsHatched,180,BaseWaterPark,30,,,
LavaLizard,EggsHatched,1200,BaseWaterPark,40,,,
Mesmer,EggsHatched,200,BaseWaterPark,20,,,
RabbitRay,EggsHatched,20,BaseWaterPark,15,,,
SandShark,EggsHatched,80,BaseWaterPark,20,,,
Shocker,EggsHatched,200,BaseWaterPark,40,,,
Stalker,EggsHatched,100,BaseWaterPark,20,,,
BaseBioReactorFragment,Fragments,,,75,,,
BaseNuclearReactorFragment,Fragments,150,,295,,,
BatteryChargerFragment,Fragments,,,65,,,
Expand All @@ -270,4 +270,4 @@ SeaglideFragment,Fragments,,,90,,,
SeamothFragment,Fragments,,,275,,,
StasisRifleFragment,Fragments,,,160,,,
ThermalPlantFragment,Fragments,100,,130,,,
WorkBenchFragment,Fragments,100,,110,,,
WorkbenchFragment,Fragments,100,,110,,,
26 changes: 6 additions & 20 deletions DevNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,19 @@
for e.g. a laser cutter.
- Table coral can be acquired with a Crashfish, or bumping into it with a vehicle.
No knife required!

- Mod support.
- Out-of-the-box support is not happening.
- Perhaps expose the progression tree? This would allow for more customisation,
and enable modded items to act as progression items and road blocks.

- Internal improvements.
- Look into why the game locks up while the mod is busy randomising.

- Scrap metal!
- For some reason, the existing logic works on some recipes but not for others.
It makes no sense.
- Randomising anew after the crafting tree has already been built once (i.e.,
a fabricator has been interacted with) makes it impossible to change until
next game restart. The scrap metal recipe could thus persist across seeds.
- Savedata idea which does not lead to a breaking update:
- Scrap metal is never crafted. Therefore, it does not have a recipe. Because
of this, it also does not have an entry in masterDict.
- Abuse this and file the new recipe for whatever scrap metal can be turned
*into* under scrap metal.

Aurora Notes:
- Fragments do spawn in LivingArea and CargoRoom, but not very often. Require very
high rates to do anything.
- Upgrade spawns are set in the editor and hard to get a hold of without modifying
every dropped upgrade in the game.



Expand All @@ -52,15 +45,8 @@ Thoughts from a playthrough:
- Alien Containment (covers both)
- Water filter (covers water, get food from surrounding fish)
- What about land seeds? If those get added, indoor growbeds are a necessity.
- Add Aurora interior to logic. What parts need repair tool, laser cutter, cannon?

Other:
- Sea treaders are a potential anti softlock mechanism. You could change their
poop and shale into something useful on the fly, or make shale always contain
something useful in the first place.

Aurora Notes:
- Fragments do spawn in LivingArea and CargoRoom, but not very often. Require very
high rates to do anything.
- Upgrade spawns are set in the editor and hard to get a hold of without modifying
every dropped upgrade in the game.
3 changes: 0 additions & 3 deletions SubnauticaRandomiser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,4 @@ Global
{04F771FE-CA90-4C9D-B633-6366DE6855E5}.Debug|x64.ActiveCfg = Debug|x64
{04F771FE-CA90-4C9D-B633-6366DE6855E5}.Release|x64.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
outputpath = "$SUBNAUTICA_DIR/QMods/SubnauticaRandomiser"
EndGlobalSection
EndGlobal
9 changes: 7 additions & 2 deletions SubnauticaRandomiser/CSVReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static async Task<List<T>> ParseDataFileAsync<T>(string fileName, Func<st
/// <exception cref="ArgumentException">If a required column is missing or invalid.</exception>
public static LogicEntity ParseRecipeLine(string[] cells)
{
EntityType entityType;
EntityType entityType = EntityType.None;
TechType techType;
TechTypeCategory category;
int depth = 0;
Expand Down Expand Up @@ -187,7 +187,12 @@ public static LogicEntity ParseRecipeLine(string[] cells)
if (string.IsNullOrEmpty(cellsCategory))
throw new ArgumentException("Category is null or empty, but is a required field.");
category = EnumHandler.Parse<TechTypeCategory>(cellsCategory);
entityType = category.Equals(TechTypeCategory.Fragments) ? EntityType.Fragment : EntityType.Recipe;
if (category.IsFragment())
entityType = EntityType.Fragment;
if (category.IsCraftable())
entityType = EntityType.Craftable;
if (category.IsRawMaterial())
entityType = EntityType.RawMaterial;

// Column 3: Depth Difficulty
if (!string.IsNullOrEmpty(cellsDepth))
Expand Down
1 change: 1 addition & 0 deletions SubnauticaRandomiser/ConfigDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal static class ConfigDefaults
{ "iRandomiserMode", new[] { 0, 0, 1 } },
{ "bUseFish", new[] { true, true, true } },
{ "bUseEggs", new[] { false, false, false } },
{ "bDiscoverEggs", new[] { false, false, false } },
{ "bUseSeeds", new[] { true, true, true } },
{ "bRandomiseDataboxes", new[] { true, true, true } },
{ "bRandomiseFragments", new[] { true, true, true } },
Expand Down
1 change: 1 addition & 0 deletions SubnauticaRandomiser/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class EntitySerializer
public Dictionary<TechType, List<SpawnData>> SpawnDataDict;
// All possible supply box contents.
public LootTable<TechType> SupplyBoxContents;
public bool DiscoverEggs;

public const int SaveVersion = Initialiser._ExpectedSaveVersion;
[NonSerialized]
Expand Down
39 changes: 29 additions & 10 deletions SubnauticaRandomiser/Handlers/EntityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal class EntityHandler
private List<LogicEntity> _allEntities;
private readonly HashSet<LogicEntity> _inLogic;
private readonly ILogHandler _log;

public List<LogicEntity> GetAll() => _allEntities.ShallowCopy();

public EntityHandler(ILogHandler logger)
{
Expand All @@ -31,12 +29,25 @@ public EntityHandler(ILogHandler logger)

public event EventHandler<EntityEventArgs> EntityEnteredLogic;

/// <summary>
/// Add the given TechType as prerequisite for all entities in the given category.
/// </summary>
/// <param name="category">The category to add prerequisites to.</param>
/// <param name="techType">The new prerequisite to add.</param>
public void AddCategoryPrerequisite(TechTypeCategory category, TechType techType)
{
foreach (var categoryEntity in _allEntities.FindAll(e => e.Category.Equals(category)))
{
categoryEntity.AddPrerequisite(techType);
}
}

/// <summary>
/// Add the given TechTypes as prerequisites for all entities in the given category.
/// </summary>
/// <param name="category">The category to add prerequisites to.</param>
/// <param name="techTypes">The new prerequisites to add.</param>
public void AddCategoryPrerequisites(TechTypeCategory category, List<TechType> techTypes)
public void AddCategoryPrerequisite(TechTypeCategory category, ICollection<TechType> techTypes)
{
foreach (var categoryEntity in _allEntities.FindAll(e => e.Category.Equals(category)))
{
Expand All @@ -48,16 +59,16 @@ public void AddCategoryPrerequisites(TechTypeCategory category, List<TechType> t
}

/// <summary>
/// Add the builder tool as a prerequisite to all base pieces.
/// Add the builder tool as a prerequisite to all base pieces. Adding it here because this is essential
/// and must be done every time, no matter the loaded modules.
/// </summary>
private void AddBaseBuilderPrerequisite()
{
List<TechType> builder = new List<TechType> { TechType.Builder };
AddCategoryPrerequisites(TechTypeCategory.BaseBasePieces, builder);
AddCategoryPrerequisites(TechTypeCategory.BaseGenerators, builder);
AddCategoryPrerequisites(TechTypeCategory.BaseExternalModules, builder);
AddCategoryPrerequisites(TechTypeCategory.BaseInternalModules, builder);
AddCategoryPrerequisites(TechTypeCategory.BaseInternalPieces, builder);
AddCategoryPrerequisite(TechTypeCategory.BaseBasePieces, TechType.Builder);
AddCategoryPrerequisite(TechTypeCategory.BaseGenerators, TechType.Builder);
AddCategoryPrerequisite(TechTypeCategory.BaseExternalModules, TechType.Builder);
AddCategoryPrerequisite(TechTypeCategory.BaseInternalModules, TechType.Builder);
AddCategoryPrerequisite(TechTypeCategory.BaseInternalPieces, TechType.Builder);
}

/// <summary>
Expand Down Expand Up @@ -230,6 +241,14 @@ public List<LogicEntity> GetAllRawMaterials(int maxDepth = 2000)
return rawMaterials;
}

/// <summary>
/// Get all entities belonging to the given category.
/// </summary>
public List<LogicEntity> GetByCategory(TechTypeCategory category)
{
return _allEntities.FindAll(entity => entity.Category.Equals(category));
}

/// <summary>
/// Check whether the given entity is considered in logic, i.e. either randomised or otherwise accessible.
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions SubnauticaRandomiser/Initialiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class Initialiser : BaseUnityPlugin
{
public const string GUID = "com.github.tinyhoot.SubnauticaRandomiser";
public const string NAME = "Subnautica Randomiser";
public const string VERSION = "0.9.2";
public const string VERSION = "0.10.0";

// Files and structure.
internal static string _ModDirectory;
Expand All @@ -30,13 +30,14 @@ internal class Initialiser : BaseUnityPlugin
public const string _RecipeFile = "recipeInformation.csv";
public const string _WreckageFile = "wreckInformation.csv";
internal const string _ExpectedRecipeMD5 = "11cc2c8e44db4473c6e0d196b869d582";
internal const int _ExpectedSaveVersion = 5;
internal const int _ExpectedSaveVersion = 6;
private static readonly Dictionary<int, string> s_versionDict = new Dictionary<int, string>
{
[1] = "v0.5.1",
[2] = "v0.6.1",
[3] = "v0.7.0",
[4] = "v0.8.2",
[5] = "v0.9.2",
[_ExpectedSaveVersion] = "v" + VERSION
};

Expand Down
9 changes: 8 additions & 1 deletion SubnauticaRandomiser/Logic/CoreLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace SubnauticaRandomiser.Logic
/// </summary>
internal class CoreLogic : MonoBehaviour
{
public static CoreLogic Main;

internal RandomiserConfig _Config { get; private set; }
internal ILogHandler _Log { get; private set; }
internal static EntitySerializer _Serializer { get; private set; }
Expand Down Expand Up @@ -76,6 +78,8 @@ internal class CoreLogic : MonoBehaviour

private void Awake()
{
Main = this;

_fileTasks = new List<Task>();
_handlingModules = new Dictionary<EntityType, ILogicModule>();
_modules = new List<ILogicModule>();
Expand All @@ -101,7 +105,10 @@ private void EnableModules()
if (_Config.bRandomiseFragments || _Config.bRandomiseNumFragments || _Config.bRandomiseDuplicateScans)
RegisterModule<FragmentLogic>();
if (_Config.bRandomiseRecipes)
{
RegisterModule<RawMaterialLogic>();
RegisterModule<RecipeLogic>();
}
}

/// <summary>
Expand Down Expand Up @@ -198,9 +205,9 @@ private IEnumerator RandomiseMainEntities(List<LogicEntity> notRandomised)
if (handler is null)
{
_Log.Warn($"[Core] Unhandled entity in main loop: {nextEntity.EntityType} {nextEntity}");
notRandomised.Remove(nextEntity);
// Add the unhandled entity into logic as a stopgap solution, for cases where a prerequisite check
// would fail because it expects unhandled entities to be in logic first.
notRandomised.Remove(nextEntity);
EntityHandler.AddToLogic(nextEntity);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion SubnauticaRandomiser/Logic/DataboxLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ApplySerializedChanges(EntitySerializer serializer) { }
public void RandomiseOutOfLoop(EntitySerializer serializer)
{
RandomiseDataboxes(serializer);
UpdateBlueprints(_coreLogic.EntityHandler.GetAll());
UpdateBlueprints(_coreLogic.EntityHandler.GetAllEntities());
LinkCyclopsHullModules(_coreLogic.EntityHandler);
}

Expand Down
46 changes: 46 additions & 0 deletions SubnauticaRandomiser/Logic/RawMaterialLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using HarmonyLib;
using SubnauticaRandomiser.Interfaces;
using SubnauticaRandomiser.Objects;
using SubnauticaRandomiser.Objects.Enums;
using SubnauticaRandomiser.Patches;
using UnityEngine;

namespace SubnauticaRandomiser.Logic
{
/// <summary>
/// Rudimentary module to handle raw materials like eggs in the logic.
/// </summary>
[RequireComponent(typeof(CoreLogic))]
internal class RawMaterialLogic : MonoBehaviour, ILogicModule
{
private CoreLogic _coreLogic;
private ProgressionManager _manager;

private void Awake()
{
_coreLogic = GetComponent<CoreLogic>();
_manager = GetComponent<ProgressionManager>();

_coreLogic.RegisterEntityHandler(EntityType.RawMaterial, this);
}

public void ApplySerializedChanges(EntitySerializer serializer) { }

public void RandomiseOutOfLoop(EntitySerializer serializer) { }

public bool RandomiseEntity(ref LogicEntity entity)
{
// Simply add this into the logic if prerequisites and depth check out.
return entity.CheckReady(_coreLogic, _manager.ReachableDepth)
&& entity.AccessibleDepth <= _manager.ReachableDepth;
}

public void SetupHarmonyPatches(Harmony harmony)
{
// This one is an exception and *can* rely on config values because the patch only has to be applied once
// on game start, and the saved data will carry over from then on.
if (CoreLogic._Serializer.DiscoverEggs)
harmony.PatchAll(typeof(EggPatcher));
}
}
}
Loading

0 comments on commit 3519fec

Please sign in to comment.