Esempio n. 1
0
    def execute(self, command, env=None):
	actions = []

        unit = command.arguments['unit']
        weapon = command.arguments['weapon']
        target = command.arguments['target']

        # setup announce-direct-fire
        announce_moment = get_moment(command.time.turn, command.time.impulse, 'announce-direct-fire')
        announce_arguments = {'unit' : unit,
                              'weapon' : weapon,
                              'target' : target }
        announce_cmd = Command(command.owner, announce_direct_fire, announce_moment, announce_arguments)
        announce_cmd.insert_into_queue(command.queue, env)
	actions.append(command.create_action('queue-command', unit, "{0} queued 'Annouce Direct Fire' action".format(unit.id), {'weapon': weapon, 'target': target}, True))

        # setup resolve-weapon
        resolve_template = weapon.use_as('direct_fire').get_resolution_template()
        resolve_moment = get_moment(command.time.turn, command.time.impulse, resolve_template.step)
        resolve_arguments = {'unit' : unit,
                             'weapon' : weapon,
                             'target' : target }
        resolve_cmd = Command(command.owner, resolve_template, resolve_moment, resolve_arguments)
        resolve_cmd.insert_into_queue(command.queue, env)
	actions.append(command.create_action('queue-command', unit, "{0} queued 'Resolve Direct Fire' action".format(unit.id), {'weapon': weapon, 'target': target}, True)) 
	return actions
Esempio n. 2
0
 def create_move_commands(self, unit, turn, from_impulse=0):
     commands = []
     for i in range(from_impulse, IMPULSES_PER_TURN):
         if self.has_move(i):
             moment = get_moment(turn, i, 'move')
             commands.append(Command(self, move, moment, {'unit' : unit}))
     return commands
Esempio n. 3
0
    def execute(self, command, env=None):
        unit = command.arguments['unit']
        delay = command.time + Duration(0, 2)
        moment = get_moment(delay.turn, delay.impulse, 'emergency-deceleration')
        cmd = Command(command, emergency_deceleration, moment, {'unit' : System})
	cmd.insert_into_queue(command.queue, env)

        actions = [command.create_action('emergency-deceleration', unit, '{0} announces emergency deceleration'.format(unit.id))]
	return actions
Esempio n. 4
0
    def execute(self, command, env=None):
        unit = command.arguments['unit']
        speed_plot = command.arguments['speed-plot']
	unit.properties['speed-plot'] = speed_plot
	actions = [command.create_action('property-change', unit, '{0} changes speed plot'.format(unit.id), {'speed-plot': speed_plot}, True)]
        actions.extend(super(ShuttleDetermineInitialSpeed, self).execute(command, env))
	registry = import_object(settings.REGISTRY)
	move = registry.get('move')
	for impulse in speed_plot:
	    time = get_moment(command.time.turn, impulse, move.step)
	    cmd = Command(command.owner, move, time, {'unit': unit})
	    cmd.insert_into_queue(command.queue)
	    actions.append(command.create_action('queue-command', unit, "{0} queued 'Move' command at {1}".format(unit.id, time), {'command': cmd}, True))
	return actions
Esempio n. 5
0
    def execute(self, command, env=None):
        # this assumes that all the targeting is legit
        unit = command.arguments['unit']
        weapon = command.arguments['weapon']
        target = command.arguments['target']
        choice = env.choice
       
        source_position = unit.get_state('position')
        target_position = target.get_state('position')
        distance = distance(source_position, target_position)

	# TODO: figure out EW, lock-on, sensors, etc.
        moment = get_moment(command.time.turn, command.time.impulse, 'allocate-damage')
        def predicate(c):
            return c.time == moment and c.arguments['target'] == target and c.arguments['source'] == unit
        allocate_cmds = command.queue.find(predicate)
        total_damage = ResourcePool()
        for cmd in allocate_cmds:
            total_damage += cmd.arguments['damage']
        command.queue.remove(predicate)
 
        damage = weapon.use_as('direct-fire').get_damage(distance, choice)
	total_damage += damage
        weapon.use_as('frequency-restriction').record_use(command.time)
        #weapon.use_as('energy-consumer').consume()

        # setup allocate damage command
        arguments = {'target' : target, 
                     'source' : unit, 
                     'damage' : total_damage}
        cmd = Command(command.owner, AllocateDamage(), moment, arguments)
        cmd.insert_into_queue(command.queue, env)

	actions = [command.create_action('command_queued', unit, '{0} causes {1} points of damage to {2}'.format(unit.id, damage, target.id), {'target': target, 'damage': damage})]

	return actions