Skip to content

Remote dungeons type selection with fallbacks #2682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/Resources/defaults.ini.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ TerrainDistance=3
TerrainHeightmapPixelError=5
SmallerDungeons=False
CustomBooksImport=True
AssetCacheThreshold = 25
AssetCacheThreshold=25
DungeonsPoolSizeTarget=3

[Enhancements]
LypyL_GameConsole=True
Expand Down
70 changes: 53 additions & 17 deletions Assets/Scripts/Game/Questing/Place.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Place : QuestResource
int p1; // Parameter 1
int p2; // Parameter 2
int p3; // Parameter 3
int[] alternateDungeonTypeIndices; // DFU extension for remote dungeons

SiteDetails siteDetails; // Site found using inputs

Expand Down Expand Up @@ -143,8 +144,7 @@ public override void SetResource(string line)
base.SetResource(line);

// Match string for Place variants
string matchStr = @"(Place|place) (?<symbol>[a-zA-Z0-9_.-]+) (?<siteType>local|remote|permanent) (?<siteName>\w+)|" +
@"(Place|place) (?<symbol>[a-zA-Z0-9_.-]+) (?<siteType>randompermanent) (?<siteList>[a-zA-Z0-9_.,]+)";
string matchStr = @"(Place|place) (?<symbol>[a-zA-Z0-9_.-]+) (?<siteType>local|remote|permanent|randompermanent) (?<siteList>[a-zA-Z0-9_.,]+)";

// Try to match source line with pattern
bool randomSiteList = false;
Expand Down Expand Up @@ -183,21 +183,22 @@ public override void SetResource(string line)
}

// Get place name for parameter lookup
name = match.Groups["siteName"].Value;
if (string.IsNullOrEmpty(name) && !randomSiteList)
{
throw new Exception(string.Format("Place site name empty for source: '{0}'", line));
}
string srcSiteList = match.Groups["siteList"].Value;
string[] siteNames = srcSiteList.Split(',');

// Pick one permanent place from random site list
if (randomSiteList)
{
string srcSiteList = match.Groups["siteList"].Value;
string[] siteNames = srcSiteList.Split(',');
if (siteNames == null || siteNames.Length == 0)
throw new Exception(string.Format("Place randompermanent must have at least one site name in source: '{0}'", line));
name = siteNames[UnityEngine.Random.Range(0, siteNames.Length)];
}
else // !randomSiteList
{
if (siteNames == null || siteNames.Length == 0)
throw new Exception(string.Format("Place site name empty for source: '{0}'", line));
name = siteNames[0];
}

// Try to read place variables from data table
Table placesTable = QuestMachine.Instance.PlacesTable;
Expand All @@ -213,6 +214,24 @@ public override void SetResource(string line)
throw new Exception(string.Format("Could not find place name in data table: '{0}'", name));
}

// Alternate places (used for remote dungeon types)
if (siteNames.Length > 1)
{
alternateDungeonTypeIndices = new int[siteNames.Length - 1];
for (int i = 1; i < siteNames.Length; i++)
{
if (placesTable.HasValue(siteNames[i]))
{
// Store value
alternateDungeonTypeIndices[i - 1] = CustomParseInt(placesTable.GetValue("p2", siteNames[i]));
}
else
{
throw new Exception(string.Format("Could not find place name in data table: '{0}'", siteNames[i]));
}
}
}

// Handle place by scope
if (scope == Scopes.Local)
{
Expand Down Expand Up @@ -761,7 +780,7 @@ void SetupRemoteSite(string line)
result = SelectRemoteTownSite((DFLocation.BuildingTypes)p2);
break;
case 1:
result = SelectRemoteDungeonSite(p2);
result = SelectRemoteDungeonSite(p2, alternateDungeonTypeIndices);
break;
case 2:
result = SelectRemoteLocationExteriorSite(p2);
Expand All @@ -770,10 +789,6 @@ void SetupRemoteSite(string line)
throw new Exception(string.Format("An unknown P1 value of {0} was encountered for Place {1}", p1, Symbol.Original));
}

