@@ -211,6 +211,7 @@ def _checkLocationRequiresForItemValueWithRegex(values_requested: dict[str, int]
211211    def  checkIfEnoughItemsForValue ():
212212        values_available  =  {}
213213        values_requested  =  {}
214+         used_regions  =  set (["Manual" ])
214215
215216        # First find the biggest values required by locations 
216217        for  location  in  DataValidation .location_table :
@@ -219,12 +220,40 @@ def checkIfEnoughItemsForValue():
219220
220221            # convert to json so we don't have to guess the data type 
221222            location_requires  =  json .dumps (location ["requires" ])
222- 
223+             if  location .get ('region' ):
224+                 used_regions .add (location ['region' ])
223225            DataValidation ._checkLocationRequiresForItemValueWithRegex (values_requested , location_requires )
224-         # Second, check region requires for the presence of item name 
226+ 
227+         parent_child  =  {}
228+         # First build a parent-child dictionary: 
225229        for  region_name  in  DataValidation .region_table :
226230            region  =  DataValidation .region_table [region_name ]
227231
232+             region_connect_to  =  region .get ("connects_to" , [])
233+             for  child  in  region_connect_to :
234+                 if  child  not  in parent_child .keys ():
235+                     parent_child [child ] =  []
236+                 parent_child [child ].append (region_name )
237+ 
238+         # add parent and their parent to used_regions recursively if any location is present 
239+         checked_parent  =  ['Manual' ]
240+         for  region_name  in  set (used_regions ):
241+             def  checkParent (name ):
242+                 if  name  in  checked_parent : #dont check a region twice 
243+                     return 
244+                 checked_parent .append (name )
245+                 if  name  in  parent_child .keys ():
246+                     for  parent  in  parent_child [name ]:
247+                         checkParent (parent )
248+                         used_regions .add (parent )
249+                 return 
250+             checkParent (region_name )
251+ 
252+         used_regions .remove ('Manual' )
253+         # Second, check region requires of used regions for the presence of ItemValue 
254+         for  region_name  in  used_regions :
255+             region  =  DataValidation .region_table [region_name ]
256+ 
228257            if  "requires"  not  in region :
229258                continue 
230259
@@ -263,12 +292,37 @@ def preFillCheckIfEnoughItemsForValue(world: World, multiworld: MultiWorld):
263292        from  .Helpers  import  get_items_with_value , get_items_for_player 
264293        player  =  world .player 
265294        values_requested  =  {}
295+         player_regions  =  {}
296+         used_regions  =  set (['Manual' ])
266297
298+         #Grab all the player's regions and take note of those with locations 
267299        for  region  in  multiworld .regions :
268300            if  region .player  !=  player :
269301                continue 
270- 
271-             manualregion  =  DataValidation .region_table .get (region .name , {})
302+             player_regions [region .name ] =  region 
303+             if  region .locations :
304+                 used_regions .add (region .name )
305+ 
306+         #Check every known region with location for parent regions 
307+         checked_parent  =  ['Manual' ]
308+         for  region_name  in  set (used_regions ):
309+             def  checkParent (name ):
310+                 region  =  player_regions [name ]
311+                 if  name  in  checked_parent : #dont check a region twice 
312+                     return 
313+                 checked_parent .append (name )
314+                 if  region .entrances :
315+                     for  entrance  in  region .entrances :
316+                         checkParent (entrance .parent_region .name )
317+                         used_regions .add (entrance .parent_region .name )
318+                 return 
319+             checkParent (region_name )
320+ 
321+         used_regions .remove ('Manual' ) #Manual shouldn't have any requires so skip it 
322+         #Check used regions (and their parent(s)) for ItemValue requirement 
323+         for  region_name  in  used_regions :
324+             region  =  player_regions [region_name ]
325+             manualregion  =  DataValidation .region_table .get (region_name , {})
272326            if  "requires"  in  manualregion  and  manualregion ["requires" ]:
273327                region_requires  =  json .dumps (manualregion ["requires" ])
274328
0 commit comments