class City(Building): TYPE = "city" STATS = entity_stats(TYPE) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.default_state = GeneratingState(self) self.reset()
class Trainer(Building): TYPE = "trainer" STATS = entity_stats(TYPE) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.default_state = IdleState(self) self.reset()
class MatterCollector(Building): TYPE = "matterCollector" STATS = entity_stats(TYPE) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.default_state = GeneratingState(self) self.reset()
class Fighter(Unit): TYPE = "fighter" STATS = entity_stats(TYPE) def __init__(self, *args, **kwargs): super(Fighter, self).__init__(*args, **kwargs) self.default_state = GuardingState(self) self.reset()
class Builder(Unit): TYPE = "builder" STATS = entity_stats(TYPE) def __init__(self, *args, **kwargs): super(Builder, self).__init__(*args, **kwargs) self.default_state = WaitingToBuildState(self) self.reset()
class Entity: TYPE = "unknown" STATS = entity_stats(TYPE) def __init__(self, owner, grid_x, grid_y, starting_health=1.0): self.owner = owner self.terrain_view = owner.terrain_view self.default_state = IdleState(self) self.grid_x = self.terrain_view.terrain.align_x(grid_x) self.grid_y = self.terrain_view.terrain.align_y(grid_y) self.state = self.default_state self.health = starting_health self.exists = False def tick(self, dt): self.state.tick(dt) if self.health < 0: self.owner.delete_entity(self) @property def state(self): return self._state @state.setter def state(self, state): self._state = state state.start() def get_self(self): return { "type": self.TYPE, "state": self.state.get_self(), "health": self.health, "x": self.grid_x, "y": self.grid_y, "id": id(self), } def reset(self): self.state = self.default_state
class Scout(Unit): TYPE = "scout" STATS = entity_stats(TYPE)