Ejemplo n.º 1
0
def melee_combat(life, targets):
	_target = get_closest_target(life, targets)
	
	if not _target:
		logging.error('No target for melee combat.')
		return False
	
	if sight.can_see_position(life, _target['last_seen_at'], block_check=True, strict=True):
		_can_see = sight.can_see_position(life, _target['life']['pos'], get_path=True)
		
		if _can_see:
			if len(_can_see)>1:
				movement.find_target(life, _target['life']['id'], distance=1, follow=True)
			else:
				melee.fight(life, _target['life']['id'])
		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:
		return False
Ejemplo n.º 2
0
def melee_combat(life, targets):
	_target = get_closest_target(life, targets)
	
	if not _target:
		logging.error('No target for melee combat.')
		return False
	
	if sight.can_see_position(life, _target['last_seen_at'], block_check=True, strict=True):
		_can_see = sight.can_see_position(life, _target['life']['pos'], get_path=True)
		
		if _can_see:
			if len(_can_see)>1:
				movement.find_target(life, _target['life']['id'], distance=1, follow=True)
			else:
				melee.fight(life, _target['life']['id'])
		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:
		return False
Ejemplo n.º 3
0
def is_confident(life):
	_friendly_confidence = 0
	_threat_confidence = 0
	
	for target_id in judgement.get_trusted(life, visible=False):
		_knows = brain.knows_alife_by_id(life, target_id)
		
		if _knows['dead'] or _knows['asleep']:
			continue
		
		_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
		
		if _knows['last_seen_time']:
			_friendly_confidence += _recent_mod
		else:
			_friendly_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
	
	for target_id in judgement.get_threats(life, ignore_escaped=True):
		_knows = brain.knows_alife_by_id(life, target_id)
		
		if _knows['dead'] or _knows['asleep']:
			continue
		
		_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
		
		if _knows['last_seen_time']:
			_threat_confidence += 2*_recent_mod
		else:
			_threat_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
	
	return _friendly_confidence > _threat_confidence
Ejemplo n.º 4
0
def is_confident(life):
    if 'player' in life:
        return False

    _friendly_confidence = judgement.get_ranged_combat_rating_of_target(
        life, life['id'])
    _threat_confidence = 0

    for target_id in judgement.get_trusted(life, visible=False):
        _knows = brain.knows_alife_by_id(life, target_id)

        if _knows['dead'] or _knows['asleep']:
            continue

        if _knows['last_seen_time'] > 30:
            if brain.get_alife_flag(life, target_id, 'threat_score'):
                _recent_mod = 1 - (
                    numbers.clip(_knows['last_seen_time'], 0, 300) / 300.0)
                _score = brain.get_alife_flag(life, target_id, 'threat_score')
                _friendly_confidence += _score * _recent_mod
            else:
                _friendly_confidence += 1
        else:
            _score = judgement.get_ranged_combat_rating_of_target(
                life, target_id)

            brain.flag_alife(life, target_id, 'threat_score', value=_score)

            _friendly_confidence += _score

    for target_id in judgement.get_threats(life, ignore_escaped=False):
        _knows = brain.knows_alife_by_id(life, target_id)

        if _knows['dead'] or _knows['asleep']:
            continue

        if _knows['last_seen_time']:
            if brain.get_alife_flag(life, target_id, 'threat_score'):
                if _knows['last_seen_time'] > 50:
                    _recent_mod = 1 - (
                        numbers.clip(_knows['last_seen_time'], 0, 600) / 600.0)
                else:
                    _recent_mod = 1

                _score = brain.get_alife_flag(life, target_id, 'threat_score')
                _threat_confidence += _score * _recent_mod
            else:
                _threat_confidence += 1
        else:
            _score = judgement.get_ranged_combat_rating_of_target(
                life, target_id, inventory_check=False)

            brain.flag_alife(life, target_id, 'threat_score', value=_score)

            _threat_confidence += _score

    return _friendly_confidence - _threat_confidence >= -2
