Exemplo n.º 1
0
	def remove(self):
		self.session.world.ships.remove(self)
		self.session.view.discard_change_listener(self.draw_health)
		if self.in_ship_map:
			if self.position.to_tuple() in self.session.world.ship_map:
				del self.session.world.ship_map[self.position.to_tuple()]
			else:
				self.log.error("Ship %s had in_ship_map flag set as True "
				               "but tuple %s was not found in world.ship_map",
				               self, self.position.to_tuple())
			if self._next_target.to_tuple() in self.session.world.ship_map:
				del self.session.world.ship_map[self._next_target.to_tuple()]
			self.in_ship_map = False
		ShipDestroyed.broadcast(self)
		super(Ship, self).remove()
Exemplo n.º 2
0
	def __init(self, target_ship):
		self.target_ship = target_ship

		self.combatIntermissions = {
			self.missionStates.sailing_to_target: (self.sail_to_target, self.flee_home),
			self.missionStates.in_combat: (self.check_ship_alive, self.flee_home),
			self.missionStates.fleeing_home: (self.flee_home, self.flee_home),
		}

		self._state_fleet_callbacks = {
			self.missionStates.sailing_to_target: Callback(self.was_reached),
			self.missionStates.fleeing_home: Callback(self.report_failure, "Combat was lost, ships fled home successfully"),
		}

		ShipDestroyed.subscribe(self._on_ship_destroyed)
Exemplo n.º 3
0
	def remove(self):
		self.session.world.ships.remove(self)
		self.session.view.discard_change_listener(self.draw_health)
		if self.in_ship_map:
			if self.position.to_tuple() in self.session.world.ship_map:
				del self.session.world.ship_map[self.position.to_tuple()]
			else:
				self.log.error("Ship %s had in_ship_map flag set as True "
				               "but tuple %s was not found in world.ship_map",
				               self, self.position.to_tuple())
			if self._next_target.to_tuple() in self.session.world.ship_map:
				del self.session.world.ship_map[self._next_target.to_tuple()]
			self.in_ship_map = False
		ShipDestroyed.broadcast(self)
		super(Ship, self).remove()
Exemplo n.º 4
0
	def end(self):
		if self.target_ship.in_ship_map:
			ShipDestroyed.unsubscribe(self._on_ship_destroyed)
		super(ChaseShipsAndAttack, self).end()
Exemplo n.º 5
0
	def _on_ship_destroyed(self, msg):
		if msg.sender is self.target_ship:
			self.check_ship_alive()
			assert not self.target_ship.in_ship_map
			ShipDestroyed.unsubscribe(self._on_ship_destroyed)
Exemplo n.º 6
0
	def end(self):
		if self.target_ship.in_ship_map:
			ShipDestroyed.unsubscribe(self._on_ship_destroyed)
		super().end()