Beispiel #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
Beispiel #2
0
def find_target(life, target, distance=5, follow=False, call=True):
    _target = brain.knows_alife_by_id(life, target)
    _dist = bad_numbers.distance(life['pos'], _target['last_seen_at'])

    _can_see = sight.can_see_target(life, target)
    if _can_see and _dist <= distance:
        if follow:
            return True

        lfe.stop(life)

        return True

    if _target['escaped'] == 1:
        search_for_target(life, target)
        return False

    if not _can_see and sight.can_see_position(
            life, _target['last_seen_at']) and _dist < distance:
        if call:
            if not _target['escaped']:
                memory.create_question(life, target, 'GET_LOCATION')

            speech.communicate(life, 'call', matches=[target])

        _target['escaped'] = 1

        return False

    if not lfe.path_dest(life) == tuple(_target['last_seen_at'][:2]):
        lfe.walk_to(life, _target['last_seen_at'])

    return False
Beispiel #3
0
def find_target(life, target, distance=5, follow=False, call=True):
    _target = brain.knows_alife_by_id(life, target)
    _dist = numbers.distance(life["pos"], _target["last_seen_at"])

    _can_see = sight.can_see_target(life, target)
    if _can_see and _dist <= distance:
        if follow:
            return True

        lfe.stop(life)

        return True

    if _target["escaped"] == 1:
        search_for_target(life, target)
        return False

    if not _can_see and sight.can_see_position(life, _target["last_seen_at"]) and _dist < distance:
        if call:
            if not _target["escaped"]:
                memory.create_question(life, target, "GET_LOCATION")

            speech.communicate(life, "call", matches=[target])

        _target["escaped"] = 1

        return False

    if not lfe.path_dest(life) == tuple(_target["last_seen_at"][:2]):
        lfe.walk_to(life, _target["last_seen_at"])

    return False
Beispiel #4
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
Beispiel #5
0
def find_target(life, target, distance=5, follow=False, call=True):
	_target = brain.knows_alife_by_id(life, target)
	_dist = numbers.distance(life['pos'], _target['last_seen_at'])
	
	_can_see = sight.can_see_target(life, target)
	if _can_see and _dist<=distance:
		if follow:
			return True
		
		lfe.stop(life)
		
		return True
	
	if _target['escaped'] == 1:
		search_for_target(life, target)
		return False
	
	if not _can_see and sight.can_see_position(life, _target['last_seen_at']) and _dist<distance:
		if call:
			if not _target['escaped']:
				memory.create_question(life, target, 'GET_LOCATION')
				
			speech.communicate(life, 'call', matches=[target])
		
		_target['escaped'] = 1
		
		return False
	
	if not lfe.path_dest(life) == tuple(_target['last_seen_at'][:2]):
		lfe.clear_actions(life)
		lfe.add_action(life,
			          {'action': 'move','to': _target['last_seen_at'][:2]},
			          200)
	
	return False
Beispiel #6
0
def distribute(life, message, filter_by=[], **kvargs):
	_group = get_group(life, life['group'])
	
	for member in _group['members']:
		if member in filter_by:
			continue
		
		speech.communicate(life, message, radio=True, matches=[member], **kvargs)
Beispiel #7
0
def _find_alife_and_say(life, target_id, say):
    _target = brain.knows_alife_by_id(life, target_id)

    if _find_alife(life, _target["life"]["id"]):
        speech.communicate(life, _say["gist"], matches=[_target["life"]["id"]], **say)
        lfe.memory(life, "told about founder", camp=_say["camp"], target=_target["life"]["id"])
        return True

    return False
Beispiel #8
0
def distribute(life, message, filter_by=[], **kvargs):
    _group = get_group(life, life['group'])

    for member in _group['members']:
        if member in filter_by:
            continue

        speech.communicate(life,
                           message,
                           radio=True,
                           matches=[member],
                           **kvargs)
Beispiel #9
0
def _find_alife_and_say(life, target_id, say):
	_target = brain.knows_alife_by_id(life, target_id)
	
	if _find_alife(life, _target['life']['id']):
		speech.communicate(life, _say['gist'], matches=[_target['life']['id']], **say)
		lfe.memory(life,
			'told about founder',
			camp=_say['camp'],
			target=_target['life']['id'])
		return True
	
	return False
Beispiel #10
0
def _find_alife_and_say(life, target_id, say):
    _target = brain.knows_alife_by_id(life, target_id)

    if _find_alife(life, _target['life']['id']):
        speech.communicate(life,
                           _say['gist'],
                           matches=[_target['life']['id']],
                           **say)
        lfe.memory(life,
                   'told about founder',
                   camp=_say['camp'],
                   target=_target['life']['id'])
        return True

    return False
