Ejemplo n.º 1
0
def ranged_combat(life, targets):
	_target = get_closest_target(life, targets)
	
	if not _target:
		for target_id in targets:
			if brain.knows_alife_by_id(life, target_id)['escaped']:
				continue
			
			brain.knows_alife_by_id(life, target_id)['escaped'] = 1
		
		logging.error('No target for ranged combat.')
		return False
	
	if not life['path'] or not numbers.distance(lfe.path_dest(life), _target['last_seen_at']) == 0:
		movement.position_to_attack(life, _target['life']['id'])
	
	if sight.can_see_position(life, _target['last_seen_at'], block_check=True, strict=True) and not sight.view_blocked_by_life(life, _target['last_seen_at'], allow=[_target['life']['id']]):
		if sight.can_see_position(life, _target['life']['pos']):
			if not len(lfe.find_action(life, matches=[{'action': 'shoot'}])):
				for i in range(weapons.get_rounds_to_fire(weapons.get_weapon_to_fire(life))):
					lfe.add_action(life,{'action': 'shoot',
						'target': _target['last_seen_at'],
						'target_id': _target['life']['id'],
						'limb': 'chest'},
						5000,
						delay=int(round(life['recoil']-stats.get_recoil_recovery_rate(life))))
		else:
			lfe.memory(life,'lost sight of %s' % (' '.join(_target['life']['name'])), target=_target['life']['id'])
			
			_target['escaped'] = 1
			
			for send_to in judgement.get_trusted(life):
				speech.communicate(life,
			        'target_missing',
			        target=_target['life']['id'],
			        matches=[send_to])
	else:
		print life['name'], 'waiting...'
		return False
Ejemplo n.º 2
0
def ranged_combat(life, targets):
	_target = brain.knows_alife_by_id(life, get_closest_target(life, targets))
	
	#if not _target:
	#	for target_id in targets:
	#		if brain.knows_alife_by_id(life, target_id)['escaped']:
	#			continue
	#		
	#		brain.knows_alife_by_id(life, target_id)['escaped'] = 1
	#	
	#	logging.error('No target for ranged combat.')
	#	
	#	return False
	
	_engage_distance = get_engage_distance(life)
	_path_dest = lfe.path_dest(life)
	
	if not _path_dest:
		_path_dest = life['pos'][:]
	
	_target_distance = bad_numbers.distance(life['pos'], _target['last_seen_at'])
	
	#Get us near the target
	#if _target['last_seen_at']:
	movement.position_to_attack(life, _target['life']['id'], _engage_distance)
		
	if sight.can_see_position(life, _target['last_seen_at']):
		if _target_distance	<= _engage_distance:
			if sight.can_see_position(life, _target['life']['pos']):
				if not sight.view_blocked_by_life(life, _target['life']['pos'], allow=[_target['life']['id']]):
					lfe.clear_actions(life)
					
					if not len(lfe.find_action(life, matches=[{'action': 'shoot'}])) and _target['time_visible']>2:
						for i in range(weapons.get_rounds_to_fire(weapons.get_weapon_to_fire(life))):
							lfe.add_action(life, {'action': 'shoot',
							                      'target': _target['last_seen_at'],
							                      'target_id': _target['life']['id'],
							                      'limb': 'chest'},
							               300,
							               delay=int(round(life['recoil']-stats.get_recoil_recovery_rate(life))))
				else:
					_friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life))
					_friendly_zones.append(zones.get_zone_at_coords(life['pos']))
					_friendly_positions.append(life['pos'][:])
					
					if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]):
						lfe.add_action(life, {'action': 'dijkstra_move',
						                      'rolldown': True,
						                      'zones': _friendly_zones,
						                      'goals': [_target['life']['pos'][:]],
						                      'orig_goals': [_target['life']['pos'][:]],
						                      'avoid_positions': _friendly_positions,
						                      'reason': 'combat_position'},
						               100)
			else:
				lfe.memory(life,'lost sight of %s' % (' '.join(_target['life']['name'])), target=_target['life']['id'])
				
				_target['escaped'] = 1
				
				for send_to in judgement.get_trusted(life):
					speech.communicate(life,
					                   'target_missing',
					                   target=_target['life']['id'],
					                   matches=[send_to])
		#else:
			#print life['name']
			#_friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life))
			#_friendly_zones.append(zones.get_zone_at_coords(life['pos']))
			#_friendly_positions.append(life['pos'][:])
			
			#if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]):
			#	lfe.add_action(life, {'action': 'dijkstra_move',
			#		                'rolldown': True,
			#		                'zones': _friendly_zones,
			#		                'goals': [_target['life']['pos'][:]],
			#		                'orig_goals': [_target['life']['pos'][:]],
			#		                'avoid_positions': _friendly_positions,
			#		                'reason': 'combat_position'},
			#		         100)
			#	
			#	print '2'
		
	else:
		return False
