Beispiel #1
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
Beispiel #2
0
def is_target_group_hostile(life, life_id):
    if not brain.knows_alife_by_id(life,
                                   life_id) or not brain.knows_alife_by_id(
                                       life, life_id)['group']:
        return False

    return factions.is_enemy(life,
                             get_group(life, LIFE[life_id]['group'])['leader'])
Beispiel #3
0
def parse_raw_judgements(life, target_id):
	lfe.execute_raw(life, 'judge', 'trust', break_on_false=False, life_id=target_id)
	
	if lfe.execute_raw(life, 'judge', 'break_trust', life_id=target_id):
		brain.knows_alife_by_id(life, target_id)['trust'] = bad_numbers.clip(brain.knows_alife_by_id(life, target_id)['trust'], -1000, -1)
		return True
	
	return False
Beispiel #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
Beispiel #5
0
def change_alignment(life, life_id, alignment):
	_knows = brain.knows_alife_by_id(life, life_id)
	
	if not _knows:
		brain.meet_alife(life, LIFE[life_id])
		_knows = brain.knows_alife_by_id(life, life_id)
	
	logging.debug('%s changed alignment of %s: %s' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), alignment))
	_knows['alignment'] = alignment
Beispiel #6
0
def parse_raw_judgements(life, target_id):
    lfe.execute_raw(life, "judge", "trust", break_on_false=False, life_id=target_id)

    if lfe.execute_raw(life, "judge", "break_trust", life_id=target_id):
        brain.knows_alife_by_id(life, target_id)["trust"] = numbers.clip(
            brain.knows_alife_by_id(life, target_id)["trust"], -1000, -1
        )
        return True

    return False
Beispiel #7
0
def change_alignment(life, life_id, alignment):
    _knows = brain.knows_alife_by_id(life, life_id)

    if not _knows:
        brain.meet_alife(life, LIFE[life_id])
        _knows = brain.knows_alife_by_id(life, life_id)

    logging.debug(
        '%s changed alignment of %s: %s' %
        (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), alignment))
    _knows['alignment'] = alignment
Beispiel #8
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
Beispiel #9
0
def react_to_attack(life, life_id):
	_knows = brain.knows_alife_by_id(life, life_id)
	
	if not _knows['alignment'] == 'hostile':
		speech.start_dialog(life, _knows['life']['id'], 'establish_hostile')
		
	if life['group']:
		groups.announce(life,
		                life['group'],
		                'attacked_by_hostile',
		                target_id=_knows['life']['id'],
		                filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30,
		                ignore_if_said_in_last=150)
Beispiel #10
0
def update_location_of_target_from_target(life, life_id, target_id):
	_known = brain.knows_alife_by_id(life, target_id)
	_target_known = brain.knows_alife_by_id(LIFE[life_id], target_id)	
	
	if _target_known['last_seen_time'] == -1:
		return False
	
	if _target_known['last_seen_time'] < _known['last_seen_time'] or not _known['last_seen_at']:
		_known['last_seen_at'] = _target_known['last_seen_at']
		_known['last_seen_time'] = _target_known['last_seen_time']
		
		logging.debug('%s updated location of %s: %s' % (' '.join(life['name']), ' '.join(LIFE[target_id]['name']), _known['last_seen_at']))
	else:
		print 'Got out of date info!' * 20
Beispiel #11
0
def react_to_attack(life, life_id):
    _knows = brain.knows_alife_by_id(life, life_id)

    if not _knows['alignment'] == 'hostile':
        speech.start_dialog(life, _knows['life']['id'], 'establish_hostile')

    if life['group']:
        groups.announce(life,
                        life['group'],
                        'attacked_by_hostile',
                        target_id=_knows['life']['id'],
                        filter_if=lambda life_id: brain.knows_alife_by_id(
                            life, life_id)['last_seen_time'] <= 30,
                        ignore_if_said_in_last=150)
