@@ -958,7 +958,7 @@ public RandomizerProperties Export(Random r)
958958 }
959959
960960
961- properties . PalaceLengths = Palaces . RollPalaceLengths ( r , properties , this ) ;
961+ properties . PalaceLengths = Palaces . RollPalaceLengths ( this , properties , r ) ;
962962
963963 properties . DarkLinkMinDistance = GetDarkLinkMinDistance ( ) ;
964964
@@ -1631,34 +1631,8 @@ public void AssignPalaceItemCounts(RandomizerProperties properties, Random r)
16311631 //I'm not sure whether I like the bias introduced in generating random values and then capping them
16321632 //vs just determining min/max ranges and fair rolling between them. Keeping it for now.
16331633 int [ ] palaceItemRoomsMin = palaceItemRoomCount == PalaceItemRoomCount . RANDOM_INCLUDE_ZERO ? [ 0 , 0 , 0 , 0 , 0 , 0 ] : [ 1 , 1 , 1 , 1 , 1 , 1 ] ;
1634- // To keep weighting consistent between 0-item and 1-item rooms across
1635- // Standard, Max Rando, etc., we roll the room count the same way
1636- // regardless of palace type. This also reduces how much (imperfect)
1637- // information the item count reveals about the palace style.
1638- int [ ] palaceItemRoomsMax = palaceItemRoomCount switch
1639- {
1640- PalaceItemRoomCount . ZERO => [ 0 , 0 , 0 , 0 , 0 , 0 ] ,
1641- PalaceItemRoomCount . ONE => [ 1 , 1 , 1 , 1 , 1 , 1 ] ,
1642- PalaceItemRoomCount . TWO => [ 2 , 2 , 2 , 2 , 2 , 2 ] ,
1643- PalaceItemRoomCount . RANDOM_NOT_ZERO or
1644- PalaceItemRoomCount . RANDOM_INCLUDE_ZERO =>
1645- properties . PalaceLengths . Select ( len => len switch
1646- {
1647- < 14 => 1 ,
1648- < 24 => 2 ,
1649- _ => 3 ,
1650- } ) . ToArray ( ) ,
1651- _ => throw new NotImplementedException ( ) ,
1652- } ;
1653- // We have to cap the number of item rooms for some styles.
1654- // Vanilla, because it doesn't make sense to change any rooms,
1655- // and Vanilla Shuffled, because it crashes with more than two.
1656- int [ ] palaceItemRoomsLimit = properties . PalaceStyles . Select ( style => style switch
1657- {
1658- PalaceStyle . VANILLA => 1 ,
1659- PalaceStyle . SHUFFLED => 2 ,
1660- _ => int . MaxValue ,
1661- } ) . ToArray ( ) ;
1634+ int [ ] palaceItemRoomsMax = GetPalaceItemRoomMaxCounts ( palaceItemRoomCount , properties . PalaceLengths ) ;
1635+ int [ ] palaceItemRoomsLimit = GetPalaceItemRoomLimits ( properties . PalaceStyles ) ;
16621636
16631637 switch ( palaceItemRoomCount )
16641638 {
@@ -1702,6 +1676,43 @@ PalaceItemRoomCount.RANDOM_NOT_ZERO or
17021676 }
17031677 }
17041678
1679+ /// Note: this value can be limited by other things, like the style being Vanilla
1680+ public static int [ ] GetPalaceItemRoomMaxCounts ( PalaceItemRoomCount palaceItemRoomCount , int [ ] palaceLengths )
1681+ {
1682+ // To keep weighting consistent between 0-item and 1-item rooms across
1683+ // Standard, Max Rando, etc., we roll the room count the same way
1684+ // regardless of palace type. This also reduces how much (imperfect)
1685+ // information the item count reveals about the palace style.
1686+ return palaceItemRoomCount switch
1687+ {
1688+ PalaceItemRoomCount . ZERO => [ 0 , 0 , 0 , 0 , 0 , 0 ] ,
1689+ PalaceItemRoomCount . ONE => [ 1 , 1 , 1 , 1 , 1 , 1 ] ,
1690+ PalaceItemRoomCount . TWO => [ 2 , 2 , 2 , 2 , 2 , 2 ] ,
1691+ PalaceItemRoomCount . RANDOM_NOT_ZERO or
1692+ PalaceItemRoomCount . RANDOM_INCLUDE_ZERO =>
1693+ palaceLengths . Select ( len => len switch
1694+ {
1695+ < 16 => 1 ,
1696+ < 26 => 2 ,
1697+ _ => 3 ,
1698+ } ) . ToArray ( ) ,
1699+ _ => throw new NotImplementedException ( ) ,
1700+ } ;
1701+ }
1702+
1703+ public static int [ ] GetPalaceItemRoomLimits ( PalaceStyle [ ] palaceStyles )
1704+ {
1705+ // We have to cap the number of item rooms for some styles.
1706+ // Vanilla, because it doesn't make sense to change any rooms,
1707+ // and Vanilla Shuffled, because it crashes with more than two.
1708+ return palaceStyles . Select ( style => style switch
1709+ {
1710+ PalaceStyle . VANILLA => 1 ,
1711+ PalaceStyle . SHUFFLED => 2 ,
1712+ _ => int . MaxValue ,
1713+ } ) . ToArray ( ) ;
1714+ }
1715+
17051716 /// Let the user know when their combination of flags will not be
17061717 /// possible to achieve.
17071718 ///
@@ -1714,10 +1725,6 @@ public void CheckForFlagConflicts()
17141725 {
17151726 requiredMinorItemReplacements = 4 - ( startingHeartContainersMax ?? 4 ) ;
17161727 }
1717- if ( palaceItemRoomCount == PalaceItemRoomCount . ZERO )
1718- {
1719- requiredMinorItemReplacements += 6 ;
1720- }
17211728 if ( CountPossibleMinorItems ( ) < requiredMinorItemReplacements )
17221729 {
17231730 throw new UserFacingException ( "Impossible Item Flags" , "Not enough possible item locations for removed palace items.\n \n Add more starting items or more palace items." ) ;
@@ -1906,6 +1913,13 @@ private int CountPossibleMinorItems()
19061913
19071914 count += 4 - ( 8 - ( startingMagicContainersMax ?? 8 ) ) ;
19081915
1916+ var palaceLengthsMax = Palaces . VANILLA_LENGTHS [ ..6 ] . Select ( n => Palaces . MaxLengthRoll ( n , normalPalaceLength ) ) . ToArray ( ) ;
1917+ var itemCountMaxRoll = GetPalaceItemRoomMaxCounts ( palaceItemRoomCount , palaceLengthsMax ) ;
1918+ var itemCountLimit = GetPalaceItemRoomLimits ( Enumerable . Repeat ( normalPalaceStyle , 6 ) . ToArray ( ) ) ;
1919+ var palaceItemsMaxDiff = itemCountMaxRoll . Zip ( itemCountLimit , Math . Min ) . Sum ( n => n - 1 ) ;
1920+
1921+ count += palaceItemsMaxDiff ;
1922+
19091923 return count ;
19101924 }
19111925
0 commit comments