Simulation.py 1.8KB

123456789101112131415161718192021222324252627282930313233
  1. from synergine.synergy.Simulation import Simulation as BaseSimulation
  2. from xyzworld.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, \
  9. COL_WALKER, ACTION_DIE, COL_ALIVE, ALIVE, ATTACKABLE
  10. # TODO: Mettre ailleurs ?
  11. def bug_die(bug, context):
  12. context.metas.collections.remove_list(bug.get_id(),
  13. [COL_TRANSPORTER_CARRYING, \
  14. COL_TRANSPORTER_NOT_CARRYING, \
  15. COL_WALKER, \
  16. COL_ALIVE],
  17. allow_not_in=True)
  18. context.metas.states.remove_list(bug.get_id(), [ALIVE, ATTACKABLE], allow_not_in=True)
  19. class Simulation(BaseSimulation):
  20. def connect_actions_signals(self, Signals):
  21. Signals.signal(PutableAction).connect(lambda obj, context: \
  22. context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING))
  23. Signals.signal(TakeableAction).connect(lambda obj, context: \
  24. context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING))
  25. Signals.signal(ACTION_DIE).connect(lambda obj, context: bug_die(obj, context))
  26. def end_cycle(self, context):
  27. if context.get_cycle() % 100 is 0:
  28. context.metas.list.clean(POSITIONS)