示例#1
0
def get_best_weapon(life):
	_weapons = lfe.get_all_inventory_items(life, matches=[{'type': 'gun'}], ignore_actions=True)
	
	_best_wep = {'weapon': None, 'feed': None, 'rounds': 0}
	for _wep in _weapons:
		_feed_rounds = 0
		_free_rounds = 0
		_feeds = lfe.get_all_inventory_items(life,
			matches=[{'type': _wep['feed'],'ammotype': _wep['ammotype']}])
		
		_loaded_feed_uid = weapons.get_feed(_wep)
		if _loaded_feed_uid:
			_loaded_feed = items.get_item_from_uid(_loaded_feed_uid)
			
			if len(_loaded_feed['rounds'])>_best_wep['rounds']:
				_best_wep['weapon'] = _wep
				_best_wep['feed'] = _loaded_feed
				_best_wep['rounds'] = len(_loaded_feed['rounds'])
				continue

		for _feed in _feeds:
			_feed_rounds = len(_feed['rounds'])
			_free_rounds = len(lfe.get_all_inventory_items(life,
				matches=[{'type': 'bullet', 'ammotype': _wep['ammotype']}]))
			
			if _feed_rounds+_free_rounds > _best_wep['rounds']:
				_best_wep['weapon'] = _wep
				_best_wep['feed'] = _feed
				_best_wep['rounds'] = _feed_rounds+_free_rounds
	
	if not _best_wep['weapon'] or not _best_wep['feed']:
		return False
	
	return _best_wep
示例#2
0
文件: combat.py 项目: flags/Reactor-3
def get_best_weapon(life):
	_weapons = lfe.get_all_inventory_items(life, matches=[{'type': 'gun'}], ignore_actions=True)
	
	_best_wep = {'weapon': None, 'feed': None, 'rounds': 0}
	for _wep in _weapons:
		_feed_rounds = 0
		_free_rounds = 0
		_feeds = lfe.get_all_inventory_items(life,
			matches=[{'type': _wep['feed'],'ammotype': _wep['ammotype']}])
		
		_loaded_feed_uid = weapons.get_feed(_wep)
		if _loaded_feed_uid:
			_loaded_feed = items.get_item_from_uid(_loaded_feed_uid)
			
			if len(_loaded_feed['rounds'])>_best_wep['rounds']:
				_best_wep['weapon'] = _wep
				_best_wep['feed'] = _loaded_feed
				_best_wep['rounds'] = len(_loaded_feed['rounds'])
				continue

		for _feed in _feeds:
			_feed_rounds = len(_feed['rounds'])
			_free_rounds = len(lfe.get_all_inventory_items(life,
				matches=[{'type': 'bullet', 'ammotype': _wep['ammotype']}]))
			
			if _feed_rounds+_free_rounds > _best_wep['rounds']:
				_best_wep['weapon'] = _wep
				_best_wep['feed'] = _feed
				_best_wep['rounds'] = _feed_rounds+_free_rounds
	
	if not _best_wep['weapon'] or not _best_wep['feed']:
		return False
	
	return _best_wep
示例#3
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
示例#4
0
def get_player_situation():
	if not SETTINGS['controlling']:
		return False
	
	_life = LIFE[SETTINGS['controlling']]
	
	_situation = {}
	_situation['armed'] = alife.combat.has_potentially_usable_weapon(_life)
	_situation['friends'] = len([l for l in _life['know'].values() if l['alignment'] in ['trust', 'feign_trust']])
	_situation['group'] = _life['group']
	_situation['online_alife'] = [l for l in LIFE.values() if l['online'] and not l['dead'] and not l['id'] == _life['id']]
	_situation['trusted_online_alife'] = [l for l in _situation['online_alife'] if alife.judgement.can_trust(_life, l['id'])]
	_situation['has_radio'] = len(lfe.get_all_inventory_items(_life, matches=[{'type': 'radio'}]))>0
	_situation['weapons'] = alife.combat.get_weapons(_life)
	_situation['equipped_gear'] = lfe.get_all_equipped_items(_life)	
	_active_factions = set()
	_enemy_factions = set()
	
	for life in _situation['online_alife']:
		if not life['faction'] in _active_factions:
			_active_factions.add(life['faction'])
		
		if alife.factions.is_enemy(_life, life['id']) and not life['faction'] in _enemy_factions:
			_enemy_factions.add(life['faction'])
	
	_situation['active_factions'] = list(_active_factions)
	_situation['friendly_factions'] = list(_enemy_factions-_active_factions)
	_situation['active_factions'] = list(_active_factions)
	_situation['enemy_factions'] = list(_enemy_factions)
	
	return _situation
示例#5
0
def process(life):
    for need in life['needs'].values():
        if need['type'] == 'item':
            _has_items = []
            _potential_items = []

            for item in brain.get_matching_remembered_items(life,
                                                            need['match'],
                                                            no_owner=True):
                if brain.get_item_flag(life, ITEMS[item], 'ignore'):
                    continue

                _potential_items.append(item)

            for item in lfe.get_all_inventory_items(life,
                                                    matches=[need['match']]):
                _has_items.append(item['uid'])

            if len(_has_items) >= _get_need_amount(life, need):
                need['meet_with'] = _has_items
            elif _potential_items:
                need['could_meet_with'] = _potential_items
            else:
                need['meet_with'] = []
                need['could_meet_with'] = []