Beispiel #12
0
def get_closest_target(life, targets):
	if targets:
		_target_positions, _zones = get_target_positions_and_zones(life, targets)
	else:
		#TODO: Dude, what?
		movement.find_target(life, targets, call=False)
		return False
	
	_targets_too_far = []
	_closest_target = {'target_id': None, 'score': 9999}
	for t in [brain.knows_alife_by_id(life, t_id) for t_id in targets]:
		_distance = numbers.distance(life['pos'], t['last_seen_at'])
		
		#NOTE: Hardcoding this for optimization reasons.
		if _distance>=100:
			targets.remove(t['life']['id'])
			_targets_too_far.append(t['life']['id'])
		
		if _distance < _closest_target['score']:
			_closest_target['score'] = _distance
			_closest_target['target_id'] = t['life']['id']
	
	if not _targets_too_far:
		_path_to_nearest = zones.dijkstra_map(life['pos'], _target_positions, _zones)
		
		if not _path_to_nearest:
			_path_to_nearest = [life['pos'][:]]
		
		if not _path_to_nearest:
			logging.error('%s lost known/visible target.' % ' '.join(life['name']))
			
			return False
		
		_target_pos = list(_path_to_nearest[len(_path_to_nearest)-1])
		#else:
		#	_target_pos = life['pos'][:]
		#	_target_positions.append(_target_pos)
		
		target = None
		
		if _target_pos in _target_positions:
			for _target in [brain.knows_alife_by_id(life, t) for t in targets]:
				if _target_pos == _target['last_seen_at']:
					target = _target
					break
	else:
		print 'THIS IS MUCH QUICKER!!!' * 10
		target = brain.knows_alife_by_id(life, _closest_target['target_id'])
	
	return target
Beispiel #13
0
def position_to_attack(life, target):
	if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'positioning for attack'}]):
		if not lfe.ticker(life, 'attack_position', 4):
			return False
	
	_target_positions, _zones = combat.get_target_positions_and_zones(life, [target])
	_nearest_target_score = zones.dijkstra_map(life['pos'], _target_positions, _zones, return_score=True)
	
	#TODO: Short or long-range weapon?
	#if _nearest_target_score >= sight.get_vision(life)/2:
	if not sight.can_see_position(life, brain.knows_alife_by_id(life, target)['last_seen_at'], block_check=True, strict=True) or sight.view_blocked_by_life(life, _target_positions[0], allow=[target]):
		print life['name'], 'changing position for combat...', life['name'], LIFE[target]['name']
		
		_avoid_positions = []
		for life_id in life['seen']:
			if life_id == target or life['id'] == life_id:
				continue
			
			if alife.judgement.can_trust(life, life_id):
				_avoid_positions.append(lfe.path_dest(LIFE[life_id]))
			else:
				_avoid_positions.append(brain.knows_alife_by_id(life, life_id)['last_seen_at'])
		
		_cover = _target_positions
		
		_zones = []
		for pos in _cover:
			_zone = zones.get_zone_at_coords(pos)
			
			if not _zone in _zones:
				_zones.append(_zone)
		
		if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': _cover[:], 'avoid_positions': _avoid_positions}]):
			lfe.stop(life)
			lfe.add_action(life, {'action': 'dijkstra_move',
				                  'rolldown': True,
				                  'goals': _cover[:],
			                      'orig_goals': _cover[:],
			                      'avoid_positions': _avoid_positions,
			                      'reason': 'positioning for attack'},
				           999)
			
			return False
		else:
			return False
	elif life['path']:
		lfe.stop(life)
	
	return True
Beispiel #14
0
def change_alignment(life, life_id, alignment):
    _alignment = '%s_to_%s' % (brain.knows_alife_by_id(
        life, life_id)['alignment'], alignment)

    if not has_sent(life, life_id, _alignment):
        start_dialog(life, life_id, _alignment)
        send(life, life_id, _alignment)
Beispiel #15
0
def get_known_group(life, life_id):
    _target = brain.knows_alife_by_id(life, life_id)
    _dialog_id = lfe.has_dialog_with(life, life_id)

    if 'player' in life:
        _menu_items = []

        for group_id in life['known_groups']:
            if _target['group'] == group_id:
                continue

            _menu_items.append(
                menus.create_item('single',
                                  group_id,
                                  None,
                                  group=group_id,
                                  dialog_id=_dialog_id))

        if not _menu_items:
            gfx.message('You don\'t know of any other groups.')
            return False

        _menu = menus.create_menu(menu=_menu_items,
                                  title='Inform of Group',
                                  format_str='$k',
                                  on_select=confirm_inform_of_group,
                                  close_on_select=True)
        menus.activate_menu(_menu)
    else:
        raise Exception('Dead end.')
