Skip to content

Commit

Permalink
Merge pull request #53 from tinyhoot/living-large-fixes
Browse files Browse the repository at this point in the history
Update to v0.9.1
  • Loading branch information
tinyhoot authored Dec 30, 2022
2 parents e41e0fc + eb62107 commit bd97371
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SubnauticaRandomiser/InitMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SubnauticaRandomiser
public class InitMod : BaseUnityPlugin
{
public const string GUID = "com.github.tinyhoot.SubnauticaRandomiser";
public const string VERSION = "0.9.0";
public const string VERSION = "0.9.1";

internal static string s_modDirectory;
internal static RandomiserConfig s_config;
Expand Down
16 changes: 10 additions & 6 deletions SubnauticaRandomiser/Logic/ProgressionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ public void SetupRecipes(bool useVanillaUpgradeChains)
AddEssentialItem(EProgressionNode.Depth0m, TechType.BaseHatch);
AddEssentialItem(EProgressionNode.Depth0m, TechType.Fabricator);

AddEssentialItem(EProgressionNode.Depth100m, TechType.Builder);
AddEssentialItem(EProgressionNode.Depth100m, TechType.BaseRoom);
AddEssentialItem(EProgressionNode.Depth100m, TechType.Seaglide);
AddEssentialItem(EProgressionNode.Depth100m, TechType.Tank);

AddEssentialItem(EProgressionNode.Depth200m, TechType.Builder);

AddEssentialItem(EProgressionNode.Depth300m, TechType.BaseWaterPark);

// From among these, at least one has to be accessible by the provided
Expand Down Expand Up @@ -421,15 +420,20 @@ public List<TechType[]> GetElectiveItems(int depth)
}

/// <summary>
/// Check whether the given entity is part of any essential or elective items in any node.
/// Check whether the given entity is part of any essential or elective items in any node up to the given depth.
/// </summary>
/// <param name="entity">The entity to check.</param>
/// <param name="depth">Consider entities up to this depth.</param>
/// <returns>True if the entity is part of essential or elective items, false otherwise.</returns>
public bool IsPriorityEntity(LogicEntity entity)
public bool IsPriorityEntity(LogicEntity entity, int depth)
{
if (_essentialItems.Values.Any(list => list.Contains(entity.TechType)))
if (_essentialItems
.Where(kv => !kv.Key.isDeeperThan(depth))
.Any(kv => kv.Value.Contains(entity.TechType)))
return true;
if (_electiveItems.Values.Any(list => list.Any(arr => arr.Contains(entity.TechType))))
if (_electiveItems
.Where(kv => !kv.Key.isDeeperThan(depth))
.Any(kv => kv.Value.Any(arr => arr.Contains(entity.TechType))))
return true;

return false;
Expand Down
1 change: 1 addition & 0 deletions SubnauticaRandomiser/Logic/Recipes/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ protected void UpdateBlacklist(LogicEntity entity)
_blacklist.Add(ETechTypeCategory.Tools);
if (_config.iUpgradesAsIngredients == 0 || (_config.iUpgradesAsIngredients == 1 && entity.CanFunctionAsIngredient()))
{
_blacklist.Add(ETechTypeCategory.ScannerRoom);
_blacklist.Add(ETechTypeCategory.VehicleUpgrades);
_blacklist.Add(ETechTypeCategory.WorkBenchUpgrades);
}
Expand Down
2 changes: 1 addition & 1 deletion SubnauticaRandomiser/Logic/Recipes/RecipeLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RecipeLogic(CoreLogic coreLogic)
internal bool RandomiseRecipe(LogicEntity entity, Dictionary<TechType, bool> unlockedProgressionItems, int reachableDepth)
{
// Does this recipe have all of its prerequisites fulfilled? Skip this check if the recipe is a priority.
if (!(_tree.IsPriorityEntity(entity)
if (!(_tree.IsPriorityEntity(entity, reachableDepth)
|| (entity.CheckBlueprintFulfilled(_logic, reachableDepth) && entity.CheckPrerequisitesFulfilled(_logic))))
{
_log.Debug($"[R] --- Recipe [{entity}] did not fulfill requirements, skipping.");
Expand Down
10 changes: 10 additions & 0 deletions SubnauticaRandomiser/Objects/Enums/EProgressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ public static class EProgressionNodeExtensions
EProgressionNode.Depth1300m,
EProgressionNode.Depth1700m
};

/// <summary>
/// Is this node deeper the given depth?
/// </summary>
public static bool isDeeperThan(this EProgressionNode node, int depth)
{
if (node.Equals(EProgressionNode.None))
return false;
return (int)node > depth;
}
}
}
4 changes: 2 additions & 2 deletions Tests/UnitTests/Logic/ProgressionTreeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ public void TestGetBaseOfUpgrade_Entity_Null()
}

[TestCase(TechType.Seaglide, ExpectedResult = true)]
[TestCase(TechType.Battery, ExpectedResult = true)]
[TestCase(TechType.Battery, ExpectedResult = false)]
[TestCase(TechType.Seamoth, ExpectedResult = false)]
public bool TestIsPriorityEntity(TechType techType)
{
_tree._essentialItems.Add(EProgressionNode.Depth100m, new List<TechType> { TechType.Seaglide });
_tree._electiveItems.Add(EProgressionNode.Depth300m, new List<TechType[]>{ new [] { TechType.Battery }});

LogicEntity entity = new LogicEntity(techType, ETechTypeCategory.None);
return _tree.IsPriorityEntity(entity);
return _tree.IsPriorityEntity(entity, 128);
}

[TestCase(TechType.Benzene, ExpectedResult = true)]
Expand Down

0 comments on commit bd97371

Please sign in to comment.