示例#6
0
def _refill_feed(life, feed):
	if not lfe.is_holding(life, feed['uid']) and not lfe.can_hold_item(life):
		logging.warning('No hands free to load ammo!')
		
		return False

	if not lfe.get_held_items(life, matches=[{'id': feed['uid']}]) and lfe.item_is_stored(life, feed['uid']) and not lfe.find_action(life, matches=[{'action': 'removeandholditem'}]):
		lfe.add_action(life,{'action': 'removeandholditem',
			'item': feed['uid']},
			200,
			delay=0)
		
		return False

	#TODO: No check for ammo type.
	
	_loading_rounds = len(lfe.find_action(life,matches=[{'action': 'refillammo'}]))
	if _loading_rounds >= len(lfe.get_all_inventory_items(life,matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}])):
		#TODO: What?
		if not _loading_rounds:
			return True
		
		return False
	
	if len(lfe.find_action(life,matches=[{'action': 'refillammo'}])):
		return False
	
	_rounds = len(feed['rounds'])
	
	if _rounds>=feed['maxrounds']:
		print 'Full?'
		return True
	
	_ammo_count = len(lfe.get_all_inventory_items(life,matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}]))
	_ammo_count += len(feed['rounds'])
	_rounds_to_load = numbers.clip(_ammo_count,0,feed['maxrounds'])
	for ammo in lfe.get_all_inventory_items(life,matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}])[:_rounds_to_load]:		
		lfe.add_action(life,{'action': 'refillammo',
			'ammo': feed,
			'round': ammo},
			200,
			delay=3)
		
		_rounds += 1
	
	return False
示例#7
0
def get_feeds_for_weapon(life, weapon_uid):
    _weapon = ITEMS[weapon_uid]

    return lfe.get_all_inventory_items(life,
                                       matches=[{
                                           'type': _weapon['feed'],
                                           'ammotype': _weapon['ammotype']
                                       }],
                                       ignore_actions=True)
示例#8
0
def get_loose_ammo_for_weapon(life, weapon_uid):
    _weapon = ITEMS[weapon_uid]

    return lfe.get_all_inventory_items(life,
                                       matches=[{
                                           'type': 'bullet',
                                           'ammotype': _weapon['ammotype']
                                       }],
                                       ignore_actions=True)
示例#9
0
def _refill_feed(life, feed):
	if not lfe.is_holding(life, feed['uid']) and not lfe.can_hold_item(life):
		logging.warning('No hands free to load ammo!')
		
		return False

	if not lfe.get_held_items(life, matches=[{'id': feed['uid']}]) and lfe.item_is_stored(life, feed['uid']) and not lfe.find_action(life, matches=[{'action': 'removeandholditem'}]):
		lfe.add_action(life,{'action': 'removeandholditem',
			'item': feed['uid']},
			200,
			delay=0)
		
		return False

	#TODO: No check for ammo type.
	
	_loading_rounds = len(lfe.find_action(life, matches=[{'action': 'refillammo'}]))
	_bullets_in_inventory = len(lfe.get_all_inventory_items(life, matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}]))
	
	if _loading_rounds:# >= _bullets_in_inventory:
		return False
	
	if len(lfe.find_action(life,matches=[{'action': 'refillammo'}])):
		return False
	
	_rounds = len(feed['rounds'])
	
	if _rounds>=feed['maxrounds'] or (not _bullets_in_inventory and _rounds):
		print 'Full?'
		return True
	
	_ammo_count = len(lfe.get_all_inventory_items(life,matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}]))
	_ammo_count += len(feed['rounds'])
	_rounds_to_load = numbers.clip(_ammo_count,0,feed['maxrounds'])
	for ammo in lfe.get_all_inventory_items(life,matches=[{'type': 'bullet', 'ammotype': feed['ammotype']}])[:_rounds_to_load]:		
		lfe.add_action(life,{'action': 'refillammo',
			'ammo': feed,
			'round': ammo},
			200,
			delay=3)
		
		_rounds += 1
	
	return False
示例#10
0
def _get_feed(life, weapon):
	_feeds = lfe.get_all_inventory_items(life, matches=[{'type': weapon['feed'], 'ammotype': weapon['ammotype']}], ignore_actions=False)

	_highest_feed = {'rounds': -1, 'feed': None}
	for feed in [lfe.get_inventory_item(life, _feed['uid']) for _feed in _feeds]:
		if feed['rounds']>_highest_feed['rounds']:
			_highest_feed['rounds'] = feed['rounds']
			_highest_feed['feed'] = feed
	
	return _highest_feed['feed']
示例#11
0
文件: combat.py 项目: flags/Reactor-3
def _get_feed(life, weapon):
	_feeds = lfe.get_all_inventory_items(life, matches=[{'type': weapon['feed'], 'ammotype': weapon['ammotype']}], ignore_actions=False)

	_highest_feed = {'rounds': -1, 'feed': None}
	for feed in [lfe.get_inventory_item(life, _feed['uid']) for _feed in _feeds]:
		if feed['rounds']>_highest_feed['rounds']:
			_highest_feed['rounds'] = feed['rounds']
			_highest_feed['feed'] = feed
	
	return _highest_feed['feed']
示例#12
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
示例#13
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 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
示例#14
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
示例#15
0
def get_ranged_combat_rating_of_target(life, life_id, inventory_check=True):
	target = LIFE[life_id]
	_score = 1
	_score_mod = 1
	
	_items = [ITEMS[i] for i in lfe.get_all_visible_items(target) if i in ITEMS and logic.matches(ITEMS[i], {'type': 'gun'})]
	
	if not _items and inventory_check:
		_items = [i for i in lfe.get_all_inventory_items(target) if i['uid'] in ITEMS and logic.matches(i, {'type': 'gun'})]
		_score_mod = .5
	
	for item in _items:
		if bad_numbers.distance(life['pos'], target['pos']) > combat.get_engage_distance(target):
			_score += item['accuracy']/2
		else:
			_score += item['accuracy']
	
	if _score:
		_score += 2*(life['stats']['firearms']/10.0)
	
	return _score*_score_mod