Beispiel #16
0
def escape(life, targets):
	_avoid_positions = []
	_zones = [zones.get_zone_at_coords(life['pos'])]
	
	if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'escape'}]):
		if lfe.ticker(life, 'escape_refresh', 4):
			lfe.stop(life)
		else:
			return False
	
	for target_id in targets:
		_target = brain.knows_alife_by_id(life, target_id)
		_zone = zones.get_zone_at_coords(_target['last_seen_at'])
		
		if not _zone in _zones:
			_zones.append(_zone)
		
		_avoid_positions.append(_target['last_seen_at'])
	
	lfe.add_action(life, {'action': 'dijkstra_move',
	                      'rolldown': False,
	                      'zones': _zones,
	                      'goals': _avoid_positions,
	                      'reason': 'escape'},
	               100)
Beispiel #17
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 #18
0
def get_known_group(life, life_id):
	_target = brain.knows_alife_by_id(life, life_id)
	_dialog_id = lfe.has_dialog_with(life, life_id)
	
	if 'player' in life:
		_menu_items = []
		
		for group_id in life['known_groups']:
			if _target['group'] == group_id:
				continue
			
			_menu_items.append(menus.create_item('single', group_id, None, group=group_id, dialog_id=_dialog_id))
		
		if not _menu_items:
			gfx.message('You don\'t know of any other groups.')
			return False
		
		_menu = menus.create_menu(menu=_menu_items,
		                          title='Inform of Group',
		                          format_str='$k',
		                          on_select=confirm_inform_of_group,
		                          close_on_select=True)
		menus.activate_menu(_menu)
	else:
		raise Exception('Dead end.')
Beispiel #19
0
def conditions(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	RETURN_VALUE = STATE_UNCHANGED
	
	_mode = None
	if lfe.execute_raw(life, 'state', 'combat'):
		_mode = 'combat'
	
	if not _mode and lfe.execute_raw(life, 'state', 'hunt'):
		_mode = 'hunt'
	
	if not _mode:
		return False
	
	if not lfe.execute_raw(life, 'combat', 'ranged') and not lfe.execute_raw(life, 'combat', 'melee'):
		return False
	
	if not life['state'] == STATE:
		life['state_flags'] = {}
		stats.battle_cry(life)
		
		if gfx.position_is_in_frame(life['pos']) and SETTINGS['controlling']:
			_can_see = sight.can_see_position(life, LIFE[SETTINGS['controlling']]['pos'])
			
			if _can_see:
				_knows = brain.knows_alife_by_id(life, SETTINGS['controlling'])
				
				if _knows and judgement.can_trust(life, SETTINGS['controlling']):
					if lfe.ticker(life, 'enter_combat_message', 3, fire=True):
						logic.show_event('%s readies up.' % ' '.join(life['name']), life=life)
		
		RETURN_VALUE = STATE_CHANGE
	
	brain.flag(life, 'combat_mode', value=_mode)
	
	return RETURN_VALUE
Beispiel #20
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)
Beispiel #21
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 #22
0
def _target_filter(life, target_list, escaped_only, ignore_escaped, recent_only=False, ignore_lost=False, limit_distance=-1, filter_func=None):
	if not target_list:
		return []
	
	_return_targets = []
	
	for target in target_list:
		if LIFE[target]['dead']:
			continue
		
		_knows = brain.knows_alife_by_id(life, target)
		
		if (escaped_only and not _knows['escaped']==1) or (ignore_escaped and _knows['escaped']>=ignore_escaped):
			continue
		
		if ignore_lost and _knows['escaped'] == 2:
			continue
		
		if recent_only and _knows['last_seen_time'] >= 95:
			continue
		
		if not limit_distance == -1 and _knows['last_seen_at'] and bad_numbers.distance(life['pos'], _knows['last_seen_at'])>limit_distance:
			continue
		
		if filter_func and not filter_func(life, target):
			continue
	
		_return_targets.append(target)
	
	return _return_targets
Beispiel #23
0
def get_target_to_follow(life):
    _highest = {"id": None, "score": 1}

    for target_id in get_trusted(life, visible=False, only_recent=False):
        if not lfe.execute_raw(life, "follow", "follow_target_if", life_id=target_id):
            continue

        _score = 0
        _known_target = brain.knows_alife_by_id(life, target_id)

        if not _known_target["last_seen_at"]:
            continue

        if _known_target["escaped"] == 2:
            continue

        _score += _known_target["trust"]

        if life["group"] and groups.is_leader(life, life["group"], target_id):
            _score += 1

        if _score >= _highest["score"]:
            _highest["id"] = target_id
            _highest["score"] = _score

    return _highest["id"]
