Example #1
0
	def execute_moves(self, players):
		result_signals = []
		for player in players:
			# unpack required information
			angle, distance = player.move_action
			# calculate new values
			x, y = util.move_wrapped(player.location, angle, distance, (self.width, self.height))
			# log action and subtract energy cost
			cost = game.move_cost(distance)
			# TODO: truncate location tuples to x decimals
			logging.info('player {} moved from {} to {} (cost: {})'.format(
				player.name,
				player.location,
				(x, y),
				cost
			))
			prev_energy = player.energy
			player.energy -= cost
			self.emit_event(
				type = 'player_move',
				player = player.name,
				angle = angle,
				distance = distance,
				location = (player.location, (x, y)),
				cost = cost,
				energy = (prev_energy, player.energy)
			)
			if player.energy <= 0.0:
				# signal player is dead
				result_signals.append(self.player_death(player))
				self.emit_event(
					type = 'player_suicide',
					player = player.name,
					action = 'move',
					cost = cost,
					energy = (prev_energy, player.energy)
				)
				logging.info('player {} died from exhaustion (move)'.format(player.name))
			else:
				# move player on the battlefield
				player.location = (x, y)
		return result_signals
Example #2
0
 def execute_moves(self, players):
     result_signals = []
     for player in players:
         # unpack required information
         angle, distance = player.move_action
         # calculate new values
         x, y = util.move_wrapped(player.location, angle, distance,
                                  (self.width, self.height))
         # log action and subtract energy cost
         cost = game.move_cost(distance)
         # TODO: truncate location tuples to x decimals
         logging.info('player {} moved from {} to {} (cost: {})'.format(
             player.name, player.location, (x, y), cost))
         prev_energy = player.energy
         player.energy -= cost
         self.emit_event(type='player_move',
                         player=player.name,
                         angle=angle,
                         distance=distance,
                         location=(player.location, (x, y)),
                         cost=cost,
                         energy=(prev_energy, player.energy))
         if player.energy <= 0.0:
             # signal player is dead
             result_signals.append(self.player_death(player))
             self.emit_event(type='player_suicide',
                             player=player.name,
                             action='move',
                             cost=cost,
                             energy=(prev_energy, player.energy))
             logging.info('player {} died from exhaustion (move)'.format(
                 player.name))
         else:
             # move player on the battlefield
             player.location = (x, y)
     return result_signals
Example #3
0
    def execute_fires(self, players):
        result_signals = []
        for player in players:
            # unpack required information
            (angle, distance, radius, charge) = player.fire_action
            # TODO: log fire action for player

            # calculate the epicenter of the blast
            epicenter = util.move_wrapped(player.location, angle, distance,
                                          (self.width, self.height))

            # subtract energy cost
            cost = game.fire_cost(distance, radius, charge)
            logging.info(
                'player {} at {} fired at {} (radius: {}, charge: {})'.format(
                    player.name, player.location, epicenter, radius, charge))

            prev_energy = player.energy
            player.energy -= cost

            # emit player fire event
            self.emit_event(type='player_fire',
                            player=player.name,
                            location=player.location,
                            angle=angle,
                            distance=distance,
                            radius=radius,
                            charge=charge,
                            cost=cost,
                            epicenter=epicenter,
                            energy=(prev_energy, player.energy))

            if player.energy <= 0.0:
                # signal player is dead
                result_signals.append(self.player_death(player))
                self.emit_event(type='player_suicide',
                                action='fire',
                                cost=cost,
                                energy=(prev_energy, player.energy))
                # XXX: possibly more to do with hitting one's self
                logging.info('player {} died from exhaustion (fire)'.format(
                    player.name))

            # calculate the bounding box for the blast
            bounds = (epicenter[0] - radius, epicenter[1] - radius,
                      epicenter[0] + radius, epicenter[1] + radius)
            # collect all players in the bounding box for the blast
            subjects = set()
            for region in util.generate_wrapped_bounds(
                (0, 0, self.width, self.height), bounds):
                subjects = subjects.union(self.find_players(region))

            # create a wrapped radius to check distance against
            radius = util.WrappedRadius(epicenter, radius,
                                        (self.width, self.height))
            # check if subject in blast radius (bounding box possibly selects too many players)
            for subject in subjects:
                # calculate distance to epicenter for all subjects, signal hit if ... hit
                if subject.location in radius:
                    # subtract energy equal to charge from subject that was hit
                    prev_energy = subject.energy
                    subject.energy -= charge
                    # emit player hit event
                    self.emit_event(type='player_hit',
                                    player=subject.name,
                                    location=subject.location,
                                    epicenter=epicenter,
                                    radius=radius,
                                    charge=charge,
                                    energy=(prev_energy, subject.energy),
                                    fatal=subject.energy <= 0.0,
                                    attacker=player.name,
                                    attacker_location=player.location,
                                    attacker_energy=player.energy)
                    # signal the subject it was hit
                    result_signals.append(
                        (player.signal_hit, player.name,
                         util.angle(
                             radius.distance(subject.location)[1],
                             epicenter), charge))
                    logging.info(
                        'player {} hit {} for {} (new energy: {})'.format(
                            player.name, subject.name, charge, subject.energy))
                    # check to see if the subject died from this hit
                    if subject.energy <= 0.0:
                        logging.info("player {} died from {}'s bomb".format(
                            subject.name, player.name))
                        result_signals.append(self.player_death(subject))
        return result_signals