// If searching for a dungeon and first numbered choice not found, then try again with any random dungeon type
if (!result && p1 == 1)
result = SelectRemoteDungeonSite(-1);

// Throw exception when remote place could not be selected, e.g. a dungeon of that type does not exist in this region
if (!result)
throw new Exception(string.Format("Search failed to locate matching remote site for Place {0} in region {1}. Resource source: '{2}'", Symbol.Original, GameManager.Instance.PlayerGPS.CurrentRegionName, line));
Expand Down Expand Up @@ -878,7 +893,7 @@ bool SelectRemoteTownSite(DFLocation.BuildingTypes requiredBuildingType)
/// This is probably because types 17-18 don't seem to contain quest markers.
/// Warning: Not all dungeon types are available in all regions. http://en.uesp.net/wiki/Daggerfall:Dungeons#Overview_of_Dungeon_Locations
/// </summary>
bool SelectRemoteDungeonSite(int dungeonTypeIndex)
bool SelectRemoteDungeonSite(int dungeonTypeIndex, int[] alternateDungeonTypeIndices)
{
// Get player region
int regionIndex = GameManager.Instance.PlayerGPS.CurrentRegionIndex;
Expand All @@ -893,14 +908,35 @@ bool SelectRemoteDungeonSite(int dungeonTypeIndex)

// Get indices for all dungeons of this type
int[] foundIndices = CollectDungeonIndicesOfType(regionData, dungeonTypeIndex);

//Debug.LogFormat("Found a total of {0} possible dungeons of type {1} in {2}", foundIndices == null ? 0 : foundIndices.Length, dungeonTypeIndex, regionData.Name);

// Add equivalence(s) if too few dungeons to select from
if (dungeonTypeIndex >= 0 && alternateDungeonTypeIndices != null)
{
int equivalentIndex = 0;
if (foundIndices == null)
{
foundIndices = new int[] {};
}
while (foundIndices.Length < DaggerfallUnity.Settings.DungeonsPoolSizeTarget && alternateDungeonTypeIndices.Length > equivalentIndex)
{
int[] equivalentIndices = CollectDungeonIndicesOfType(regionData, alternateDungeonTypeIndices[equivalentIndex]);
if (equivalentIndices != null && equivalentIndices.Length > 0)
{
// Debug.LogFormat("Adding {0} possible dungeons of type {1} by equivalence", equivalentIndices.Length, alternateDungeonTypeIndices[equivalentIndex]);
foundIndices = foundIndices.Concat(equivalentIndices).ToArray();
}
equivalentIndex++;
}
}

if (foundIndices == null || foundIndices.Length == 0)
{
Debug.LogFormat("Could not find any random dungeons of type {0} in {1}", dungeonTypeIndex, regionData.Name);
return false;
}

//Debug.LogFormat("Found a total of {0} possible dungeons of type {1} in {2}", foundIndices.Length, dungeonTypeIndex, regionData.Name);

// Select a random dungeon location index from available list
int index = UnityEngine.Random.Range(0, foundIndices.Length);

Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ string ReadDistributionSuffix()
public float TerrainHeightmapPixelError { get; set; }
public bool SmallerDungeons { get; set; }
public int AssetCacheThreshold { get; set; }
public int DungeonsPoolSizeTarget { get; set; }

// [Enhancements]
public bool LypyL_GameConsole { get; set; }
Expand Down Expand Up @@ -555,6 +556,7 @@ public void LoadSettings()
TerrainHeightmapPixelError = GetFloat(sectionExperimental, "TerrainHeightmapPixelError", 1, 10);
SmallerDungeons = GetBool(sectionExperimental, "SmallerDungeons");
AssetCacheThreshold = GetInt(sectionExperimental, "AssetCacheThreshold", 0, 120);
DungeonsPoolSizeTarget = GetInt(sectionExperimental, "DungeonsPoolSizeTarget", 0, 999);

LypyL_GameConsole = GetBool(sectionEnhancements, "LypyL_GameConsole");
LypyL_ModSystem = GetBool(sectionEnhancements, "LypyL_ModSystem");
Expand Down Expand Up @@ -747,6 +749,7 @@ public void SaveSettings()
SetFloat(sectionExperimental, "TerrainHeightmapPixelError", TerrainHeightmapPixelError);
SetBool(sectionExperimental, "SmallerDungeons", SmallerDungeons);
SetInt(sectionExperimental, "AssetCacheThreshold", AssetCacheThreshold);
SetInt(sectionExperimental, "DungeonsPoolSizeTarget", DungeonsPoolSizeTarget);

SetBool(sectionEnhancements, "LypyL_GameConsole", LypyL_GameConsole);
SetBool(sectionEnhancements, "LypyL_ModSystem", LypyL_ModSystem);
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/$CUREVAM.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Person _vamp2_ face 4 factiontype Vampire_Clan male remote
Person _hunter_ face 1 factiontype Knightly_Guard remote anyInfo 1011 rumors 1012

Place _fatherdung_ remote dungeon8
Place _wrongdung_ remote dungeon5
Place _wrongdung_ remote dungeon5,dungeon6

Clock _S.10_ 1.00:00 2.22:00
Clock _S.13_ 7.00:00 27.23:40
Expand Down
4 changes: 2 additions & 2 deletions Assets/StreamingAssets/Quests/$CUREWER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ Person _alchemist_ group Chemist remote
Person _father_ face 5 group Noble male remote anyInfo 1013 rumors 1014
Person _local_ group Resident1 remote

Place _mapdung_ remote dungeon4
Place _mapdung_ remote dungeon4,dungeon7
Place glenmorilCoven permanent GlenmorilCoven
Place _childhouse_ remote house2
Place _hintdung_ remote dungeon11
Place _hintdung_ remote dungeon11,dungeon2

Clock _S.05_ 7.00:00 27.23:40
Clock _huntstart_ 60.00:00 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/20C00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Person _dummy_ face 1 group Spellcaster remote

Place _mondung_ remote dungeon9
Place _tavern_ remote tavern
Place _hideout_ remote dungeon11
Place _hideout_ remote dungeon11,dungeon2

Clock _1stparton_ 00:00 0 flag 1 range 0 5
Clock _S.08_ 00:01 00:04
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/60C00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Person _questgiver_ face 112 named Sheogorath anyInfo 1012
Person _qgfriend_ face 1 group Innkeeper remote anyInfo 1011 rumors 1014

Place _mondung_ remote dungeon
Place _contactdung_ remote dungeon3
Place _contactdung_ remote dungeon3,dungeon

Clock _1stparton_ 00:00 0 flag 1 range 2 5

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/70C00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Item _artifact_ artifact Sanguine_Rose anyInfo 1014
Person _questgiver_ face 112 named Sanguine anyInfo 1011
Person _contact_ face 232 faction The_Cabal remote anyInfo 1012

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7

Clock _1stparton_ 00:00 0 flag 1 range 2 5

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/A0C0XY04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Person _dummymage_ face 1 faction The_Mages_Guild remote
Person _dummyorc_ face 1 named Gortwog
Person _dummydarkb_ face 49 faction The_Dark_Brotherhood remote

Place _dungeon_ remote dungeon7
Place _dungeon_ remote dungeon7,dungeon4,dungeon
Place _meetingplace_ local apothecary

Clock _extratime_ 00:30 0 flag 1 range 0 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Person _qgiver_ group Questor
Person _lady_ face 2 group Noble female local
Person _vamp_ face 40 factiontype Vampire_Clan local

Place _mondung_ remote dungeon8
Place _mondung_ remote dungeon8,dungeon

Clock _2mondung_ 00:00 0 flag 17 range 0 2
Clock _S.07_ 10:00 1.16:00
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B10Y04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ QBN:

Person _qgiver_ group Questor

Place _mondung_ remote dungeon1
Place _mondung_ remote dungeon1,dungeon
Place tavern local tavern

Clock _2mondung_ 00:00 0 flag 17 range 0 2
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B40Y08.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ QBN:
Person _qgiver_ group Questor
Person _local_ face 207 group Resident2 female local

Place _dungeon_ remote dungeon1
Place _dungeon_ remote dungeon1,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B40Y09.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Item _gold_ gold
Person _qgiver_ group Questor
Person _local_ face 207 group Resident2 female local

Place _dungeon_ remote dungeon13
Place _dungeon_ remote dungeon13,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B60Y12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Person _qgiver_ group Questor
Person _nobleman_ group Resident1 remote
Person _local_ face 1 group Resident2 local

Place _dungeon_ remote dungeon0
Place _dungeon_ remote dungeon0,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B70Y14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Item _gold_ gold

Person _qgiver_ group Questor

Place _dungeon_ remote dungeon7
Place _dungeon_ remote dungeon7,dungeon4,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B80Y17.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ QBN:
Person _qgiver_ group Questor
Person _local_ face 1 group Resident2 local

Place _dungeon_ remote dungeon0
Place _dungeon_ remote dungeon0,dungeon11,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0B81Y02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Person _wizard_ face 1 group Spellcaster remote
Place _dungeon_ remote dungeon
Place _dungeon2_ remote dungeon
Place _mageguild_ remote magery
Place _dungeon3_ remote dungeon0
Place _dungeon3_ remote dungeon0,dungeon11

Clock _2dung_ 00:00 0 flag 17 range 0 2
Clock _S.30_ 180.13:20 0 flag 1 range 0 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/B0C00Y06.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ QBN:
Person _qgiver_ group Questor
Person _local_ face 207 group Resident2 female local

Place _dungeon_ remote dungeon13
Place _dungeon_ remote dungeon13,dungeon

Clock _2dung_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/C0B00Y01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ Person _prophet_ face 1 group Local_4.0 anyInfo 1038
Person _replace_ face 3 factiontype Temple female anyInfo 1023
Person _lover_ face 104 group Group_7.0 remote anyInfo 1017

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7
Place _tavern_ remote tavern
Place _prophouse_ remote tavern

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/C0B00Y03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ QBN:
Person _qgiver_ group Questor
Person _cleric_ face 105 factiontype Temple

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7,dungeon

Clock _queston_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/C0B00Y14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Item _I.00_ item class 10 subclass 4
Person _questgiver_ group Questor
Person _priest_ group Cleric remote

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7

Clock _qtime_ 00:00 0 flag 17 range 1 5

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/E0B00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Item _reward_ gold

Person _questgiver_ group Questor

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7,dungeon

Clock _1stparton_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/H0B00Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Item _reward_ gold

Person _questgiver_ group Questor

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7

Clock _1stparton_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/K0C00Y02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Item _I.07_ gold
Person _qgiver_ group Questor

Place _depository_ remote bank
Place _mondung_ remote dungeon2
Place _mondung_ remote dungeon2,dungeon15
Place _palace_ remote palace
Place _mansion_ remote house1

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/K0C01Y00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Person _victim_ face 1 group Group_7.0
Person _tg_ faction The_Thieves_Guild local

Place _mondung_ remote dungeon
Place _mondung2_ remote dungeon2
Place _mondung2_ remote dungeon2,dungeon15

Clock _queston1_ 00:00 0 flag 17 range 0 2
Clock _S.05_ 08:20 3.11:20
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/K0C01Y10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Item _bothdorjii_ letter used 1011

Person _qgiver_ group Questor

Place _mondung_ remote dungeon4
Place _mondung_ remote dungeon4,dungeon7

Clock _queston_ 00:00 0 flag 17 range 0 2

Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/Quests/L0B00Y02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Item _letter_ letter used 1011
Person _qgiver_ face 110 group Questor

Place _mondung_ remote dungeon
Place _stronghold_ remote dungeon2
Place _stronghold_ remote dungeon2,dungeon15

Clock _queston_ 00:00 0 flag 17 range 0 5

Expand Down
Loading