Beispiel #24
0
def believe_which_alife(life, alife):
    _scores = {}
    for ai in alife:
        _score = 0

        if can_trust(life, ai):
            _score = get_trust(life, ai)

        if _score in _scores:
            _scores[_score].append(ai)
        else:
            _scores[_score] = [ai]

    _winners = _scores[max(_scores)][:]

    if len(_winners) > 1:
        _scores = {}
        for winner in _winners:
            _know = brain.knows_alife_by_id(life, winner)
            _score = _know["danger"]

            if _score in _scores:
                _scores[_score].append(winner)
            else:
                _scores[_score] = [winner]

        return random.choice(_scores[max(_scores)])

    return _winners[0]
Beispiel #25
0
def believe_which_alife(life, alife):
	_scores = {}
	for ai in alife:
		_score = 0
		
		if can_trust(life, ai):
			_score = get_trust(life, ai)
		
		if _score in _scores:
			_scores[_score].append(ai)
		else:
			_scores[_score] = [ai]
	
	_winners = _scores[max(_scores)][:]
	
	if len(_winners)>1:
		_scores = {}
		for winner in _winners:
			_know = brain.knows_alife_by_id(life, winner)
			_score = _know['danger']
			
			if _score in _scores:
				_scores[_score].append(winner)
			else:
				_scores[_score] = [winner]
		
		return random.choice(_scores[max(_scores)])
	
	return _winners[0]
Beispiel #26
0
def judge_life(life, target_id):
    target = brain.knows_alife_by_id(life, target_id)

    _old_danger = target["danger"]
    _old_trust = target["trust"]

    target["danger"] = _calculate_danger(life, target)
    target["trust"] = _calculate_trust(life, target_id)

    parse_raw_judgements(life, target_id)

    if not _old_danger == target["danger"]:
        print "%s danger in %s: %s -> %s" % (
            " ".join(life["name"]),
            " ".join(target["life"]["name"]),
            _old_danger,
            target["danger"],
        )

    if not _old_trust == target["trust"]:
        print "%s trust in %s: %s -> %s" % (
            " ".join(life["name"]),
            " ".join(target["life"]["name"]),
            _old_trust,
            target["trust"],
        )
Beispiel #27
0
def get_target_to_follow(life):
	_highest = {'id': None, 'score': 0}
	
	for target_id in get_trusted(life, visible=False, only_recent=False):
		if not lfe.execute_raw(life, 'follow', 'follow_target_if', life_id=target_id):
			continue
		
		_score = 0
		_known_target = brain.knows_alife_by_id(life, target_id)
		
		if not _known_target['last_seen_at']:
			continue
		
		if _known_target['escaped'] == 2:
			continue
		
		#_score += _known_target['trust']
			
		if life['group'] and groups.is_leader(life, life['group'], target_id) and groups.get_stage(life, life['group']) == STAGE_RAIDING:
			_score += 1
	
		if _score > _highest['score']:
			_highest['id'] = target_id
			_highest['score'] = _score
	
	return _highest['id']
Beispiel #28
0
def escape(life, targets):
    _avoid_positions = []
    _zones = [zones.get_zone_at_coords(life['pos'])]

    if lfe.find_action(life, [{
            'action': 'dijkstra_move',
            'reason': 'escape'
    }]):
        if lfe.ticker(life, 'escape_refresh', 4):
            lfe.stop(life)
        else:
            return False

    for target_id in targets:
        _target = brain.knows_alife_by_id(life, target_id)
        _zone = zones.get_zone_at_coords(_target['last_seen_at'])

        if not _zone in _zones:
            _zones.append(_zone)

        _avoid_positions.append(_target['last_seen_at'])

    lfe.add_action(
        life, {
            'action': 'dijkstra_move',
            'rolldown': False,
            'zones': _zones,
            'goals': _avoid_positions,
            'reason': 'escape'
        }, 100)
Beispiel #29
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 #30
0
def update_location_of_target_from_target(life, life_id, target_id):
    _known = brain.knows_alife_by_id(life, target_id)
    _target_known = brain.knows_alife_by_id(LIFE[life_id], target_id)

    if _target_known['last_seen_time'] == -1:
        return False

    if _target_known['last_seen_time'] < _known[
            'last_seen_time'] or not _known['last_seen_at']:
        _known['last_seen_at'] = _target_known['last_seen_at']
        _known['last_seen_time'] = _target_known['last_seen_time']

        logging.debug('%s updated location of %s: %s' %
                      (' '.join(life['name']), ' '.join(
                          LIFE[target_id]['name']), _known['last_seen_at']))
    else:
        print 'Got out of date info!' * 20
