Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def announce(life, gist, public=False, trusted=False, group=None, filter_if=None, **kwargs):
	"""Sends `gist` to any known ALife. If `public`, then send to everyone."""
	if public:
		_announce_to = [LIFE[i] for i in LIFE if not i == life['id']]
	elif trusted:
		_announce_to = [life['know'][i]['life'] for i in life['know'] if life['know'][i]['alignment'] == 'trust']
	elif group:
		_announce_to = [LIFE[i] for i in groups.get_group(life, group)['members'] if not i == life['id']]
	else:
		_announce_to = [life['know'][i]['life'] for i in life['know'] if not judgement.is_target_dangerous(life, i)]
	
	for target in _announce_to:
		if not stats.can_talk_to(life, target['id']):
			continue
		
		if filter_if and filter_if(life):
			return False
		
		_radio = False
		if not sight.can_see_position(life, target['pos']):
			if lfe.get_all_inventory_items(life, matches=[{'name': 'radio'}]):
				_radio = True
			else:
				continue
	
		memory.create_question(life, target['id'], gist, **kwargs)
	
	return True
Ejemplo n.º 5
0
def inform_of_group(life, life_id):
    memory.create_question(life,
                           life_id,
                           'group_exists',
                           group_id=life['group'],
                           group_list=groups.get_group(
                               life, life['group'])['members'])
Ejemplo n.º 6
0
def manage_territory(life, group_id):
	_shelter = get_shelter(life, group_id)
	
	if not _shelter:
		return False
	
	_shelter_chunk = chunks.get_nearest_chunk_in_list(life['pos'], references.get_reference(_shelter))
	
	for known_group_id in life['known_groups']:
		if group_id == known_group_id:
			continue
		
		_opposing_shelter = get_possible_group_location(life, known_group_id)
		if not _opposing_shelter:
			continue
		
		_distance = chunks.get_distance_to_nearest_chunk_in_list(WORLD_INFO['chunk_map'][_shelter_chunk]['pos'], references.get_reference(_opposing_shelter))
		
		if _distance<=30:
			print '2 CLOSE 2 HANDLE'
	
	for seen_life_id in life['seen']:
		_target = brain.knows_alife_by_id(life, seen_life_id)
		
		if not _target or _target['alignment'] == 'trust' or not _target['last_seen_at'] or _target['dead']:
			continue
		
		if chunks.get_distance_to_nearest_chunk_in_list(_target['last_seen_at'], references.get_reference(_shelter))>30:
			continue
		
		print 'L@@K'* 20
		print life['name'], LIFE[seen_life_id]['name'], _target['alignment']
		
		memory.create_question(life, seen_life_id, 'territory_violation', ignore_if_said_in_last=-1)
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 manage_strategy(life, group_id):
	_last_strat = get_flag(life, group_id, 'strategy')
	
	if _last_strat and _last_strat['ready'] and WORLD_INFO['ticks']-_last_strat['updated']<100:
		return False
	
	if _last_strat:
		_strat = _last_strat
	else:
		_strat = {'ready': False, 'gear_track': {}}
		
	flag(life, group_id, 'strategy', _strat)
	
	_gear_track = _strat['gear_track']
	_group = get_group(life, group_id)
	_members_combat_ready = 0
	
	#Get inventory...
	for member_id in _group['members']:
		#TODO: Handle this
		if member_id == life['id']:
			continue
		
		if not member_id in _gear_track:
			_gear_track[member_id] = {'has_weapon': len(lfe.get_all_equipped_items(LIFE[member_id], matches=[{'type': 'gun'}]))>0,
			                          'has_ammo': False,
			                          'asked': [],
			                          'mia': False}
		
		_track = _gear_track[member_id]

		if brain.knows_alife_by_id(life, member_id)['last_seen_time'] <= 100:
			if 'mia_check' in _track['asked']:
				_track['asked'].remove('mia_check')
			
			_track['mia'] = False
		else:
			_track['mia'] = True
		
		if _track['mia']:
			if not 'mia_check' in _track['asked']:
				_track['asked'].append('mia_check')
				_size = get_group_size(life, group_id)
				
				memory.create_question(life, member_id, 'order_status_report_%s' % _size)
		elif _track['has_weapon']:
			if _track['has_ammo']:
				_members_combat_ready.append(member_id)
		elif not 'order_equip_weapon' in _track['asked']:
			_track['asked'].append('order_equip_weapon')
			
			memory.create_question(life, member_id, 'order_equip_weapon')