示例#16
0
def process(life):
    for need in life["needs"].values():
        if need["type"] == "item":
            _has_items = []
            _potential_items = []

            for item in brain.get_matching_remembered_items(life, need["match"], no_owner=True):
                if brain.get_item_flag(life, ITEMS[item], "ignore"):
                    continue

                _potential_items.append(item)

            for item in lfe.get_all_inventory_items(life, matches=[need["match"]]):
                _has_items.append(item["uid"])

            if len(_has_items) >= _get_need_amount(life, need):
                need["meet_with"] = _has_items
            elif _potential_items:
                need["could_meet_with"] = _potential_items
            else:
                need["meet_with"] = []
                need["could_meet_with"] = []
示例#17
0
def process(life):
	for need in life['needs'].values():
		if need['type'] == 'item':
			_has_items = []
			_potential_items = []
			
			for item in brain.get_matching_remembered_items(life, need['match'], no_owner=True):
				if brain.get_item_flag(life, ITEMS[item], 'ignore'):
					continue
				
				_potential_items.append(item)
				
			for item in lfe.get_all_inventory_items(life, matches=[need['match']]):
				_has_items.append(item['uid'])
			
			if len(_has_items) >= _get_need_amount(life, need):
				need['meet_with'] = _has_items
			elif _potential_items:
				need['could_meet_with'] = _potential_items
			else:
				need['meet_with'] = []
				need['could_meet_with'] = []
示例#18
0
文件: combat.py 项目: flags/Reactor-3
def get_loose_ammo_for_weapon(life, weapon_uid):
	_weapon = ITEMS[weapon_uid]
	
	return lfe.get_all_inventory_items(life, matches=[{'type': 'bullet', 'ammotype': _weapon['ammotype']}], ignore_actions=True)