Example #4
0
	def execute_fires(self, players):
		result_signals = []
		for player in players:
			# unpack required information
			(angle, distance, radius, charge) = player.fire_action
			# TODO: log fire action for player

			# calculate the epicenter of the blast
			epicenter = util.move_wrapped(player.location, angle, distance, (self.width, self.height))

			# subtract energy cost
			cost = game.fire_cost(distance, radius, charge)
			logging.info('player {} at {} fired at {} (radius: {}, charge: {})'.format(
				player.name,
				player.location,
				epicenter,
				radius,
				charge
			))

			prev_energy = player.energy
			player.energy -= cost

			# emit player fire event
			self.emit_event(
				type = 'player_fire',
				player = player.name,
				location = player.location,
				angle = angle,
				distance = distance,
				radius = radius,
				charge = charge,
				cost = cost,
				epicenter = epicenter,
				energy = (prev_energy, player.energy)
			)

			if player.energy <= 0.0:
				# signal player is dead
				result_signals.append(self.player_death(player))
				self.emit_event(
					type = 'player_suicide',
					action = 'fire',
					cost = cost,
					energy = (prev_energy, player.energy)
				)
				# XXX: possibly more to do with hitting one's self
				logging.info('player {} died from exhaustion (fire)'.format(player.name))

			# calculate the bounding box for the blast
			bounds = (
				epicenter[0] - radius, epicenter[1] - radius,
				epicenter[0] + radius, epicenter[1] + radius
			)
			# collect all players in the bounding box for the blast
			subjects = set()
			for region in util.generate_wrapped_bounds((0, 0, self.width, self.height), bounds):
				subjects = subjects.union(self.find_players(region))

			# create a wrapped radius to check distance against
			radius = util.WrappedRadius(epicenter, radius, (self.width, self.height))
			# check if subject in blast radius (bounding box possibly selects too many players)
			for subject in subjects:
				# calculate distance to epicenter for all subjects, signal hit if ... hit
				if subject.location in radius:
					# subtract energy equal to charge from subject that was hit
					prev_energy = subject.energy
					subject.energy -= charge
					# emit player hit event
					self.emit_event(
						type = 'player_hit',
						player = subject.name,
						location = subject.location,
						epicenter = epicenter,
						radius = radius,
						charge = charge,
						energy = (prev_energy, subject.energy),
						fatal = subject.energy <= 0.0,
						attacker = player.name,
						attacker_location = player.location,
						attacker_energy = player.energy
					)
					# signal the subject it was hit
					result_signals.append((player.signal_hit, player.name,
							util.angle(radius.distance(subject.location)[1], epicenter),
							charge
					))
					logging.info('player {} hit {} for {} (new energy: {})'.format(player.name, subject.name, charge, subject.energy))
					# check to see if the subject died from this hit
					if subject.energy <= 0.0:
						logging.info("player {} died from {}'s bomb".format(subject.name, player.name))
						result_signals.append(self.player_death(subject))
		return result_signals