Beispiel #31
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')
Beispiel #32
0
def react_to_attack(life, life_id):
	_knows = brain.knows_alife_by_id(life, life_id)
	
	if not _knows['alignment'] == 'hostile':
		speech.start_dialog(life, _knows['life']['id'], 'establish_hostile')
		
	if life['group']:
		groups.announce(life, life['group'], 'attacked_by_hostile', target_id=_knows['life']['id'])
Beispiel #33
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 #34
0
def wants_alignment_change(life, life_id):
	_target = brain.knows_alife_by_id(life, life_id)
	
	for memory in lfe.get_memory(life, matches={'text': 'healed_by'}):
		if memory['target'] == life_id:
			if _target['alignment'] == 'feign_trust':
				return 'trust'
	
	return None
Beispiel #35
0
def is_target_lost(life, target_id):
	_know = brain.knows_alife_by_id(life, target_id)
	if sight.can_see_position(life, _know['last_seen_at']):
		if sight.can_see_position(life, _know['life']['pos']):
			return False
		else:
			return True
	
	return False
Beispiel #36
0
def get_orders_for_target(life, life_id, active_only=True):
	_active_orders = []
	for order in brain.knows_alife_by_id(life, life_id)['orders'].values():
		if active_only and not order['active']:
			continue
		
		_active_orders.append(order)
	
	return _active_orders
Beispiel #37
0
def wants_alignment_change(life, life_id):
    _target = brain.knows_alife_by_id(life, life_id)

    for memory in lfe.get_memory(life, matches={'text': 'healed_by'}):
        if memory['target'] == life_id:
            if _target['alignment'] == 'feign_trust':
                return 'trust'

    return None
Beispiel #38
0
def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	if lfe.ticker(life, 'call_for_help', 160, fire=True):
		_target = judgement.get_nearest_threat(life)
		_knows = brain.knows_alife_by_id(life, _target)
		if _target and judgement.get_nearest_trusted_target(life):
			if _knows:
				speech.announce(life, 'attacked_by_hostile', public=True, target_id=_target, last_seen_at=_knows['last_seen_at'])
			else:
				speech.announce(life, 'attacked_by_hostile', public=True, target_id=_target)
Beispiel #39
0
def get_orders_for_target(life, life_id, active_only=True):
	_active_orders = []
	for order in brain.knows_alife_by_id(life, life_id)['orders'].values():
		if active_only and not order['active']:
			continue
		
		_active_orders.append(order)
	
	return _active_orders
Beispiel #40
0
def is_target_lost(life, target_id):
    _know = brain.knows_alife_by_id(life, target_id)
    if sight.can_see_position(life, _know["last_seen_at"]):
        if sight.can_see_position(life, _know["life"]["pos"]):
            return False
        else:
            return True

    return False
Beispiel #41
0
def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	if lfe.ticker(life, 'call_for_help', 160, fire=True):
		_target = judgement.get_nearest_threat(life)
		_knows = brain.knows_alife_by_id(life, _target)
		if _target and judgement.get_nearest_trusted_target(life):
			if _knows:
				speech.announce(life, 'attacked_by_hostile', public=True, target_id=_target, last_seen_at=_knows['last_seen_at'])
			else:
				speech.announce(life, 'attacked_by_hostile', public=True, target_id=_target)
Beispiel #42
0
def get_max_tension_with(life, life_id):
    _target = brain.knows_alife_by_id(life, life_id)

    if _target["alignment"] == "trust" or not _target["last_seen_at"]:
        return 0

    if _target["alignment"] in ["hostile", "scared"]:
        return 1

    return 0.75
Beispiel #43
0
def has_threat_in_combat_range(life):
	_engage_distance = combat.get_engage_distance(life)
	
	for target_id in judgement.get_threats(life):
		_target = brain.knows_alife_by_id(life, target_id)
		
		if numbers.distance(life['pos'], _target['last_seen_at']) <= _engage_distance:
			return True
	
	return False
Beispiel #44
0
def get_distance_to_target(life, target_id):
    target = brain.knows_alife_by_id(life, target_id)
    _goals = [target["last_seen_at"]]
    _zones = [zones.get_zone_at_coords(target["last_seen_at"])]

    _zone = zones.get_zone_at_coords(life["pos"])
    if not _zone in _zones:
        _zones.append(_zone)

    return zones.dijkstra_map(life["pos"], _goals, _zones, return_score=True)
Beispiel #45
0
def get_distance_to_target(life, target_id):
	target = brain.knows_alife_by_id(life, target_id)
	_goals = [target['last_seen_at']]
	_zones = [zones.get_zone_at_coords(target['last_seen_at'])]
	
	_zone = zones.get_zone_at_coords(life['pos'])
	if not _zone in _zones:
		_zones.append(_zone)
	
	return zones.dijkstra_map(life['pos'], _goals, _zones, return_score=True)
Beispiel #46
0
def will_obey(life, life_id):
    _know = brain.knows_alife_by_id(life, life_id)

    if not _know:
        return False

    if judgement.can_trust(life, life_id):
        return True

    return False
Beispiel #47
0
def is_parent_of(life, life_id):
    _know = brain.knows_alife_by_id(life, life_id)

    if not _know:
        return False

    for relation in ['son', 'daughter']:
        if brain.get_alife_flag(life, life_id, relation):
            return True

    return False
Beispiel #48
0
def is_family(life, life_id):
    _know = brain.knows_alife_by_id(life, life_id)

    if not _know:
        return False

    for relation in ['son', 'daughter', 'mother', 'father', 'sibling']:
        if brain.get_alife_flag(life, life_id, relation):
            return True

    return False
Beispiel #49
0
def has_threat_in_combat_range(life):
    _engage_distance = combat.get_engage_distance(life)

    for target_id in judgement.get_threats(life):
        _target = brain.knows_alife_by_id(life, target_id)

        if numbers.distance(life['pos'],
                            _target['last_seen_at']) <= _engage_distance:
            return True

    return False
Beispiel #50
0
def defend_camp(camp_id, life_id):
    _camp = camps.get_camp(camp_id)

    if not life_id in _camp['raid']['defenders']:
        _camp['raid']['defenders'].append(life_id)
        logging.debug('%s is now defending camp %s' %
                      (' '.join(LIFE[life_id]['name']), _camp['name']))

    for raider in get_raiders(camp_id):
        if not brain.knows_alife_by_id(LIFE[life_id], raider):
            brain.meet_alife(LIFE[life_id], LIFE[raider])
Beispiel #51
0
def target_is_combat_ready(life, life_id):
	_knows = brain.knows_alife_by_id(life, life_id)
	
	#They could be in those states but still have a weapon
	if _knows['last_seen_time']:# or _knows['state'] in ['surrender', 'hiding', 'hidden'] or _knows['asleep']:
		return False
	
	if combat.get_equipped_weapons(LIFE[life_id]):
		return True
	
	return False
Beispiel #52
0
def is_scared(life):
	for target in get_all_visible_life(life):
		_knows = brain.knows_alife_by_id(life, target)
		
		if not _knows:
			continue
		
		if _knows['alignment'] == 'scared' and not _knows['asleep'] and not _knows['dead']:
			print life['name'], 'is scared'
			return True
	
	return False
Beispiel #53
0
def get_stance_towards(life, target_id):
    _know = brain.knows_alife_by_id(life, target_id)

    if _know:
        if judgement.can_trust(life, target_id):
            return 'friendly'
        elif judgement.is_target_dangerous(life, target_id):
            return 'hostile'
        else:
            return 'neutral'
    else:
        return 'neutral'
Beispiel #54
0
def get_target_state(life, life_id):
	_target = brain.knows_alife_by_id(life, life_id)
	_mods = []
	
	if _target['asleep']:
		_mods.append('s')
	elif LIFE[life_id]['state_tier'] >= TIER_COMBAT:
		_mods.append('!')
	elif LIFE[life_id]['state_tier'] < TIER_COMBAT:
		_mods.append('c')
	
	return ''.join(_mods)
Beispiel #55
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))
Beispiel #56
0
def get_ranged_combat_ready_score(life, consider_target_id=None):
	_score = 0
	
	if consider_target_id:
		_target = brain.knows_alife_by_id(life, consider_target_id)
		#TODO: Judge proper distance based on weapon equip time
		if bad_numbers.distance(life['pos'], _target['last_seen_at'])<sight.get_vision(life)/2:
			if lfe.get_held_items(life, matches=[{'type': 'gun'}]):
				_score += 1
		elif lfe.get_all_inventory_items(life, matches=[{'type': 'gun'}]):
			_score += 1
	
	return _score