Example #1
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
Example #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
Example #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
Example #4
0
def react_to_tension(life, life_id):
    if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']:
        return False

    if life['group'] and not groups.is_leader(
            life, life['group'], life['id']) and groups.get_leader(
                life, life['group']):
        if sight.can_see_target(life, groups.get_leader(
                life, life['group'])) and sight.can_see_target(
                    LIFE[life_id], groups.get_leader(life, life['group'])):
            return False

    _disarm = brain.get_alife_flag(life, life_id, 'disarm')

    if _disarm:
        #For now...
        if not sight.can_see_position(life, LIFE[life_id]['pos']):
            groups.announce(life,
                            life['group'],
                            'attacked_by_hostile',
                            filter_if=lambda life_id: brain.knows_alife_by_id(
                                life, life_id)['last_seen_time'] <= 30,
                            target_id=life_id)

            return False

        for item_uid in lfe.get_all_visible_items(LIFE[life_id]):
            if ITEMS[item_uid]['type'] == 'gun':
                break
        else:
            brain.unflag_alife(life, life_id, 'disarm')
            speech.start_dialog(life, life_id, 'clear_drop_weapon')

            return False

        _time_elapsed = WORLD_INFO['ticks'] - _disarm

        if _time_elapsed > 135 and not speech.has_sent(life, life_id,
                                                       'threaten'):
            speech.start_dialog(life, life_id, 'threaten')
            speech.send(life, life_id, 'threaten')
        elif _time_elapsed > 185:
            speech.start_dialog(life, life_id, 'establish_hostile')
    elif not speech.has_sent(life, life_id, 'confront'):
        speech.start_dialog(life, life_id, 'confront')
        speech.send(life, life_id, 'confront')
Example #5
0
def react_to_tension(life, life_id):
	if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']:
		return False
	
	if life['group'] and not groups.is_leader(life, life['group'], life['id']) and groups.get_leader(life, life['group']):
		if sight.can_see_target(life, groups.get_leader(life, life['group'])) and sight.can_see_target(LIFE[life_id], groups.get_leader(life, life['group'])):
			return False
	
	_disarm = brain.get_alife_flag(life, life_id, 'disarm')
	
	if _disarm:
		#For now...
		if not sight.can_see_position(life, LIFE[life_id]['pos']):
			groups.announce(life,
			                life['group'],
			                'attacked_by_hostile',
			                filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30,
			                target_id=life_id)
			
			return False
		
		for item_uid in lfe.get_all_visible_items(LIFE[life_id]):
			if ITEMS[item_uid]['type'] == 'gun':
				break
		else:
			brain.unflag_alife(life, life_id, 'disarm')
			speech.start_dialog(life, life_id, 'clear_drop_weapon')
			
			return False
		
		_time_elapsed = WORLD_INFO['ticks']-_disarm
		
		if _time_elapsed>135 and not speech.has_sent(life, life_id, 'threaten'):
			speech.start_dialog(life, life_id, 'threaten')
			speech.send(life, life_id, 'threaten')
		elif _time_elapsed>185:
			speech.start_dialog(life, life_id, 'establish_hostile')
	elif not speech.has_sent(life, life_id, 'confront'):
		speech.start_dialog(life, life_id, 'confront')
		speech.send(life, life_id, 'confront')