Ejemplo n.º 9
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.º 10
0
def inform_of_group_members(life, life_id, group_id):
    if 'player' in life:
        _dialog_id = lfe.has_dialog_with(life, life_id)
        _menu_items = []

        for target_id in life['know']:
            if target_id == life['id'] or target_id == life_id:
                continue

            if groups.is_member(life, group_id, target_id):
                _colors = (tcod.green, tcod.white)
                _values = ['Member', 'Not Member']
            else:
                _colors = (tcod.red, tcod.white)
                _values = ['Not Member', 'Member']

            _menu_items.append(
                menus.create_item('list',
                                  ' '.join(LIFE[target_id]['name']),
                                  _values,
                                  group=group_id,
                                  target_id=target_id,
                                  members=_menu_items,
                                  color=_colors,
                                  dialog_id=_dialog_id))

        if not _menu_items:
            return False

        _menu = menus.create_menu(menu=_menu_items,
                                  title='Inform of Group Members',
                                  format_str='$k: $v',
                                  on_select=confirm_inform_of_group_members,
                                  close_on_select=True)
        menus.activate_menu(_menu)
    else:
        for target_id in groups.get_group(life, group_id)['members']:
            if life['id'] == target_id:
                continue

            memory.create_question(life,
                                   target_id,
                                   'group_list',
                                   group_id=group_id,
                                   group_list=groups.get_group(
                                       life, group_id)['members'])
Ejemplo n.º 11
0
def update_group_members(life, target_id, group_id, group_list):
	_known_members = groups.get_group(life, group_id)['members'][:]
	_group_list = group_list[:]
	_send = []
	
	for member in _group_list:
		if not member in _known_members:
			_known_members.append(member)
			groups.add_member(life, group_id, member)
	
	for member in _known_members:
		if not member in group_list:
			_send.append(member)
	
	if _send:
		memory.create_question(life, target_id, 'group_list',
		                       group_id=life['group'],
		                       group_list=groups.get_group(life, life['group'])['members'])
Ejemplo n.º 12
0
def announce(life,
             gist,
             public=False,
             trusted=False,
             group=None,
             filter_if=None,
             **kwargs):
    """Sends `gist` to any known ALife. If `public`, then send to everyone."""
    if public:
        _announce_to = [LIFE[i] for i in LIFE if not i == life['id']]
    elif trusted:
        _announce_to = [
            life['know'][i]['life'] for i in life['know']
            if life['know'][i]['alignment'] == 'trust'
        ]
    elif group:
        _announce_to = [
            LIFE[i] for i in groups.get_group(life, group)['members']
            if not i == life['id']
        ]
    else:
        _announce_to = [
            life['know'][i]['life'] for i in life['know']
            if not judgement.is_target_dangerous(life, i)
        ]

    for target in _announce_to:
        if not stats.can_talk_to(life, target['id']):
            continue

        if filter_if and filter_if(target['id']):
            continue

        _radio = False
        if not sight.can_see_position(life, target['pos']):
            if lfe.get_all_inventory_items(life, matches=[{'name': 'radio'}]):
                _radio = True
            else:
                continue

        memory.create_question(life, target['id'], gist, **kwargs)

    return True
