-
-
Save andythenorth/fa91106044e0d62afe485443a1681a43 to your computer and use it in GitHub Desktop.
My Town Mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AggressiveTown(Town): | |
class table: | |
pass | |
class actions: | |
bribe = Action(String("Bribe"), AggressiveTown._onActionBribe) | |
grow_town = Action(String("Grow town"), AggressiveTown._onActionGrowTown) | |
class storage: | |
PISSED: bool | |
MY_HOUSE_LOCATION: Location | |
YUMMINESS: int | |
ELECTRICITY_SUPPLY_LEVEL: int | |
GAS_UNDERGROUND: bool | |
CATS_LAST_DELIVERED: int | |
class Event(Town.Event): | |
town: AggressiveTown | |
def onPlace(event) -> None: | |
event.town.storage.PISSED = False | |
event.town.add_timer(AggressiveTown._onTimer, tools.DAY * 10, repeat=Timer.REPEAT_ALWAYS) | |
event.town.add_timer(AggressiveTown._onCatTimer, tools.DAY * 30, repeat=Timer.REPEAT_ALWAYS) | |
def onTick(event) -> None: | |
if event.town.storage.YUMMINESS > 0 and event.town.storage.ELECTRICITY_SUPPLY_LEVEL > 0: | |
event.town.api.GrowTown() | |
event.town.storage.YUMMINESS -= 10 | |
event.town.api.ChangeZone(Location(-1, 0), Zone.Type.SUBURBS) | |
electricity_supply_level = 0 | |
for industry in event.town.api.GetIndustries(): | |
amount = industry.api.GetProduction(Cargo.ELECTRICITY) | |
if amount: | |
electricity_supply_level += amount | |
if electricity_supply_level > 10: | |
event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 2 | |
elif electricity_supply_level > 0: | |
event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 1 | |
else: | |
event.town.storage.ELECTRICITY_SUPPLY_LEVEL = 0 | |
if tools.today().month() in [11, 12]: | |
event.town.api.SetZoneStorage(Zone.Type.CITY, 0, True) | |
else: | |
event.town.api.SetZoneStorage(Zone.Type.CITY, 0, False) | |
def onDemolish(event, location) -> None: | |
if location == event.town.storage.MY_HOUSE_LOCATION: | |
event.town.storage.PISSED = True | |
event.town.actions.grow_town.disabled = String("The town is pissed at you") | |
def onDelivery(event, cargo, amount) -> None: | |
if cargo == Cargo.CHEESE: | |
event.town.storage.YUMMINESS += amount | |
if cargo == Cargo.CATS: | |
if event.town.storage.CATS_LAST_DELIVERED - tools.today() < 30: | |
event.town.api.SetPrice(Cargo.CATS, event.town.api.GetPrice(Cargo.CATS) - 10) | |
event.town.storage.CATS_LAST_DELIVERED = tools.today() | |
class Hook: | |
town: AggressiveTown | |
def onIndustryCreation(hook, type) -> bool: | |
return hook.town.storage.GAS_UNDERGROUND and hook.town.api.CountIndustries(type='gas_well') < 3 | |
def _onActionBribe(town) -> None: | |
town.storage.PISSED = False | |
town.actions.grow_town.disabled = None | |
def _onActionGrowTown(town) -> None: | |
town.api.GrowTown() | |
def _onTimer(town) -> None: | |
if town.api.CountIndustries(type='cat_farm') < 3: | |
town.api.CreateIndustry('cat_farm') | |
# transport at least 25% of trash or town hates you | |
if town.api.TransportedCargos.TRASH < (town.api.ProducedCargos.TRASH / 4); | |
event.town.storage.PISSED = True | |
def _onCatTimer(town) -> None: | |
if town.storage.CATS_LAST_DELIVERED - tools.today() >= 30: | |
town.api.SetPrice(Cargo.CATS, min(town.api.GetPrice(Cargo.CATS) + 20, town.api.GetDefaultPrice(Cargo.CATS))) | |
class Client(Town.Client): | |
town: AggressiveTown | |
class storage: | |
LAST_COMMAND: int = 0 | |
def GUI(client) -> List[Any]: | |
res: List[Any] = [] | |
if client.town.storage.PISSED: | |
res.append(String("What have you done?! WE ARE PISSED")) | |
else: | |
res.append(String("More cheese please :)")) | |
if client.storage.LAST_COMMAND == 0: | |
res.append(Button("Click", AggressiveTown.Client._onClickButton)) | |
return res | |
def onCommand(client, command: int): | |
client.storage.LAST_COMMAND = command | |
def _onClickButton(client): | |
client.SendCommand(1) | |
class Server(Town.Server): | |
town: AggressiveTown | |
def onCommand(server, command: int): | |
server.SendCommand(1) | |
class MyHouse(House): | |
town: AggressiveTown | |
class table: | |
dimension = Dimension(2, 2) | |
flags = House.Flags.ONLY_SCENARIO_EDITOR | House.Flags.ONE_PER_TOWN | |
population = 12 | |
accept_cargo = { | |
Cargo.MAIL: 8 | |
} | |
def onEventPlace(house) -> None: | |
house.town.storage.MY_HOUSE_LOCATION = house.location | |
def onEventTick(house) -> None: | |
if tools.random() < house.town.population: | |
house.api.MoveGoodsToStation(Cargo.PASSENGERS, 100, house.town) | |
class Hook(House.Hook): | |
house: MyHouse | |
def onGetSprite(hook, offset: Offset) -> Sprite: | |
zone = hook.house.town.api.GetZone(hook.house.location) | |
if zone.type == Zone.Type.SUBURBS: | |
return Sprite("myhouse_suburbs.png", offset.x * 50, offset.y * 50, 50, 50) | |
if zone.storage[0]: | |
return Sprite("myhouse_city_xmas.png", offset.x * 50, offset.y * 50, 50, 50) | |
return Sprite("myhouse_city.png", offset.x * 50, offset.y * 50, 50, 50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment