Added MainPathCopyNodeBehaviour

Added README
This commit is contained in:
LadyAliceMargatroid 2024-07-29 19:07:14 -07:00
parent eebf00988e
commit 70f6ce5154
6 changed files with 92 additions and 11 deletions

View File

@ -11,6 +11,11 @@ namespace DunGenPlus
public class API {
public static bool AddDunGenExtender(DungeonFlow dungeonFlow, DunGenExtender dunGenExtender) {
if (dungeonFlow == null) {
Plugin.logger.LogError("dungeonFlow was null");
return false;
}
if (Plugin.DunGenExtenders.ContainsKey(dungeonFlow)) {
Plugin.logger.LogWarning($"Already contains DunGenExtender asset for {dungeonFlow.name}");
return false;
@ -22,5 +27,14 @@ namespace DunGenPlus
return true;
}
public static bool AddDunGenExtender(DunGenExtender dunGenExtender) {
if (dunGenExtender == null) {
Plugin.logger.LogError("dunGenExtender was null");
return false;
}
return AddDunGenExtender(dunGenExtender.DungeonFlow, dunGenExtender);
}
}
}

View File

@ -28,7 +28,7 @@ namespace DunGenPlus {
}
foreach(var e in extenders){
API.AddDunGenExtender(e.DungeonFlow, e);
API.AddDunGenExtender(e);
}
}

View File

@ -12,12 +12,20 @@ namespace DunGenPlus.Collections {
[System.Serializable]
public class DunGenExtenderProperties {
public enum CopyNodeBehaviour {
CopyFromMainPathPosition,
CopyFromNodeList
}
[Header("Main Path")]
[Tooltip("The number of main paths.\n\n1 means no additional main paths\n3 means two additional main paths\netc.")]
[Range(1, 9)]
public int MainPathCount = 1;
[Tooltip("The Tile Prefab where the additional main paths will start from. Cannot be null if MainPathCount is more than 1.\n\nHighly advice for this Tile Prefab to have multiple doorways.")]
public GameObject MainRoomTilePrefab;
[Tooltip("CopyFromMainPathPosition means that nodes will copy from the MainRoomTilePrefab's position in the main path.\n\nCopyFromNodeList means that nodes will copy from the MainRoomTilePrefab's location from the node list + 1.")]
public CopyNodeBehaviour MainPathCopyNodeBehaviour = CopyNodeBehaviour.CopyFromMainPathPosition;
//public bool MainPathCopyInjectionTiles;
[Header("Dungeon Bounds")]
[Tooltip("If enabled, restricts the dungeon's generation to the bounds described below.\n\nThis will help in condensing the dungeon, but it will increase the chance of dungeon generation failure (potentially guarantees failure if the bounds is too small).")]
@ -33,7 +41,7 @@ namespace DunGenPlus.Collections {
[Header("Archetypes on Normal Nodes")]
[Tooltip("If enabled, adds archetypes to the normal nodes in the DungeonFlow.\n\nBy default, nodes cannot have branching paths since they don't have archetype references. This allows nodes to have branching paths.")]
public bool AddArchetypesToNormalNodes = true;
public bool AddArchetypesToNormalNodes = false;
public List<NodeArchetype> NormalNodeArchetypes;
internal Dictionary<string, NodeArchetype> _normalNodeArchetypesDictioanry;
internal NodeArchetype _defaultNodeArchetype;
@ -104,6 +112,8 @@ namespace DunGenPlus.Collections {
copy.MainPathCount = MainPathCount;
copy.MainRoomTilePrefab = MainRoomTilePrefab;
copy.MainPathCopyNodeBehaviour = MainPathCopyNodeBehaviour;
//copy.MainPathCopyInjectionTiles = MainPathCopyInjectionTiles;
copy.UseDungeonBounds = UseDungeonBounds;
copy.DungeonSizeBase = DungeonSizeBase;

View File

@ -18,5 +18,8 @@ namespace DunGenPlus {
public DunGenExtenderProperties Properties;
public DunGenExtenderEvents Events;
[Header("DEV ONLY: DON'T TOUCH")]
public string Version = "0";
}
}

View File

@ -130,13 +130,19 @@ namespace DunGenPlus.Generation {
// nodes
var nodesSorted = gen.DungeonFlow.Nodes.OrderBy(n => n.Position).ToList();
var startingNodeIndex = nodesSorted.FindIndex(n => n.TileSets.SelectMany(t => t.TileWeights.Weights).Any(t => t.Value == Properties.MainRoomTilePrefab));
if (startingNodeIndex == -1) {
Plugin.logger.LogWarning($"Switching to default dungeon branch generation due to MainRoomTilePrefab not existing in the Nodes' tilesets");
ActiveAlternative = false;
yield return gen.Wait(gen.GenerateBranchPaths());
ActiveAlternative = true;
yield break;
var startingNodeIndexCache = -1;
if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromNodeList) {
startingNodeIndexCache = nodesSorted.FindIndex(n => n.TileSets.SelectMany(t => t.TileWeights.Weights).Any(t => t.Value == Properties.MainRoomTilePrefab));
if (startingNodeIndexCache == -1) {
Plugin.logger.LogWarning($"Switching to default dungeon branch generation due to CopyNodeBehaviour being CopyFromNodeList AND MainRoomTilePrefab not existing in the Nodes' tilesets");
ActiveAlternative = false;
yield return gen.Wait(gen.GenerateBranchPaths());
ActiveAlternative = true;
yield break;
}
startingNodeIndexCache++;
}
//FixDoorwaysToAllFloors(mainRoom, doorwayGroups);
@ -152,7 +158,18 @@ namespace DunGenPlus.Generation {
var newMainPathTiles = new List<TileProxy>();
newMainPathTiles.Add(mainRoom);
var nodes = nodesSorted.Skip(startingNodeIndex + 1);
int startingNodeIndex;
if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromMainPathPosition) {
var lineDepthRatio = Mathf.Clamp01(1f / (targetLength - 1));
startingNodeIndex = nodesSorted.FindIndex(n => n.Position >= lineDepthRatio);
} else if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromNodeList) {
startingNodeIndex = startingNodeIndexCache;
} else {
Plugin.logger.LogError($"{Properties.MainPathCopyNodeBehaviour} is not yet defined. How did this happen?");
startingNodeIndex = -1;
}
var nodes = nodesSorted.Skip(startingNodeIndex);
var nodesVisited = new List<GraphNode>(nodes.Count());
// most of this code is a mix of the GenerateMainPath()

View File

@ -1,2 +1,39 @@
# DungeonGenerationPlus_LethalCompany_Mod
# Dungeon Generation Plus
An API to expand the compatibilities of Lethal Company's dungeon generation.
This mod is for interior modders to add to their projects if they so desire. By itself, this mod cannot improve the dungeon generation of vanilla dungeons.
This API was originally a part of the custom interior, [Scarlet Devil Mansion](https://thunderstore.io/c/lethal-company/p/Alice/ScarletDevilMansion/).
## How to Setup and Use
Please refer to the [wiki](https://git.touhou.dev/Raphtalia/DungeonGenerationPlus_LethalCompany_Mod/wiki) for documentation on utilizing this API for your custom interior.
## Multiple Main Paths
The prominent feature of this API is the ability to seemlesly add multiple main paths to your interior. Below are some examples.
![](https://i.imgur.com/nN5Zz5e.png)
![](https://i.imgur.com/ogrUKAI.png)
![](https://i.imgur.com/IRjMb9V.png)
![](https://i.imgur.com/URTcLNF.png)
## Credits
LadyEbony.itch.io - Code\
gav - Mod icon\
@albinogeek (Discord) - Wiki proofreading\
@bsl (Discord) - Beta testing
#### License
Released under Creative Commons Attribution License. Do what you want, you don't need my permission. You only have to include the text blob above, with the names and their contributions, somewhere reasonably visible in your mod page or whatever you doing.
## Contact
Any complaints or questions can asked in this [discord thread](https://discordapp.com/channels/1168655651455639582/1195583267546595389). You can also dm personally at this [discord](https://discord.gg/M7aZKP9Qvc), LadyRaphtalia. Please do not send a friend request, I will not accept it.