Ejemplo n.º 13
0
def inform_of_group_members(life, life_id, group_id):
	if 'player' in life:
		_dialog_id = lfe.has_dialog_with(life, life_id)
		_menu_items = []
		
		for target_id in life['know']:
			if target_id == life['id'] or target_id == life_id:
				continue
			
			if groups.is_member(life, group_id, target_id):
				_colors = (tcod.green, tcod.white)
				_values = ['Member', 'Not Member']
			else:
				_colors = (tcod.red, tcod.white)
				_values = ['Not Member', 'Member']
			
			_menu_items.append(menus.create_item('list',
			                                     ' '.join(LIFE[target_id]['name']),
			                                     _values,
			                                     group=group_id,
			                                     target_id=target_id,
			                                     members=_menu_items,
			                                     color=_colors,
			                                     dialog_id=_dialog_id))
		
		if not _menu_items:
			return False
		
		_menu = menus.create_menu(menu=_menu_items,
		                          title='Inform of Group Members',
		                          format_str='$k: $v',
		                          on_select=confirm_inform_of_group_members,
		                          close_on_select=True)
		menus.activate_menu(_menu)
	else:
		for target_id in groups.get_group(life, group_id)['members']:
			if life['id'] == target_id:
				continue
			
			memory.create_question(life, target_id, 'group_list',
				                   group_id=group_id,
				                   group_list=groups.get_group(life, group_id)['members'])
Ejemplo n.º 14
0
def update_group_members(life, target_id, group_id, group_list):
    _known_members = groups.get_group(life, group_id)['members'][:]
    _group_list = group_list[:]
    _send = []

    for member in _group_list:
        if not member in _known_members:
            _known_members.append(member)
            groups.add_member(life, group_id, member)

    for member in _known_members:
        if not member in group_list:
            _send.append(member)

    if _send:
        memory.create_question(life,
                               target_id,
                               'group_list',
                               group_id=life['group'],
                               group_list=groups.get_group(
                                   life, life['group'])['members'])
Ejemplo n.º 15
0
def inform_of_group(life, life_id):
	memory.create_question(life, life_id, 'group_exists',
	                       group_id=life['group'],
	                       group_list=groups.get_group(life, life['group'])['members'])
Ejemplo n.º 16
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']])
Ejemplo n.º 17
0
def manage_strategy(life, group_id):
    _last_strat = get_flag(life, group_id, 'strategy')

    if _last_strat and _last_strat[
            'ready'] and WORLD_INFO['ticks'] - _last_strat['updated'] < 100:
        return False

    if _last_strat:
        _strat = _last_strat
    else:
        _strat = {'ready': False, 'gear_track': {}}

    flag(life, group_id, 'strategy', _strat)

    _gear_track = _strat['gear_track']
    _group = get_group(life, group_id)
    _members_combat_ready = 0

    #Get inventory...
    for member_id in _group['members']:
        #TODO: Handle this
        if member_id == life['id']:
            continue

        if not member_id in _gear_track:
            _gear_track[member_id] = {
                'has_weapon':
                len(
                    lfe.get_all_equipped_items(LIFE[member_id],
                                               matches=[{
                                                   'type': 'gun'
                                               }])) > 0,
                'has_ammo':
                False,
                'asked': [],
                'mia':
                False
            }

        _track = _gear_track[member_id]

        if brain.knows_alife_by_id(life, member_id)['last_seen_time'] <= 100:
            if 'mia_check' in _track['asked']:
                _track['asked'].remove('mia_check')

            _track['mia'] = False
        else:
            _track['mia'] = True

        if _track['mia']:
            if not 'mia_check' in _track['asked']:
                _track['asked'].append('mia_check')
                _size = get_group_size(life, group_id)

                memory.create_question(life, member_id,
                                       'order_status_report_%s' % _size)
        elif _track['has_weapon']:
            if _track['has_ammo']:
                _members_combat_ready.append(member_id)
        elif not 'order_equip_weapon' in _track['asked']:
            _track['asked'].append('order_equip_weapon')

            memory.create_question(life, member_id, 'order_equip_weapon')