Ejemplo n.º 3
0
def ranged_combat(life, targets):
    _target = brain.knows_alife_by_id(life, get_closest_target(life, targets))

    #if not _target:
    #	for target_id in targets:
    #		if brain.knows_alife_by_id(life, target_id)['escaped']:
    #			continue
    #
    #		brain.knows_alife_by_id(life, target_id)['escaped'] = 1
    #
    #	logging.error('No target for ranged combat.')
    #
    #	return False

    _engage_distance = get_engage_distance(life)
    _path_dest = lfe.path_dest(life)

    if not _path_dest:
        _path_dest = life['pos'][:]

    _target_distance = bad_numbers.distance(life['pos'],
                                            _target['last_seen_at'])

    #Get us near the target
    #if _target['last_seen_at']:
    movement.position_to_attack(life, _target['life']['id'], _engage_distance)

    if sight.can_see_position(life, _target['last_seen_at']):
        if _target_distance <= _engage_distance:
            if sight.can_see_position(life, _target['life']['pos']):
                if not sight.view_blocked_by_life(
                        life,
                        _target['life']['pos'],
                        allow=[_target['life']['id']]):
                    lfe.clear_actions(life)

                    if not len(
                            lfe.find_action(
                                life, matches=[{
                                    'action': 'shoot'
                                }])) and _target['time_visible'] > 2:
                        for i in range(
                                weapons.get_rounds_to_fire(
                                    weapons.get_weapon_to_fire(life))):
                            lfe.add_action(
                                life, {
                                    'action': 'shoot',
                                    'target': _target['last_seen_at'],
                                    'target_id': _target['life']['id'],
                                    'limb': 'chest'
                                },
                                300,
                                delay=int(
                                    round(
                                        life['recoil'] -
                                        stats.get_recoil_recovery_rate(life))))
                else:
                    _friendly_positions, _friendly_zones = get_target_positions_and_zones(
                        life, judgement.get_trusted(life))
                    _friendly_zones.append(
                        zones.get_zone_at_coords(life['pos']))
                    _friendly_positions.append(life['pos'][:])

                    if not lfe.find_action(
                            life, [{
                                'action': 'dijkstra_move',
                                'orig_goals': [_target['life']['pos'][:]],
                                'avoid_positions': _friendly_positions
                            }]):
                        lfe.add_action(
                            life, {
                                'action': 'dijkstra_move',
                                'rolldown': True,
                                'zones': _friendly_zones,
                                'goals': [_target['life']['pos'][:]],
                                'orig_goals': [_target['life']['pos'][:]],
                                'avoid_positions': _friendly_positions,
                                'reason': 'combat_position'
                            }, 100)
            else:
                lfe.memory(life,
                           'lost sight of %s' %
                           (' '.join(_target['life']['name'])),
                           target=_target['life']['id'])

                _target['escaped'] = 1

                for send_to in judgement.get_trusted(life):
                    speech.communicate(life,
                                       'target_missing',
                                       target=_target['life']['id'],
                                       matches=[send_to])
        #else:
        #print life['name']
        #_friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life))
        #_friendly_zones.append(zones.get_zone_at_coords(life['pos']))
        #_friendly_positions.append(life['pos'][:])

        #if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]):
        #	lfe.add_action(life, {'action': 'dijkstra_move',
        #		                'rolldown': True,
        #		                'zones': _friendly_zones,
        #		                'goals': [_target['life']['pos'][:]],
        #		                'orig_goals': [_target['life']['pos'][:]],
        #		                'avoid_positions': _friendly_positions,
        #		                'reason': 'combat_position'},
        #		         100)
        #
        #	print '2'

    else:
        return False