Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. class AggressiveTown(Town):
  2. class table:
  3. pass
  4.  
  5. class actions:
  6. bribe = Action(String("Bribe"), AggressiveTown._onActionBribe)
  7. grow_town = Action(String("Grow town"), AggressiveTown._onActionGrowTown)
  8.  
  9. class storage:
  10. PISSED: bool
  11. MY_HOUSE_LOCATION: Location
  12. YUMMINESS: int
  13. ELECTRICITY_SUPPLY_LEVEL: int
  14. GAS_UNDERGROUND: bool
  15. CATS_LAST_DELIVERED: int
  16.  
  17. class Event(Town.Event):
  18. town: AggressiveTown
  19.  
  20. def onPlace(event) -> None:
  21. event.town.storage.PISSED = False
  22.  
  23. event.town.add_timer(AggressiveTown._onTimer, tools.DAY * 10, repeat=Timer.REPEAT_ALWAYS)
  24. event.town.add_timer(AggressiveTown._onCatTimer, tools.DAY * 30, repeat=Timer.REPEAT_ALWAYS)
  25.  
  26. def onTick(event) -> None:
  27. if event.town.storage.YUMMINESS > 0 and event.town.storage.ELECTRICITY_SUPPLY_LEVEL > 0:
  28. event.town.api.GrowTown()
  29. event.town.storage.YUMMINESS -= 10
  30.  
  31. event.town.api.ChangeZone(Location(-1, 0), Zone.Type.SUBURBS)
  32.  
  33. electricity_supply_level = 0
  34. for industry in event.town.api.GetIndustries():
  35. amount = industry.api.GetProduction(Cargo.ELECTRICITY)
  36. if amount:
  37. electricity_supply_level += amount
  38.  
  39. if electricity_supply_level > 10:
  40. event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 2
  41. elif electricity_supply_level > 0:
  42. event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 1
  43. else:
  44. event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 0
  45.  
  46. if tools.today().month() in [11, 12]:
  47. event.town.api.SetZoneStorage(Zone.Type.CITY, 0, True)
  48. else:
  49. event.town.api.SetZoneStorage(Zone.Type.CITY, 0, False)
  50.  
  51. def onDemolish(event, location) -> None:
  52. if location == event.town.storage.MY_HOUSE_LOCATION:
  53. event.town.storage.PISSED = True
  54. event.town.actions.grow_town.disabled = String("The town is pissed at you")
  55.  
  56. def onDelivery(event, cargo, amount) -> None:
  57. if cargo == Cargo.CHEESE:
  58. event.town.storage.YUMMINESS += amount
  59.  
  60. if cargo == Cargo.CATS:
  61. if event.town.storage.CATS_LAST_DELIVERED - tools.today() < 30:
  62. event.town.api.SetPrice(Cargo.CATS, event.town.api.GetPrice(Cargo.CATS) - 10)
  63. event.town.storage.CATS_LAST_DELIVERED = tools.today()
  64.  
  65.  
  66. class Hook:
  67. town: AggressiveTown
  68.  
  69. def onIndustryCreation(hook, type) -> bool:
  70. return hook.town.storage.GAS_UNDERGROUND and hook.town.api.CountIndustries(type='gas_well') < 3
  71.  
  72. def _onActionBribe(town) -> None:
  73. town.storage.PISSED = False
  74. town.actions.grow_town.disabled = None
  75.  
  76. def _onActionGrowTown(town) -> None:
  77. town.api.GrowTown()
  78.  
  79. def _onTimer(town) -> None:
  80. if town.api.CountIndustries(type='cat_farm') < 3:
  81. town.api.CreateIndustry('cat_farm')
  82.  
  83. # transport at least 25% of trash or town hates you
  84. if town.api.TransportedCargos.TRASH < (town.api.ProducedCargos.TRASH / 4);
  85. event.town.storage.PISSED = True
  86.  
  87. def _onCatTimer(town) -> None:
  88. if town.storage.CATS_LAST_DELIVERED - tools.today() >= 30:
  89. town.api.SetPrice(Cargo.CATS, min(town.api.GetPrice(Cargo.CATS) + 20, town.api.GetDefaultPrice(Cargo.CATS)))
  90.  
  91. class Client(Town.Client):
  92. town: AggressiveTown
  93.  
  94. class storage:
  95. LAST_COMMAND: int = 0
  96.  
  97. def GUI(client) -> List[Any]:
  98. res: List[Any] = []
  99.  
  100. if client.town.storage.PISSED:
  101. res.append(String("What have you done?! WE ARE PISSED"))
  102. else:
  103. res.append(String("More cheese please :)"))
  104.  
  105. if client.storage.LAST_COMMAND == 0:
  106. res.append(Button("Click", AggressiveTown.Client._onClickButton))
  107.  
  108. return res
  109.  
  110. def onCommand(client, command: int):
  111. client.storage.LAST_COMMAND = command
  112.  
  113. def _onClickButton(client):
  114. client.SendCommand(1)
  115.  
  116. class Server(Town.Server):
  117. town: AggressiveTown
  118.  
  119. def onCommand(server, command: int):
  120. server.SendCommand(1)
  121.  
  122.  
  123. class MyHouse(House):
  124. town: AggressiveTown
  125.  
  126. class table:
  127. dimension = Dimension(2, 2)
  128. flags = House.Flags.ONLY_SCENARIO_EDITOR | House.Flags.ONE_PER_TOWN
  129. population = 12
  130. accept_cargo = {
  131. Cargo.MAIL: 8
  132. }
  133.  
  134. def onEventPlace(house) -> None:
  135. house.town.storage.MY_HOUSE_LOCATION = house.location
  136.  
  137. def onEventTick(house) -> None:
  138. if tools.random() < house.town.population:
  139. house.api.MoveGoodsToStation(Cargo.PASSENGERS, 100, house.town)
  140.  
  141. class Hook(House.Hook):
  142. house: MyHouse
  143.  
  144. def onGetSprite(hook, offset: Offset) -> Sprite:
  145. zone = hook.house.town.api.GetZone(hook.house.location)
  146.  
  147. if zone.type == Zone.Type.SUBURBS:
  148. return Sprite("myhouse_suburbs.png", offset.x * 50, offset.y * 50, 50, 50)
  149. if zone.storage[0]:
  150. return Sprite("myhouse_city_xmas.png", offset.x * 50, offset.y * 50, 50, 50)
  151. return Sprite("myhouse_city.png", offset.x * 50, offset.y * 50, 50, 50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement