示例#1
0
def tick(life):
	if life['actions']:
		return True

	_needs_to_meet = brain.retrieve_from_memory(life, 'needs_to_meet')
	
	for need in _needs_to_meet:
		movement.collect_nearby_wanted_items(life, matches=need['match'], only_visible=False)
		break
	
	_needs_to_satisfy = brain.retrieve_from_memory(life, 'needs_to_satisfy')
	
	for need in _needs_to_satisfy:
		survival.satisfy(life, need)
示例#2
0
def tick(life):
    if not lfe.execute_raw(life, 'discover', 'discover_type'):
        _lost_method = lfe.execute_raw(life, 'discover', 'when_lost')
        if _lost_method:
            if not life['path'] or not brain.retrieve_from_memory(
                    life, 'discovery_lock'):
                if not 'scanned_chunks' in life['state_flags']:
                    life['state_flags']['scanned_chunks'] = []

                sight.scan_surroundings(
                    life,
                    _chunks=brain.get_flag(life, 'visible_chunks'),
                    ignore_chunks=life['state_flags']['scanned_chunks'])

                _explore_chunk = chunks.find_best_chunk(
                    life,
                    ignore_starting=True,
                    ignore_time=True,
                    lost_method=_lost_method,
                    only_recent=True)
                brain.store_in_memory(life, 'discovery_lock', True)
                brain.store_in_memory(life, 'explore_chunk', _explore_chunk)

                if not _explore_chunk:
                    brain.flag(life, 'lost')
                    return False

                survival.explore_known_chunks(life)
        else:
            return False
示例#3
0
def has_needs_to_satisfy(life):
    _needs = brain.retrieve_from_memory(life, "needs_to_satisfy")

    if _needs:
        return True

    return False
示例#4
0
def has_needs_to_satisfy(life):
    _needs = brain.retrieve_from_memory(life, 'needs_to_satisfy')

    if _needs:
        return True

    return False
示例#5
0
def tick(life):
    if life['actions']:
        return True

    _needs_to_meet = brain.retrieve_from_memory(life, 'needs_to_meet')

    for need in _needs_to_meet:
        movement.collect_nearby_wanted_items(life,
                                             matches=need['match'],
                                             only_visible=False)
        break

    _needs_to_satisfy = brain.retrieve_from_memory(life, 'needs_to_satisfy')

    for need in _needs_to_satisfy:
        survival.satisfy(life, need)
示例#6
0
def explore_known_chunks(life):
    # Our first order of business is to figure out exactly what we're looking for.
    # There's a big difference between exploring the map looking for a purpose and
    # exploring the map with a purpose. Both will use similar routines but I wager
    # it'll actually be a lot harder to do it without there being some kind of goal
    # to at least start us in the right direction.

    # This function will kick in only if the ALife is idling, so looting is handled
    # automatically.

    # Note: Determining whether this fuction should run at all needs to be done inside
    # the module itself.
    _chunk_key = brain.retrieve_from_memory(life, "explore_chunk")
    _chunk = maps.get_chunk(_chunk_key)

    if life["path"] and chunks.position_is_in_chunk(lfe.path_dest(life), _chunk_key):
        return True

    if chunks.is_in_chunk(life, "%s,%s" % (_chunk["pos"][0], _chunk["pos"][1])):
        life["known_chunks"][_chunk_key]["last_visited"] = WORLD_INFO["ticks"]
        return False

    if not _chunk["ground"]:
        return False

    _pos_in_chunk = random.choice(_chunk["ground"])
    lfe.clear_actions(life)
    lfe.add_action(life, {"action": "move", "to": _pos_in_chunk}, 200)
    return True
示例#7
0
def explore_known_chunks(life):
    #Our first order of business is to figure out exactly what we're looking for.
    #There's a big difference between exploring the map looking for a purpose and
    #exploring the map with a purpose. Both will use similar routines but I wager
    #it'll actually be a lot harder to do it without there being some kind of goal
    #to at least start us in the right direction.

    #This function will kick in only if the ALife is idling, so looting is handled
    #automatically.

    #Note: Determining whether this fuction should run at all needs to be done inside
    #the module itself.
    _chunk_key = brain.retrieve_from_memory(life, 'explore_chunk')
    _chunk = maps.get_chunk(_chunk_key)

    if life['path'] and chunks.position_is_in_chunk(lfe.path_dest(life),
                                                    _chunk_key):
        return True

    if chunks.is_in_chunk(life,
                          '%s,%s' % (_chunk['pos'][0], _chunk['pos'][1])):
        life['known_chunks'][_chunk_key]['last_visited'] = WORLD_INFO['ticks']
        return False

    if not _chunk['ground']:
        return False

    _pos_in_chunk = random.choice(_chunk['ground'])

    lfe.walk_to(life, _pos_in_chunk)

    return True
示例#8
0
def get_targets(life, escaped_only=False, ignore_escaped=True, limit_distance=-1, filter_func=None):
    return _target_filter(
        life,
        brain.retrieve_from_memory(life, "targets"),
        escaped_only,
        ignore_escaped,
        limit_distance=limit_distance,
        filter_func=filter_func,
    )
示例#9
0
def has_needs_to_meet(life):
    _needs = brain.retrieve_from_memory(life, "needs_to_meet")

    if not _needs:
        return False

    if len(_needs) > 0:
        return True

    return False
