Simulation.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435
  1. from synergine.synergy.Simulation import Simulation as BaseSimulation
  2. from synergine_xyz.cst import POSITION, POSITIONS
  3. #from intelligine.synergy.event.attack.NearAttackableAction import NearAttackableAction
  4. from intelligine.synergy.event.transport.PutableAction import PutableAction
  5. from intelligine.synergy.event.transport.TakeableAction import TakeableAction
  6. from intelligine.synergy.event.move.MoveAction import MoveAction
  7. from intelligine.synergy.event.CycleAction import CycleAction
  8. from intelligine.cst import COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER, \
  9. COL_WALKER, ACTION_DIE, COL_ALIVE, ALIVE, ATTACKABLE
  10. class Simulation(BaseSimulation):
  11. @staticmethod
  12. def event_bug_die(bug, context):
  13. context.metas.collections.remove_list(bug.get_id(),
  14. [COL_TRANSPORTER, \
  15. COL_TRANSPORTER_CARRYING, \
  16. COL_TRANSPORTER_NOT_CARRYING, \
  17. COL_WALKER, \
  18. COL_ALIVE],
  19. allow_not_in=True)
  20. context.metas.states.remove_list(bug.get_id(), [ALIVE, ATTACKABLE], allow_not_in=True)
  21. def connect_actions_signals(self, Signals):
  22. Signals.signal(PutableAction).connect(lambda obj, context: \
  23. context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING))
  24. Signals.signal(TakeableAction).connect(lambda obj, context: \
  25. context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING))
  26. Signals.signal(ACTION_DIE).connect(lambda obj, context: self.event_bug_die(obj, context))
  27. def end_cycle(self, context):
  28. if context.get_cycle() % 100 is 0:
  29. context.metas.list.clean(POSITIONS)