Loading

Paste #podilmqzz

  1. class IndustryLocationChecks(object):
  2.     """class to hold location checks for an industry"""
  3.     def __init__(self, **kwargs):
  4.         self.incompatible = kwargs.get('incompatible', {})
  5.  
  6.     def get_render_tree(self, switch_prefix):
  7.         result = [LocationCheckFounder()]
  8.         for industry_type, distance in self.incompatible.items():
  9.             result.append(LocationCheckIncompatible(industry_type, distance))
  10.         prev = None
  11.         for lc in reversed(result):
  12.             if prev is not None:
  13.                 lc.switch_result = switch_prefix + prev.switch_entry_point
  14.             prev = lc
  15.         return list(reversed(result))
  16.  
  17.  
  18. class LocationCheckIncompatible(object):
  19.     """prevent locating near incompatible industry types"""
  20.     def __init__(self, industry_type, distance):
  21.         self.industry_type = industry_type
  22.         self.distance = distance
  23.         self.switch_result = 'return CB_RESULT_LOCATION_ALLOW' # default result, value may also be id for next switch
  24.         self.switch_entry_point = self.industry_type
  25.  
  26.     def render(self):
  27.         return 'CHECK_INCOMPATIBLE (' + self.industry_type + ', ' + str(self.distance) + ', CB_RESULT_LOCATION_DISALLOW, ' + self.switch_result + ')'
  28.  
  29.  
  30. class LocationCheckFounder(object):
  31.     """ensures player can build irrespective of _industry_ location checks (tile checks still apply)"""
  32.     def __init__(self):
  33.         self.switch_result = 'return CB_RESULT_LOCATION_ALLOW' # default result, value may also be id for next switch
  34.         self.switch_entry_point = 'check_founder'
  35.  
  36.     def render(self):
  37.         return 'CHECK_FOUNDER (' + self.switch_result + ')'

Comments