Beispiel #11
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
Beispiel #12
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
Beispiel #13
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
Beispiel #14
0
def setup(life):
	#TODO: Add these two values to an array called PANIC_STATES
	#if not alife_seen:
	#	return False
	#if brain.retrieve_from_memory(life, 'tension_spike') >= 10:
	#	lfe.say(life, '@n panics!', action=True)
	
	_potential_talking_targets = []
	for ai in life['seen']:
		if not stats.can_talk_to(life, ai):
			continue
		
		#print life['name'], LIFE[ai]['name'], judgement.get_tension_with(life, ai)
		
		if stats.has_attacked_self(life, ai):
			stats.react_to_attack(life, ai)
		elif 0<judgement.get_tension_with(life, ai)<=judgement.get_max_tension_with(life, ai):
			stats.react_to_tension(life, ai)
		else:
			#if not stats.desires_first_contact_with(life, ai) and not stats.desires_conversation_with(life, ai):
			#	continue
			if not stats.desires_conversation_with(life, ai):
				continue
	
			_potential_talking_targets.append(ai)
	
	if not _potential_talking_targets:
		if life['dialogs']:
			_dialog = life['dialogs'][0]
			dialog.process(life, _dialog)
		
		if not lfe.ticker(life, 'talk', 6):
			return False
	
	if lfe.get_all_inventory_items(life, matches=[{'type': 'radio'}]):
		for ai in life['know']:
			if ai in _potential_talking_targets:
				continue
			
			if not stats.can_talk_to(life, ai):
				continue
			
			_potential_talking_targets.append(ai)
	
	#TODO: Score these
	random.shuffle(_potential_talking_targets)
	
	for target in _potential_talking_targets:
		if life['dialogs']:
			break
		
		#if stats.desires_first_contact_with(life, target):
		#	memory.create_question(life, target, 'establish_relationship', ignore_if_said_in_last=-1)
		
		if memory.get_questions_for_target(life, target):
			_question = memory.ask_target_question(life, target)
			speech.start_dialog(life, target, _question['gist'], **_question['args'])
		elif memory.get_orders_for_target(life, target):
			speech.start_dialog(life, target, 'give_order')
		elif stats.wants_group_member(life, target):
			memory.create_question(life, target, 'recruit', ignore_if_said_in_last=-1, group_id=life['group'])
	
	if life['dialogs']:
		_dialog = life['dialogs'][0]
		dialog.process(life, _dialog)	
	
	if not judgement.is_safe(life) and lfe.ticker(life, 'call_for_help', 90, fire=True):
		_combat_targets = judgement.get_ready_combat_targets(life)
		
		if _combat_targets:
			if life['camp'] and camps.is_in_camp(life, lfe.get_current_camp(life)):
				_nearest_camp = camps.get_nearest_known_camp(life)
				raids.create_raid(_nearest_camp['id'], join=life['id'])
				raids.add_raiders(_nearest_camp['id'], _combat_targets)
				
				#TODO: Remove memory call
				speech.announce(life,
					'camp_raid',
					camp=_nearest_camp,
					raiders=_combat_targets)
			
			if life['group']:
				for target in _combat_targets:
					_last_seen_at = None
					_know = brain.knows_alife_by_id(life, target)
					
					if _know:
						_last_seen_at = _know['last_seen_at']
						
					groups.distribute(life, 'under_attack', attacker=target, last_seen_at=_last_seen_at)
		
		for target in judgement.get_ready_combat_targets(life):
			_last_seen_at = None
			_know = brain.knows_alife_by_id(life, target)
			
			if _know:
				_last_seen_at = _know['last_seen_at']

			speech.announce(life, 'attacked_by_hostile', trusted=True, target_id=target, last_seen_at=_last_seen_at)

	_visible_items = [life['know_items'][item] for item in life['know_items'] if not life['know_items'][item]['last_seen_time'] and not 'parent_id' in ITEMS[life['know_items'][item]['item']]]
	for ai in [life['know'][i] for i in life['know']]:
		if judgement.is_target_dangerous(life, ai['life']['id']):
			continue
		
		#if life['state'] == 'combat':
		#	break
		
		if ai['life']['state'] in ['hiding', 'hidden']:
			break
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue

		for item in _visible_items:
			#TODO: Check
			if brain.has_shared_item_with(life, ai['life'], item['item']):
				continue

			if not item['item'] in ITEMS:
				continue

			brain.share_item_with(life, ai['life'], item['item'])
			speech.communicate(life,
				'share_item_info',
				item=item['item'],
				matches=[ai['life']['id']])