示例#10
0
def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	if brain.retrieve_from_memory(life, 'active_goals'):
		print 'ACTIVE GOAL' * 100
		goals.perform_goal(life, judgement.get_best_goal(life))
	else:
		#if jobs.alife_has_job(life):
		#	lfe.clear_actions(life)
		#	return True
		
		jobs.work(life)
示例#11
0
def has_needs_to_meet(life):
    _needs = brain.retrieve_from_memory(life, 'needs_to_meet')

    if not _needs:
        return False

    if len(_needs) > 0:
        return True

    return False
示例#12
0
文件: sight.py 项目: flags/Reactor-3
def find_known_items(life, matches={}, only_visible=True):
	_match = []
	
	_could_meet_with = []
	for need in brain.retrieve_from_memory(life, 'needs_to_meet'):
		_could_meet_with.extend(need['could_meet_with'])
	
	for item_uid in brain.get_matching_remembered_items(life, matches, no_owner=True, only_visible=only_visible):
		#TODO: Offload?
		_item = ITEMS[item_uid]
		
		_match.append(item_uid)
	
	return _match
示例#13
0
def get_ready_combat_targets(
    life, escaped_only=False, ignore_escaped=False, recent_only=False, limit_distance=-1, filter_func=None
):
    _targets = _target_filter(
        life,
        brain.retrieve_from_memory(life, "combat_targets"),
        escaped_only,
        ignore_escaped,
        recent_only=recent_only,
        limit_distance=limit_distance,
        filter_func=filter_func,
    )

    return [t for t in _targets if target_is_combat_ready(life, t)]
示例#14
0
def find_known_items(life, matches={}, only_visible=True):
    _match = []

    _could_meet_with = []
    for need in brain.retrieve_from_memory(life, 'needs_to_meet'):
        _could_meet_with.extend(need['could_meet_with'])

    for item_uid in brain.get_matching_remembered_items(
            life, matches, no_owner=True, only_visible=only_visible):
        #TODO: Offload?
        _item = ITEMS[item_uid]

        _match.append(item_uid)

    return _match
示例#15
0
def get_threats(
    life,
    escaped_only=False,
    ignore_lost=True,
    ignore_escaped=True,
    recent_only=False,
    limit_distance=-1,
    filter_func=None,
):
    return _target_filter(
        life,
        brain.retrieve_from_memory(life, "threats"),
        escaped_only,
        ignore_escaped,
        ignore_lost=ignore_lost,
        recent_only=recent_only,
        limit_distance=limit_distance,
        filter_func=filter_func,
    )
示例#16
0
def tick(life):
	if not lfe.execute_raw(life, 'discover', 'discover_type'):
		_lost_method = lfe.execute_raw(life, 'discover', 'when_lost')
		if _lost_method:
			if not life['path'] or not brain.retrieve_from_memory(life, 'discovery_lock'):
				if not 'scanned_chunks' in life['state_flags']:
					life['state_flags']['scanned_chunks'] = []

				sight.scan_surroundings(life, _chunks=brain.get_flag(life, 'visible_chunks'), ignore_chunks=life['state_flags']['scanned_chunks'])
				
				_explore_chunk = chunks.find_best_chunk(life, ignore_starting=True, ignore_time=True, lost_method=_lost_method, only_recent=True)
				brain.store_in_memory(life, 'discovery_lock', True)
				brain.store_in_memory(life, 'explore_chunk', _explore_chunk)
				
				if not _explore_chunk:
					brain.flag(life, 'lost')
					return False
				
				survival.explore_known_chunks(life)
		else:
			return False
示例#17
0
def get_combat_targets(life, escaped_only=False, ignore_escaped=False, ignore_lost=True, recent_only=False, limit_distance=-1, filter_func=None):
	return _target_filter(life, brain.retrieve_from_memory(life, 'combat_targets'), escaped_only, ignore_escaped, recent_only=recent_only, ignore_lost=ignore_lost, limit_distance=limit_distance, filter_func=filter_func)
示例#18
0
def has_unmet_needs(life):
    if len(brain.retrieve_from_memory(life, 'needs_unmet')) > 0:
        return True

    return False
示例#19
0
def get_threats(life, escaped_only=False, ignore_lost=True, ignore_escaped=True, recent_only=False, limit_distance=-1, filter_func=None):
	return _target_filter(life, brain.retrieve_from_memory(life, 'threats'), escaped_only, ignore_escaped, ignore_lost=ignore_lost, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func)
示例#20
0
def get_ready_combat_targets(life, escaped_only=False, ignore_escaped=False, recent_only=False, limit_distance=-1, filter_func=None):
	_targets = _target_filter(life, brain.retrieve_from_memory(life, 'combat_targets'), escaped_only, ignore_escaped, recent_only=recent_only, limit_distance=limit_distance, filter_func=filter_func)
	
	return [t for t in _targets if target_is_combat_ready(life, t)]
示例#21
0
def get_best_goal(life):
	for goal in brain.retrieve_from_memory(life, 'active_goals'):
		return goal
	
	return -1
示例#22
0
def get_tension(life):
    return brain.retrieve_from_memory(life, "tension")
示例#23
0
def get_best_goal(life):
    for goal in brain.retrieve_from_memory(life, "active_goals"):
        return goal

    return -1
示例#24
0
def has_unmet_needs(life):
    if len(brain.retrieve_from_memory(life, "needs_unmet")) > 0:
        return True

    return False
示例#25
0
def get_tension(life):
	return brain.retrieve_from_memory(life, 'tension')