示例#19
0
def create_function_map():
    FUNCTION_MAP.update(
        {
            "is_family": stats.is_family,
            "is_same_species": stats.is_same_species,
            "can_trust": judgement.can_trust,
            "is_dangerous": judgement.is_target_dangerous,
            "can_bite": stats.can_bite,
            "can_scratch": stats.can_scratch,
            "weapon_equipped_and_ready": combat.weapon_equipped_and_ready,
            "prepare_for_ranged": combat.prepare_for_ranged,
            "explore_unknown_chunks": survival.explore_unknown_chunks,
            "is_nervous": stats.is_nervous,
            "is_aggravated": stats.is_aggravated,
            "is_scared": judgement.is_scared,
            "is_safe": judgement.is_safe,
            "is_healthy": None,
            "is_intimidated": stats.is_intimidated,
            "is_intimidating": lambda life, life_id: stats.is_intimidated_by(LIFE[life_id], life["id"]),
            "is_confident": stats.is_confident,
            "is_situation_tense": lambda life: judgement.get_tension(life) >= 10,
            "is_combat_ready": lambda life, life_id: not LIFE[life_id]["state"] in ["hiding", "hidden"],
            "is_surrendering": lambda life, life_id: LIFE[life_id]["state"] == "surrender",
            "is_being_surrendered_to": lambda life: len(
                judgement.get_combat_targets(
                    life, ignore_escaped=True, filter_func=lambda life, life_id: LIFE[life_id]["state"] == "surrender"
                )
            )
            > 0,
            "closest": None,
            "kill": lambda life: lfe.kill(life, "their own dumb self"),
            "has_attacked_trusted": stats.has_attacked_trusted,
            "has_attacked_self": stats.has_attacked_self,
            "distance_to_pos": stats.distance_from_pos_to_pos,
            "current_chunk_has_flag": lambda life, flag: chunks.get_flag(life, lfe.get_current_chunk_id(life), flag)
            > 0,
            "is_idle": lambda life: life["state"] == "idle",
            "is_relaxed": lambda life: life["state_tier"] == TIER_RELAXED,
            "is_child_of": stats.is_child_of,
            "is_parent_of": stats.is_parent_of,
            "has_parent": stats.has_parent,
            "has_child": stats.has_child,
            "is_night": logic.is_night,
            "is_born_leader": stats.is_born_leader,
            "is_psychotic": stats.is_psychotic,
            "is_safe_in_shelter": stats.is_safe_in_shelter,
            "is_incapacitated": stats.is_incapacitated,
            "is_target": lambda life, life_id: life_id in judgement.get_targets(life)
            or life_id in judgement.get_combat_targets(life),
            "seen_target_recently": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["last_seen_time"]
            <= 150,
            "is_combat_target": lambda life, life_id: life_id in judgement.get_combat_targets(life),
            "is_traitor": lambda life, life_id: len(
                lfe.get_memory(life, matches={"text": "traitor", "target": life_id})
            )
            > 0,
            "is_awake": judgement.is_target_awake,
            "is_dead": judgement.is_target_dead,
            "is_raiding": lambda life: (life["group"] and groups.get_stage(life, life["group"]) == STAGE_RAIDING)
            == True,
            "find_and_announce_shelter": groups.find_and_announce_shelter,
            "desires_shelter": stats.desires_shelter,
            "travel_to_position": movement.travel_to_position,
            "find_target": movement.find_target,
            "can_see_target": sight.can_see_target,
            "has_threats": lambda life: len(judgement.get_threats(life, ignore_escaped=1)) > 0,
            "has_visible_threat": lambda life: len(judgement.get_visible_threats(life)) > 0,
            "has_combat_targets": lambda life: len(judgement.get_combat_targets(life)) > 0,
            "has_lost_threat": lambda life: len(judgement.get_threats(life, escaped_only=True, ignore_escaped=2)) > 0,
            "has_ready_combat_targets": lambda life: len(
                judgement.get_ready_combat_targets(life, recent_only=True, limit_distance=sight.get_vision(life) + 10)
            )
            > 0,
            "danger_close": stats.is_threat_too_close,
            "number_of_alife_in_chunk_matching": lambda life, chunk_key, matching, amount: len(
                chunks.get_alife_in_chunk_matching(chunk_key, matching)
            )
            > amount,
            "number_of_alife_in_reference_matching": lambda life, reference_id, matching, amount: len(
                references.get_alife_in_reference_matching(reference_id, matching)
            )
            > amount,
            "announce_to_group": groups.announce,
            "is_in_chunk": chunks.is_in_chunk,
            "is_in_shelter": lfe.is_in_shelter,
            "has_shelter": lambda life: len(judgement.get_known_shelters(life)) > 0,
            "has_completed_job": lambda life, job_id: job_id in life["completed_jobs"],
            "has_completed_task": lambda life, job_id: job_id in life["completed_jobs"],
            "retrieve_from_memory": brain.retrieve_from_memory,
            "pick_up_and_hold_item": lfe.pick_up_and_hold_item,
            "has_usable_weapon": lambda life: not combat.has_ready_weapon(life) == False,
            "target_is_combat_ready": judgement.target_is_combat_ready,
            "create_item_need": survival.add_needed_item,
            "group_needs_resources": lambda life, group_id: groups.needs_resources(group_id),
            "has_needs_to_meet": survival.has_needs_to_meet,
            "has_unmet_needs": survival.has_unmet_needs,
            "has_needs_to_satisfy": survival.has_needs_to_satisfy,
            "has_needs": lambda life: survival.has_needs_to_meet(life)
            or survival.has_unmet_needs(life)
            or survival.has_needs_to_satisfy(life),
            "has_number_of_items_matching": lambda life, matching, amount: len(
                lfe.get_all_inventory_items(life, matches=matching)
            )
            >= amount,
            "flag_item_matching": lambda life, matching, flag: lfe.get_all_inventory_items(life, matches=[matching])
            and brain.flag_item(life, lfe.get_all_inventory_items(life, matches=[matching])[0], flag) > 0,
            "drop_item_matching": lambda life, matching: lfe.get_all_inventory_items(life, matches=[matching])
            and lfe.drop_item(life, lfe.get_all_inventory_items(life, matches=[matching])[0]["uid"]) > 0,
            "has_target_to_follow": lambda life: judgement.get_target_to_follow(life) > 0,
            "has_target_to_guard": lambda life: judgement.get_target_to_guard(life) > 0,
            "get_recent_events": speech.get_recent_events,
            "get_target": lambda life, life_id: speech.get_target(
                life,
                lfe.has_dialog_with(life, life_id),
                dialog.get_flag(lfe.has_dialog_with(life, life_id), "NEXT_GIST"),
            ),
            "get_needs": lambda life, life_id: speech.get_needs(
                life,
                lfe.has_dialog_with(life, life_id),
                dialog.get_flag(lfe.has_dialog_with(life, life_id), "NEXT_GIST"),
            ),
            "get_location": lambda life: "%s, %s" % (life["pos"][0], life["pos"][1]),
            "join_group": lambda life, **kwargs: groups.join_group(life, kwargs["group_id"]),
            "add_group_member": lambda life, life_id: groups.add_member(life, life["group"], life_id),
            "claim_to_be_group_leader": lambda life, life_id: groups.set_leader(life, life["group"], life["id"]),
            "is_group_leader": lambda life: groups.is_leader_of_any_group(life) == True,
            "is_in_same_group": lambda life, life_id: (life["group"] and LIFE[life_id]["group"] == life["group"]) > 0,
            "is_target_group_leader": lambda life, life_id: (groups.is_leader_of_any_group(LIFE[life_id])) == True,
            "is_in_group": lambda life: life["group"] > 0,
            "is_target_hostile": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["alignment"] == "hostile",
            "is_target_in_group": lambda life, life_id, **kwargs: brain.knows_alife_by_id(life, life_id)["group"]
            == kwargs["group"],
            "is_target_in_any_group": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["group"] > 0,
            "is_target_group_friendly": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["group"]
            and groups.get_group_memory(life, brain.knows_alife_by_id(life, life_id)["group"], "alignment") == "trust",
            "is_target_group_hostile": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["group"]
            and groups.get_group_memory(life, brain.knows_alife_by_id(life, life_id)["group"], "alignment")
            == "hostile",
            "is_target_group_neutral": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["group"]
            and groups.get_group_memory(life, brain.knows_alife_by_id(life, life_id)["group"], "alignment")
            == "neutral",
            "is_group_hostile": lambda life, **kwargs: groups.get_group_memory(life, kwargs["group_id"], "alignment")
            == "hostile",
            "inform_of_group_members": speech.inform_of_group_members,
            "update_group_members": speech.update_group_members,
            "get_group_flag": groups.get_flag,
            "get_flag": brain.get_flag,
            "get_group": lambda life: life["group"],
            "discover_group": lambda life, **kwargs: groups.discover_group(life, kwargs["group_id"]),
            "add_target_to_known_group": lambda life, life_id, **kwargs: groups.add_member(
                life, kwargs["group_id"], life_id
            ),
            "knows_about_group": lambda life, **kwargs: groups.group_exists(life, kwargs["group_id"]),
            "group_has_shelter": lambda life: groups.get_shelter(life, life["group"]) > 0,
            "declare_group_hostile": lambda life, **kwargs: stats.declare_group_hostile(life, kwargs["group_id"]),
            "declare_group_trusted": lambda life, **kwargs: stats.declare_group_trusted(life, kwargs["group_id"]),
            "declare_group_target": lambda life, life_id: stats.declare_group_target(life, life_id, "hostile"),
            "get_group_shelter": lambda life: groups.get_shelter(life, life["group"]),
            "set_group_shelter": lambda life, **kwargs: groups.set_shelter(life, kwargs["group_id"], kwargs["shelter"]),
            "get_group_stage": lambda life: groups.get_stage(life, life["group"]),
            "get_group_stage_message": speech.get_group_stage_message,
            "set_group_stage": lambda life, **kwargs: groups.set_stage(life, kwargs["group_id"], kwargs["stage"]),
            "is_group_motivated_for_crime": lambda life: life["group"]
            and groups.get_motive(life, life["group"]) == "crime",
            "wants_to_leave_group_for_group": lambda life: stats.wants_to_abandon_group(life, life["group"]),
            "knows_items_matching": lambda life, **kwargs: len(
                brain.get_multi_matching_remembered_items(life, kwargs["items"], no_owner=True)
            )
            > 0,
            "get_known_group": speech.get_known_group,
            "inform_of_group": speech.inform_of_group,
            "force_inform_of_group": speech.force_inform_of_group,
            "inform_of_items": lambda life, life_id, **kwargs: speech.inform_of_items(life, life_id, kwargs["items"]),
            "update_location": lambda life, life_id: brain.update_known_life(
                life, life_id, "last_seen_at", life["pos"][:]
            ),
            "has_questions_for_target": lambda life, life_id: len(memory.get_questions_for_target(life, life_id)) > 0,
            "has_orders_for_target": lambda life, life_id: len(memory.get_orders_for_target(life, life_id)) > 0,
            "ask_target_question": memory.ask_target_question,
            "give_target_order_message": memory.give_target_order_message,
            "give_target_order": memory.give_target_order,
            "take_order": memory.take_order,
            "reject_order": memory.reject_order,
            "get_introduction_message": speech.get_introduction_message,
            "get_introduction_gist": speech.get_introduction_gist,
            "establish_trust": stats.establish_trust,
            "establish_feign_trust": stats.establish_trust,
            "establish_aggressive": stats.establish_aggressive,
            "establish_hostile": stats.establish_hostile,
            "establish_scared": stats.establish_scared,
            "claim_hostile": lambda life, target, **kwargs: stats.establish_hostile(life, kwargs["target_id"]),
            "describe_target": lambda life, life_id, **kwargs: speech.describe_target(life, kwargs["target"]),
            "consume": lfe.consume,
            "explode": items.explode,
            "is_player": lambda life: "player" in life,
            "is_neutral": lambda life, life_id: brain.knows_alife_by_id(life, life_id)["alignment"] == "neutral",
            "reset_think_timer": lfe.reset_think_rate,
            "mark_target_as_combat_ready": lambda life, life_id: brain.flag_alife(life, life_id, "combat_ready"),
            "mark_target_as_not_combat_ready": lambda life, life_id: brain.flag_alife(
                life, life_id, "combat_ready", value=False
            ),
            "saw_target_recently": lambda life, **kwargs: brain.knows_alife_by_id(life, kwargs["target_id"])
            and -1 < brain.knows_alife_by_id(life, kwargs["target_id"])["last_seen_time"] < 6000,
            "update_location_of_target_from_target": speech.update_location_of_target_from_target,
            "ping": lambda life: logging.debug("%s: Ping!" % " ".join(life["name"])),
            "wander": lambda life: alife_discover.tick(life),
            "pick_up_item": lambda life: alife_needs.tick(life),
            "take_shelter": lambda life: alife_shelter.tick(life),
            "has_non_relaxed_goal": lambda life: life["state_tier"] > TIER_RELAXED,
            "needs_to_manage_inventory": lambda life: alife_manage_items.conditions(life),
            "manage_inventory": lambda life: alife_manage_items.tick(life),
            "cover_exposed": lambda life: len(combat.get_exposed_positions(life)) > 0,
            "ranged_ready": lambda life: lfe.execute_raw(life, "combat", "ranged_ready"),
            "ranged_attack": lambda life: alife_combat.ranged_attack(life),
            "melee_ready": lambda life: lfe.execute_raw(life, "combat", "melee_ready"),
            "melee_attack": lambda life: alife_combat.melee_attack(life),
            "take_cover": lambda life: alife_cover.tick(life),
            "hide": lambda life: alife_hide.tick(life),
            "search_for_threat": lambda life: alife_search.tick(life),
            "has_recoil": lambda life: life["recoil"] >= 4,
            "has_focus_point": lambda life: len(lfe.get_memory(life, matches={"text": "focus_on_chunk"})) > 0,
            "walk_to": lambda life: movement.travel_to_chunk(
                life, lfe.get_memory(life, matches={"text": "focus_on_chunk"})[0]["chunk_key"]
            ),
            "follow_target": alife_follow.tick,
            "guard_focus_point": lambda life: movement.guard_chunk(
                life, lfe.get_memory(life, matches={"text": "focus_on_chunk"})[0]["chunk_key"]
            ),
            "disarm": lambda life, life_id: brain.flag_alife(life, life_id, "disarm", value=WORLD_INFO["ticks"]),
            "is_disarming": lambda life, life_id: brain.get_alife_flag(life, life_id, "disarm") > 0,
            "get_id": lambda life: life["id"],
            "always": lambda life: 1 == 1,
            "pass": lambda life, *a, **k: True,
            "never": lambda life: 1 == 2,
        }
    )