Beispiel #15
0
def setup(life):
	#TODO: Add these two values to an array called PANIC_STATES
	#if not alife_seen:
	#	return False
	#if brain.retrieve_from_memory(life, 'tension_spike') >= 10:
	#	lfe.say(life, '@n panics!', action=True)
	_needs_help = stats.is_injured(life)
	
	_potential_talking_targets = []
	for ai in life['seen']:
		if not stats.can_talk_to(life, ai):
			continue
		
		_relationship_change = stats.wants_alignment_change(life, ai)
		
		#if 'player' in LIFE[ai]:
		#	print life['name'], LIFE[ai]['name'], judgement.get_tension_with(life, ai)>judgement.get_max_tension_with(life, ai), _relationship_change
		
		if stats.has_attacked_self(life, ai):
			stats.react_to_attack(life, ai)
		elif judgement.get_tension_with(life, ai)>judgement.get_max_tension_with(life, ai):
			stats.react_to_tension(life, ai)
		elif _needs_help:
			if stats.desires_help_from(life, ai):
				stats.ask_for_help(life, ai)
		elif _relationship_change:
			speech.change_alignment(life, ai, _relationship_change)
		else:
			if not stats.desires_conversation_with(life, ai):
				continue
	
			_potential_talking_targets.append(ai)
	
	if not _potential_talking_targets:
		if life['dialogs']:
			_dialog = life['dialogs'][0]
			dialog.process(life, _dialog)
		
		if not lfe.ticker(life, 'talk', 6):
			return False
	
	if lfe.get_all_inventory_items(life, matches=[{'type': 'radio'}]):
		for ai in life['know']:
			if ai in _potential_talking_targets:
				continue
			
			if not stats.can_talk_to(life, ai):
				continue
			
			_potential_talking_targets.append(ai)
	
	#TODO: Score these
	random.shuffle(_potential_talking_targets)
	
	for target in _potential_talking_targets:
		if life['dialogs']:
			break
		
		#if stats.desires_first_contact_with(life, target):
		#	memory.create_question(life, target, 'establish_relationship', ignore_if_said_in_last=-1)
		
		if memory.get_questions_for_target(life, target) and numbers.distance(life['pos'], LIFE[target]['pos'])<=25:
			_question = memory.ask_target_question(life, target)
			speech.start_dialog(life, target, _question['gist'], **_question['args'])
		elif memory.get_orders_for_target(life, target):
			speech.start_dialog(life, target, 'give_order')
		#elif stats.wants_group_member(life, target):
		#	memory.create_question(life, target, 'recruit', ignore_if_said_in_last=-1, group_id=life['group'])
	
	if life['dialogs']:
		_dialog = life['dialogs'][0]
		dialog.process(life, _dialog)
	
	if not judgement.is_safe(life) and lfe.ticker(life, 'call_for_help', 90, fire=True):
		_combat_targets = judgement.get_ready_combat_targets(life)
		
		if _combat_targets:
			if life['camp'] and camps.is_in_camp(life, lfe.get_current_camp(life)):
				_nearest_camp = camps.get_nearest_known_camp(life)
				raids.create_raid(_nearest_camp['id'], join=life['id'])
				raids.add_raiders(_nearest_camp['id'], _combat_targets)
				
				#TODO: Remove memory call
				speech.announce(life,
					'camp_raid',
					camp=_nearest_camp,
					raiders=_combat_targets)
			
			if life['group']:
				for target in _combat_targets:
					_last_seen_at = None
					_know = brain.knows_alife_by_id(life, target)
					
					if _know:
						_last_seen_at = _know['last_seen_at']
						
					groups.distribute(life, 'under_attack', attacker=target, last_seen_at=_last_seen_at)
		
		for target in judgement.get_ready_combat_targets(life):
			_last_seen_at = None
			_know = brain.knows_alife_by_id(life, target)
			
			if _know:
				_last_seen_at = _know['last_seen_at']

			speech.announce(life,
			                'attacked_by_hostile',
			                trusted=True,
			                target_id=target,
			                filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30,
			                last_seen_at=_last_seen_at,
			                ignore_if_said_in_last=150)

	_visible_items = [life['know_items'][item] for item in life['know_items'] if not life['know_items'][item]['last_seen_time'] and not 'parent_id' in ITEMS[life['know_items'][item]['item']]]
	for ai in [life['know'][i] for i in life['know']]:
		if judgement.is_target_dangerous(life, ai['life']['id']):
			continue
		
		#if life['state'] == 'combat':
		#	break
		
		if ai['life']['state'] in ['hiding', 'hidden']:
			break
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue

		for item in _visible_items:
			#TODO: Check
			if brain.has_shared_item_with(life, ai['life'], item['item']):
				continue

			if not item['item'] in ITEMS:
				continue

			brain.share_item_with(life, ai['life'], item['item'])
			speech.communicate(life,
				'share_item_info',
				item=item['item'],
				matches=[ai['life']['id']])