Example #6
0
def add_member(life, group_id, life_id):
    if is_member(life, group_id, life_id):
        raise Exception(
            '%s failed to add new member: %s is already a member of group: %s'
            % (' '.join(life['name']), ' '.join(
                LIFE[life_id]['name']), group_id))

    if not life['id'] == life_id:
        _target = brain.knows_alife_by_id(life, life_id)

        if _target:
            if _target['group'] == group_id:
                pass
            elif _target and _target['group']:
                lfe.memory(LIFE[life_id],
                           'left group for group',
                           left_group=_target['group'],
                           group=group_id)
                remove_member(life, _target['group'], life_id)

            _target['group'] = group_id
        else:
            _target = brain.meet_alife(life, LIFE[life_id])

        stats.establish_trust(life, life_id)
    elif life['id'] == life_id and life[
            'group'] and not life['group'] == group_id:
        remove_member(life, life['group'], life_id)

    _group = get_group(life, group_id)
    for member in _group['members']:
        brain.meet_alife(LIFE[member], LIFE[life_id])

    if _group['shelter']:
        LIFE[life_id]['shelter'] = _group['shelter']
        lfe.memory(LIFE[life_id],
                   'shelter founder',
                   shelter=_group['shelter'],
                   founder=_group['leader'])

    _group['members'].append(life_id)

    if _group['leader'] and 'player' in LIFE[_group['leader']]:
        _text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name'])
        gfx.message(_text, style='good')

        if sight.can_see_target(LIFE[_group['leader']], life_id):
            logic.show_event(_text, life=LIFE[life_id], delay=1)

    logging.debug(
        '%s added %s to group \'%s\'' %
        (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
Example #7
0
def judge_reference(life, reference_id, known_penalty=False):
    # TODO: Length
    _score = 0
    _count = 0
    _closest_chunk_key = {"key": None, "distance": -1}

    for key in references.get_reference(reference_id):
        if known_penalty and key in life["known_chunks"]:
            continue

        _count += 1
        _chunk = maps.get_chunk(key)
        _chunk_center = (
            _chunk["pos"][0] + (WORLD_INFO["chunk_size"] / 2),
            _chunk["pos"][1] + (WORLD_INFO["chunk_size"] / 2),
        )
        _distance = numbers.distance(life["pos"], _chunk_center)

        if not _closest_chunk_key["key"] or _distance < _closest_chunk_key["distance"]:
            _closest_chunk_key["key"] = key
            _closest_chunk_key["distance"] = _distance

            # Judge: ALife
        for ai in _chunk["life"]:
            if ai == life["id"]:
                continue

            if not sight.can_see_target(life, ai):
                continue

            _knows = brain.knows_alife(life, LIFE[ai])
            if not _knows:
                continue

                # How long since we've been here?
                # if key in life['known_chunks']:
                # 	_last_visit = numbers.clip(abs((life['known_chunks'][key]['last_visited']-WORLD_INFO['ticks'])/FPS), 2, 99999)
                # 	_score += _last_visit
                # else:
                # 	_score += WORLD_INFO['ticks']/FPS

                # Take length into account
    _score += _count

    # Subtract distance in chunks
    _score -= _closest_chunk_key["distance"] / WORLD_INFO["chunk_size"]

    # TODO: Average time since last visit (check every key in reference)
    # TODO: For tracking last visit use world ticks

    return _score
Example #8
0
def get_trusted(life, visible=True, only_recent=False):
    _trusted = []

    for target in life["know"].values():
        if can_trust(life, target["life"]["id"]):
            if only_recent and target["last_seen_time"] >= 150:
                continue

            if visible and not sight.can_see_target(life, target["life"]["id"]):
                continue

            _trusted.append(target["life"]["id"])

    return _trusted
Example #9
0
def get_trusted(life, visible=True, only_recent=False):
	_trusted = []
	
	for target in life['know'].values():
		if can_trust(life, target['life']['id']):
			if only_recent and target['last_seen_time']>=150:
				continue
			
			if visible and not sight.can_see_target(life, target['life']['id']):
				continue
			
			_trusted.append(target['life']['id'])
	
	return _trusted
Example #10
0
def judge_reference(life, reference_id, known_penalty=False):
	#TODO: Length
	_score = 0
	_count = 0
	_closest_chunk_key = {'key': None, 'distance': -1}
	
	for key in references.get_reference(reference_id):
		if known_penalty and key in life['known_chunks']:
			continue
		
		_count += 1
		_chunk = maps.get_chunk(key)
		_chunk_center = (_chunk['pos'][0]+(WORLD_INFO['chunk_size']/2),
			_chunk['pos'][1]+(WORLD_INFO['chunk_size']/2))
		_distance = bad_numbers.distance(life['pos'], _chunk_center)
		
		if not _closest_chunk_key['key'] or _distance<_closest_chunk_key['distance']:
			_closest_chunk_key['key'] = key
			_closest_chunk_key['distance'] = _distance
		
		#Judge: ALife
		for ai in _chunk['life']:
			if ai == life['id']:
				continue
			
			if not sight.can_see_target(life, ai):
				continue
			
			_knows = brain.knows_alife(life, LIFE[ai])
			if not _knows:
				continue
		
		#How long since we've been here?
		#if key in life['known_chunks']:
		#	_last_visit = bad_numbers.clip(abs((life['known_chunks'][key]['last_visited']-WORLD_INFO['ticks'])/FPS), 2, 99999)
		#	_score += _last_visit
		#else:
		#	_score += WORLD_INFO['ticks']/FPS
		
	#Take length into account
	_score += _count
	
	#Subtract distance in chunks
	_score -= _closest_chunk_key['distance']/WORLD_INFO['chunk_size']
	
	#TODO: Average time since last visit (check every key in reference)
	#TODO: For tracking last visit use world ticks
	
	return _score
Example #11
0
def describe_target(life, life_id):
	if life['id'] == life_id:
		return 'That\'s me.'
	
	_target = brain.knows_alife_by_id(life, life_id)
	_details = []
	
	if _target['dead']:
		return 'He died.'
	
	if sight.can_see_target(life, life_id):
		_details.append('He\'s right over there!')
	else:
		if _target['last_seen_time'] >= 2000:
			_details.append('I last saw him at %s, %s, but it was a long time ago.' % (_target['last_seen_at'][0], _target['last_seen_at'][1]))
		else:
			_details.append('I last saw him at %s, %s, recently.' % (_target['last_seen_at'][0], _target['last_seen_at'][1]))
	
	return ' '.join(_details)
Example #12
0
def add_member(life, group_id, life_id):
	if not group_id in LIFE[life_id]['known_groups']:
		raise Exception('DOES NOT KNOW')
	
	if is_member(life, group_id, life_id):
		raise Exception('%s failed to add new member: %s is already a member of group: %s' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
	
	if not life['id'] == life_id:
		_target = brain.knows_alife_by_id(life, life_id)
		
		if _target:
			if _target['group'] == group_id:
				pass
			elif _target and _target['group']:
				lfe.memory(LIFE[life_id], 'left group for group', left_group=_target['group'], group=group_id)
				remove_member(life, _target['group'], life_id)
			
			_target['group'] = group_id
		else:
			brain.meet_alife(life, LIFE[life_id])
	elif life['id'] == life_id and life['group'] and not life['group'] == group_id:
		remove_member(life, life['group'], life_id)
	
	_group = get_group(life, group_id)
	for member in _group['members']:
		brain.meet_alife(LIFE[member], LIFE[life_id])
	
	if _group['shelter']:
		LIFE[life_id]['shelter'] = _group['shelter']
		lfe.memory(LIFE[life_id], 'shelter founder', shelter=_group['shelter'], founder=_group['leader'])
	
	_group['members'].append(life_id)
	
	if _group['leader'] and 'player' in LIFE[_group['leader']]:
		_text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name'])
		gfx.message(_text, style='good')
		
		if sight.can_see_target(LIFE[_group['leader']], life_id):
			logic.show_event(_text, life=LIFE[life_id], delay=1)
	
	logging.debug('%s added %s to group \'%s\'' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
Example #13
0
def describe_target(life, life_id):
    if life['id'] == life_id:
        return 'That\'s me.'

    _target = brain.knows_alife_by_id(life, life_id)
    _details = []

    if _target['dead']:
        return 'He died.'

    if sight.can_see_target(life, life_id):
        _details.append('He\'s right over there!')
    else:
        if _target['last_seen_time'] >= 2000:
            _details.append(
                'I last saw him at %s, %s, but it was a long time ago.' %
                (_target['last_seen_at'][0], _target['last_seen_at'][1]))
        else:
            _details.append(
                'I last saw him at %s, %s, recently.' %
                (_target['last_seen_at'][0], _target['last_seen_at'][1]))

    return ' '.join(_details)
Example #14
0
def can_hear(life, target_id):
    #TODO: Walls, etc
    return sight.can_see_target(life, target_id)
Example #15
0
def can_hear(life, target_id):
	#TODO: Walls, etc
	return sight.can_see_target(life, target_id)