示例#20
0
文件: combat.py 项目: flags/Reactor-3
def get_weapons(life):
	return lfe.get_all_inventory_items(life, matches=[{'type': 'gun'}], ignore_actions=False)
示例#21
0
def _has_inventory_item(life, matches={}):
    return lfe.get_all_inventory_items(life, matches=[matches])
示例#22
0
文件: combat.py 项目: flags/Reactor-3
def get_feeds_for_weapon(life, weapon_uid):
	_weapon = ITEMS[weapon_uid]
	
	return lfe.get_all_inventory_items(life, matches=[{'type': _weapon['feed'], 'ammotype': _weapon['ammotype']}], ignore_actions=True)
示例#23
0
def get_weapons(life):
    return lfe.get_all_inventory_items(life,
                                       matches=[{
                                           'type': 'gun'
                                       }],
                                       ignore_actions=False)
示例#24
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']])
示例#25
0
def create_function_map():
	FUNCTION_MAP.update({'is_family': stats.is_family,
		'name': lambda life: ' '.join(life['name']),
		'is_same_species': stats.is_same_species,
		'can_trust': judgement.can_trust,
		'is_dangerous': judgement.is_target_dangerous,
		'can_bite': stats.can_bite,
		'can_scratch': stats.can_scratch,
		'weapon_equipped_and_ready': combat.weapon_equipped_and_ready,
		'prepare_for_ranged': combat.prepare_for_ranged,
		'explore_unknown_chunks': survival.explore_unknown_chunks,
		'is_nervous': stats.is_nervous,
		'is_aggravated': stats.is_aggravated,
		'is_scared': judgement.is_scared,
		'is_safe': judgement.is_safe,
		'is_healthy': None,
		'is_intimidated': stats.is_intimidated,
		'is_intimidating': lambda life, life_id: stats.is_intimidated_by(LIFE[life_id], life['id']),
		'is_confident': stats.is_confident,
		'is_situation_tense': lambda life: judgement.get_tension(life)>=10,
		'is_combat_ready': lambda life, life_id: not LIFE[life_id]['state'] in ['hiding', 'hidden'],
		'is_surrendering': lambda life, life_id: LIFE[life_id]['state'] == 'surrender',
		'is_being_surrendered_to': lambda life: len(judgement.get_combat_targets(life, ignore_escaped=True, filter_func=lambda life, life_id: LIFE[life_id]['state'] == 'surrender'))>0,
		'closest': None,
		'kill': lambda life: lfe.kill(life, 'their own dumb self'),
		'has_attacked_trusted': stats.has_attacked_trusted,
		'has_attacked_self': stats.has_attacked_self,
		'distance_to_pos': stats.distance_from_pos_to_pos,
		'current_chunk_has_flag': lambda life, flag: chunks.get_flag(life, lfe.get_current_chunk_id(life), flag)>0,
		'is_idle': lambda life: life['state'] == 'idle',
		'is_relaxed': lambda life: life['state_tier'] == TIER_RELAXED,
		'is_child_of': stats.is_child_of,
		'is_parent_of': stats.is_parent_of,
		'has_parent': stats.has_parent,
		'has_child': stats.has_child,
		'is_night': logic.is_night,
		'is_born_leader': stats.is_born_leader,
		'is_psychotic': stats.is_psychotic,
		'is_safe_in_shelter': stats.is_safe_in_shelter,
		'is_incapacitated': stats.is_incapacitated,
		'is_target': lambda life, life_id: life_id in judgement.get_targets(life) or life_id in judgement.get_combat_targets(life),
		'seen_target_recently': lambda life, life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=150,
		'is_combat_target': lambda life, life_id: life_id in judgement.get_combat_targets(life),
		'is_traitor': lambda life, life_id: len(lfe.get_memory(life, matches={'text': 'traitor', 'target': life_id}))>0,
		'is_awake': judgement.is_target_awake,
		'is_dead': judgement.is_target_dead,
		'is_target_dead': judgement.is_target_dead,
		'is_raiding': lambda life: (life['group'] and groups.get_stage(life, life['group'])==STAGE_RAIDING)==True,
		'find_and_announce_shelter': groups.find_and_announce_shelter,
		'desires_shelter': stats.desires_shelter,
		'travel_to_position': movement.travel_to_position,
		'find_target': movement.find_target,
		'can_see_target': sight.can_see_target,
		'has_threats': lambda life: len(judgement.get_threats(life, ignore_escaped=1))>0,
		'has_visible_threat': lambda life: len(judgement.get_visible_threats(life))>0,
		'has_combat_targets': lambda life: len(judgement.get_combat_targets(life))>0,
		'has_lost_threat': lambda life: len(judgement.get_threats(life, escaped_only=True, ignore_escaped=2))>0,
		'has_ready_combat_targets': lambda life: len(judgement.get_ready_combat_targets(life, recent_only=True, limit_distance=sight.get_vision(life)+10))>0,
		'danger_close': stats.is_threat_too_close,
		'number_of_alife_in_chunk_matching': lambda life, chunk_key, matching, amount: len(chunks.get_alife_in_chunk_matching(chunk_key, matching))>amount,
		'number_of_alife_in_reference_matching': lambda life, reference_id, matching, amount: len(references.get_alife_in_reference_matching(reference_id, matching))>amount,
		'announce_to_group': groups.announce,
		'is_in_chunk': chunks.is_in_chunk,
		'is_in_shelter': lfe.is_in_shelter,
		'has_shelter': lambda life: len(judgement.get_known_shelters(life))>0,
		'has_completed_job': lambda life, job_id: job_id in life['completed_jobs'],
		'has_completed_task': lambda life, job_id: job_id in life['completed_jobs'],
		'retrieve_from_memory': brain.retrieve_from_memory,
		'pick_up_and_hold_item': lfe.pick_up_and_hold_item,
		'has_usable_weapon': lambda life: not combat.has_ready_weapon(life) == False,
		'has_potentially_usable_weapon': lambda life: combat.has_potentially_usable_weapon(life) == True,
		'target_is_combat_ready': judgement.target_is_combat_ready,
		'create_item_need': survival.add_needed_item,
		'group_needs_resources': lambda life, group_id: groups.needs_resources(group_id),
		'has_needs_to_meet': survival.has_needs_to_meet,
		'has_unmet_needs': survival.has_unmet_needs,
		'has_needs_to_satisfy': survival.has_needs_to_satisfy,
		'has_needs': lambda life: survival.has_needs_to_meet(life) or survival.has_unmet_needs(life) or survival.has_needs_to_satisfy(life),
		'has_number_of_items_matching': lambda life, matching, amount: len(lfe.get_all_inventory_items(life, matches=matching))>=amount,
		'flag_item_matching': lambda life, matching, flag: lfe.get_all_inventory_items(life, matches=[matching]) and brain.flag_item(life, lfe.get_all_inventory_items(life, matches=[matching])[0], flag)>0,
		'drop_item_matching': lambda life, matching: lfe.get_all_inventory_items(life, matches=[matching]) and lfe.drop_item(life, lfe.get_all_inventory_items(life, matches=[matching])[0]['uid'])>0,
		'has_target_to_follow': lambda life: judgement.get_target_to_follow(life)>0,
		'has_target_to_guard': lambda life: judgement.get_target_to_guard(life)>0,
		'get_recent_events': speech.get_recent_events,
		'get_target': lambda life, life_id: speech.get_target(life,
	                                                           lfe.has_dialog_with(life, life_id),
	                                                           dialog.get_flag(lfe.has_dialog_with(life, life_id),
	                                                                           'NEXT_GIST')),
		'get_needs': lambda life, life_id: speech.get_needs(life,
	                                                         lfe.has_dialog_with(life, life_id),
	                                                         dialog.get_flag(lfe.has_dialog_with(life, life_id),
	                                                                         'NEXT_GIST')),
		'get_location': lambda life: '%s, %s' % (life['pos'][0], life['pos'][1]),
		'join_group': lambda life, **kwargs: groups.join_group(life, kwargs['group_id']),
		'add_group_member': lambda life, life_id: groups.add_member(life, life['group'], life_id),
		'claim_to_be_group_leader': lambda life, life_id: groups.set_leader(life, life['group'], life['id']),
		'is_group_leader': lambda life: groups.is_leader_of_any_group(life)==True,
		'is_in_same_group': lambda life, life_id: (life['group'] and LIFE[life_id]['group'] == life['group'])>0,
		'is_target_group_leader': lambda life, life_id: (groups.is_leader_of_any_group(LIFE[life_id]))==True,
		'is_in_group': lambda life: life['group']>0,
		'is_target_hostile': lambda life, life_id: brain.knows_alife_by_id(life, life_id) and brain.knows_alife_by_id(life, life_id)['alignment'] == 'hostile',
		'is_target_in_group': lambda life, life_id, **kwargs: brain.knows_alife_by_id(life, life_id) and brain.knows_alife_by_id(life, life_id)['group']==kwargs['group'],
		'is_target_in_any_group': lambda life, life_id: brain.knows_alife_by_id(life, life_id) and brain.knows_alife_by_id(life, life_id)['group']>0,
		'is_target_group_friendly': lambda life, life_id: brain.knows_alife_by_id(life, life_id) and brain.knows_alife_by_id(life, life_id)['group'] and groups.get_group_memory(life, brain.knows_alife_by_id(life, life_id)['group'], 'alignment')=='trust',
		'is_target_group_hostile': groups.is_target_group_hostile,
		'is_target_group_neutral': lambda life, life_id: brain.knows_alife_by_id(life, life_id) and brain.knows_alife_by_id(life, life_id)['group'] and groups.get_group_memory(life, brain.knows_alife_by_id(life, life_id)['group'], 'alignment')=='neutral',
		'is_group_hostile': lambda life, **kwargs: groups.get_group_memory(life, kwargs['group_id'], 'alignment')=='hostile',
		'is_injured': lambda life: len(lfe.get_cut_limbs(life)) or len(lfe.get_bleeding_limbs(life)),
		'inform_of_group_members': speech.inform_of_group_members,
		'update_group_members': speech.update_group_members,
		'get_group_flag': groups.get_flag,
		'get_flag': brain.get_flag,
		'get_group': lambda life: life['group'],
		'discover_group': lambda life, **kwargs: groups.discover_group(life, kwargs['group_id']),
		'add_target_to_known_group': lambda life, life_id, **kwargs: groups.add_member(life, kwargs['group_id'], life_id),
		'knows_about_group': lambda life, **kwargs: groups.group_exists(life, kwargs['group_id']),
		'group_has_shelter': lambda life: groups.get_shelter(life, life['group'])>0,
		'declare_group_hostile': lambda life, **kwargs: stats.declare_group_hostile(life, kwargs['group_id']),
		'declare_group_trusted': lambda life, **kwargs: stats.declare_group_trusted(life, kwargs['group_id']),
		'declare_group_target': lambda life, life_id: stats.declare_group_target(life, life_id, 'hostile'),
		'get_group_shelter': lambda life: groups.get_shelter(life, life['group']),
		'set_group_shelter': lambda life, **kwargs: groups.set_shelter(life, kwargs['group_id'], kwargs['shelter']),
		'get_group_stage': lambda life: groups.get_stage(life, life['group']),
		'get_group_stage_message': speech.get_group_stage_message,
		'set_group_stage': lambda life, **kwargs: groups.set_stage(life, kwargs['group_id'], kwargs['stage']),
		'is_group_motivated_for_crime': lambda life: life['group'] and groups.get_motive(life, life['group']) == 'crime',
		'wants_to_leave_group_for_group': lambda life: stats.wants_to_abandon_group(life, life['group']),
		'knows_items_matching': lambda life, **kwargs: len(brain.get_multi_matching_remembered_items(life, kwargs['items'], no_owner=True))>0,
		'get_known_group': speech.get_known_group,
		'inform_of_group': speech.inform_of_group,
		'force_inform_of_group': speech.force_inform_of_group,
		'inform_of_items': lambda life, life_id, **kwargs: speech.inform_of_items(life, life_id, kwargs['items']),
		'update_location': lambda life, life_id: brain.update_known_life(life, life_id, 'last_seen_at', LIFE[life_id]['pos'][:]),
		'has_questions_for_target': lambda life, life_id: len(memory.get_questions_for_target(life, life_id))>0,
		'has_orders_for_target': lambda life, life_id: len(memory.get_orders_for_target(life, life_id))>0,
		'ask_target_question': memory.ask_target_question,
		'give_target_order_message': memory.give_target_order_message,
		'give_target_order': memory.give_target_order,
		'take_order': memory.take_order,
		'reject_order': memory.reject_order,
		'get_introduction_message': speech.get_introduction_message,
		'get_introduction_gist': speech.get_introduction_gist,
		'establish_trust': stats.establish_trust,
		'establish_feign_trust': stats.establish_feign_trust,
		'establish_aggressive': stats.establish_aggressive,
		'establish_hostile': stats.establish_hostile,
		'establish_scared': stats.establish_scared,
		'claim_hostile': lambda life, target, **kwargs: stats.establish_hostile(life, kwargs['target_id']),
		'describe_target': lambda life, life_id, **kwargs: speech.describe_target(life, kwargs['target']),
		'consume': lfe.consume,
		'explode': items.explode,
		'is_player': lambda life: 'player' in life,
		'is_neutral': lambda life, life_id: brain.knows_alife_by_id(life, life_id)['alignment'] == 'neutral',
		'reset_think_timer': lfe.reset_think_rate,
		'mark_target_as_combat_ready': lambda life, life_id: brain.flag_alife(life, life_id, 'combat_ready'),
		'mark_target_as_not_combat_ready': lambda life, life_id: brain.flag_alife(life, life_id, 'combat_ready', value=False),
		'saw_target_recently': lambda life, **kwargs: brain.knows_alife_by_id(life, kwargs['target_id']) and -1<brain.knows_alife_by_id(life, kwargs['target_id'])['last_seen_time']<6000,
		'update_location_of_target_from_target': speech.update_location_of_target_from_target,
		'ping': lambda life: logging.debug('%s: Ping!' % ' '.join(life['name'])),
		'wander': lambda life: alife_discover.tick(life),
		'pick_up_item': lambda life: alife_needs.tick(life),
		'take_shelter': lambda life: alife_shelter.tick(life),
		'has_non_relaxed_goal': lambda life: life['state_tier']>TIER_RELAXED,
		'needs_to_manage_inventory': lambda life: alife_manage_items.conditions(life) == True,
		'manage_inventory': lambda life: alife_manage_items.tick(life),
		'cover_exposed': lambda life: len(combat.get_exposed_positions(life))>0,
		'ranged_ready': lambda life: lfe.execute_raw(life, 'combat', 'ranged_ready'),
		'ranged_attack': lambda life: alife_combat.ranged_attack(life),
		'melee_ready': lambda life: lfe.execute_raw(life, 'combat', 'melee_ready'),
		'melee_attack': lambda life: alife_combat.melee_attack(life),
		'take_cover': lambda life: alife_cover.tick(life),
		'hide': lambda life: alife_escape.tick(life),
		'stop': lfe.stop,
		'search_for_threat': lambda life: alife_search.tick(life),
		'has_low_recoil': lambda life: life['recoil']>=.25,
		'has_medium_recoil': lambda life: life['recoil']>=.5,
		'has_high_recoil': lambda life: life['recoil']>=.75,
		'has_focus_point': lambda life: len(lfe.get_memory(life, matches={'text': 'focus_on_chunk'}))>0,
		'walk_to': lambda life: movement.travel_to_chunk(life, lfe.get_memory(life, matches={'text': 'focus_on_chunk'})[len(lfe.get_memory(life, matches={'text': 'focus_on_chunk'}))-1]['chunk_key']),
		'follow_target': alife_follow.tick,
		'guard_focus_point': lambda life: movement.guard_chunk(life, lfe.get_memory(life, matches={'text': 'focus_on_chunk'})[0]['chunk_key']),
		'disarm': lambda life, life_id: brain.flag_alife(life, life_id, 'disarm', value=WORLD_INFO['ticks']),
		'drop_weapon': lambda life: lfe.drop_item(life, lfe.get_held_items(life, matches={'type': 'gun'})[0]),
		'is_disarming': lambda life, life_id: brain.get_alife_flag(life, life_id, 'disarm')>0,
		'set_raid_location': lambda life, **kwargs: lfe.memory(life, 'focus_on_chunk', chunk_key=kwargs['chunk_key']),
		'move_to_chunk': lambda life, **kwargs:  movement.set_focus_point(life, kwargs['chunk_key']),
		'move_to_chunk_key': movement.set_focus_point,
		'recruiting': lambda life, life_id: speech.send(life, life_id, 'recruit'),
		'is_raiding': lambda life: life['group'] and groups.get_stage(life, life['group']) == STAGE_ATTACKING,
		'is_in_target_chunk': lambda life, target_id: lfe.get_current_chunk_id(life) == lfe.get_current_chunk_id(LIFE[target_id]),
		'get_chunk_key': lfe.get_current_chunk_id,
		'has_threat_in_combat_range': stats.has_threat_in_combat_range,
		'find_nearest_chunk_in_reference': references.find_nearest_chunk_key_in_reference_of_type,
		'has_item_type': lambda life, item_match: not lfe.get_inventory_item_matching(life, item_match) == None,
		'move_to_target': lambda life, target_id: movement.travel_to_position(life, LIFE[target_id]['pos']),
		'is_in_range_of_target': lambda life, target_id, distance: numbers.distance(life['pos'], LIFE[target_id]['pos'])<=int(distance),
		'track_target': lambda life, target_id: brain.meet_alife(life, LIFE[target_id]) and judgement.track_target(life, target_id),
		'untrack_target': judgement.untrack_target,
		'clear_tracking': lambda life: brain.flag(life, 'tracking_targets', []),
		'can_see_item': lambda life, item_uid: item_uid in life['seen_items'],
		'has_item': lambda life, item_uid: item_uid in life['inventory'],
		'pick_up_item': movement.pick_up_item,
		'create_mission': missions.create_mission_for_self,
		'give_mission': missions.create_mission_and_give,
		'do_mission': alife_work.tick,
		'has_mission': lambda life: len(life['missions'])>0,
		'drop_item': lfe.drop_item,
		'get_id': lambda life: life['id'],
		'always': lambda life: 1==1,
		'pass': lambda life, *a, **k: True,
		'never': lambda life: 1==2})
示例#26
0
def _has_inventory_item(life, matches={}):
    return lfe.get_all_inventory_items(life, matches=[matches])
示例#27
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']])