Ejemplo n.º 5
0
def announce(life,
             _group_id,
             gist,
             message='',
             order=False,
             consider_motive=False,
             filter_if=None,
             **kwargs):
    _group = get_group(life, _group_id)

    if consider_motive:
        if _group['claimed_motive'] == 'wealth':
            _announce_to = []

            for life_id in LIFE.keys():
                if life_id == life['id']:
                    continue

                if stats.is_same_species(life, life_id):
                    _announce_to.append(life_id)
        elif _group['claimed_motive'] in ['crime', 'military']:
            _announce_to = judgement.get_trusted(life, visible=False)

            for life_id in _announce_to[:]:
                if not stats.is_same_species(life, life_id):
                    _announce_to.remove(life_id)

        elif _group['claimed_motive'] == 'survival':
            _announce_to = []

            for life_id in LIFE.keys():
                if life_id == life['id']:
                    continue

                if stats.is_same_species(life, life_id):
                    _announce_to.append(life_id)

    else:
        _announce_to = _group['members'][:]

        if life['id'] in _announce_to:
            _announce_to.remove(life['id'])
    #TODO: Could have an option here to form an emergency "combat" group

    for life_id in _announce_to:
        if filter_if and filter_if(life_id):
            continue

        #_sent = speech.has_sent(life, life_id, gist)
        #if _sent and WORLD_INFO['ticks']-_sent<15:
        #	continue

        if order:
            memory.create_order(life, life_id, gist, message, **kwargs)
        else:
            memory.create_question(life, life_id, gist, **kwargs)
Ejemplo n.º 6
0
def is_confident(life):
	if 'player' in life:
		return False
	
	_friendly_confidence = judgement.get_ranged_combat_rating_of_target(life, life['id'])
	_threat_confidence = 0
	
	for target_id in judgement.get_trusted(life, visible=False):
		_knows = brain.knows_alife_by_id(life, target_id)
		
		if _knows['dead'] or _knows['asleep']:
			continue
		
		if _knows['last_seen_time']>30:
			if brain.get_alife_flag(life, target_id, 'threat_score'):
				_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 300)/300.0)
				_score = brain.get_alife_flag(life, target_id, 'threat_score')
				_friendly_confidence += _score*_recent_mod
			else:
				_friendly_confidence += 1
		else:
			_score = judgement.get_ranged_combat_rating_of_target(life, target_id)
			
			brain.flag_alife(life, target_id, 'threat_score', value=_score)
			
			_friendly_confidence += _score
	
	for target_id in judgement.get_threats(life, ignore_escaped=False):
		_knows = brain.knows_alife_by_id(life, target_id)
		
		if _knows['dead'] or _knows['asleep']:
			continue
		
		if _knows['last_seen_time']:
			if brain.get_alife_flag(life, target_id, 'threat_score'):
				if _knows['last_seen_time']>50:
					_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 600)/600.0)
				else:
					_recent_mod = 1
				
				_score = brain.get_alife_flag(life, target_id, 'threat_score')
				_threat_confidence += _score*_recent_mod
			else:
				_threat_confidence += 1
		else:
			_score = judgement.get_ranged_combat_rating_of_target(life, target_id, inventory_check=False)
			
			brain.flag_alife(life, target_id, 'threat_score', value=_score)
			
			_threat_confidence += _score
	
	return _friendly_confidence-_threat_confidence>=-2
Ejemplo n.º 7
0
def announce(life, _group_id, gist, message='', order=False, consider_motive=False, filter_if=None, **kwargs):
	_group = get_group(life, _group_id)
	
	if consider_motive:
		if _group['claimed_motive'] == 'wealth':
			_announce_to = []
			
			for life_id in LIFE.keys():
				if life_id == life['id']:
					continue
				
				if stats.is_same_species(life, life_id):
					_announce_to.append(life_id)
		elif _group['claimed_motive'] in ['crime', 'military']:
			_announce_to = judgement.get_trusted(life, visible=False)

			for life_id in _announce_to[:]:
				if not stats.is_same_species(life, life_id):
					_announce_to.remove(life_id)
			
		elif _group['claimed_motive'] == 'survival':
			_announce_to = []
			
			for life_id in LIFE.keys():
				if life_id == life['id']:
					continue
				
				if stats.is_same_species(life, life_id):
					_announce_to.append(life_id)
			
	else:
		_announce_to = _group['members'][:]
		
		if life['id'] in _announce_to:
			_announce_to.remove(life['id'])
	#TODO: Could have an option here to form an emergency "combat" group
	
	for life_id in _announce_to:
		if filter_if and filter_if(life_id):
			continue
		
		#_sent = speech.has_sent(life, life_id, gist)
		#if _sent and WORLD_INFO['ticks']-_sent<15:
		#	continue
		
		if order:
			memory.create_order(life, life_id, gist, message, **kwargs)
		else:
			memory.create_question(life, life_id, gist, **kwargs)
Ejemplo n.º 8
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.º 9
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.º 10
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.º 11
0
def has_attacked_trusted(life, life_id):
    return _has_attacked(life, life_id, judgement.get_trusted(life))
Ejemplo n.º 12
0
def has_attacked_trusted(life, life_id):
	return _has_attacked(life, life_id, judgement.get_trusted(life))