def find_nearest_key_in_reference(life, reference_id, unknown=False, ignore_current=False, threshold=-1): _lowest = {'chunk_key': None, 'distance': 9000} #Dirty hack here... #We can use the list of visible chunks to find the nearest key in the reference #This is actually SLOWER if the NPC can't see any keys in the reference and a search #has to be done (the way we're doing it now.) _reference = get_reference(reference_id) for _key in _reference: if unknown and _key in life['known_chunks']: continue if ignore_current and lfe.get_current_chunk_id(life) == _key: print 'ignoring current' continue if not maps.get_chunk(_key)['ground']: continue _center = [int(val)+(WORLD_INFO['chunk_size']/2) for val in _key.split(',')] _distance = numbers.distance(life['pos'], _center) if not _lowest['chunk_key'] or _distance<_lowest['distance']: _lowest['distance'] = _distance _lowest['chunk_key'] = _key if threshold > -1 and _lowest['distance'] <= threshold: break return _lowest['chunk_key']
def order_spread_out(life, group_id, chunk_keys, filter_by=None): _group = get_group(life, group_id) _ordered_targets = [] for life_id in _group['members']: if not filter_by(life_id): continue if life_id == life['id']: movement.set_focus_point(life, random.choice(chunk_keys)) continue _ordered_targets.append(life_id) if lfe.get_current_chunk_id(LIFE[life_id]) in chunk_keys: speech.start_dialog(life, life_id, 'order_wait_%s' % get_group_size(life, group_id), remote=True) else: speech.start_dialog(life, life_id, 'order_move_to_chunk', chunk_key=random.choice(chunk_keys), remote=True) return _ordered_targets
def control_zes(): _zes = get_faction('ZES') if not 'intro_created' in _zes['flags'] and _zes['members'] and SETTINGS['controlling']: _zes = get_faction('ZES') _zes['flags']['intro_created'] = True _item_uid = weapons.spawn_and_arm('glock', '9x19mm magazine', '9x19mm round', 17) _kill_target = get_faction('Bandits')['members'][0] _kill_target_direction = bad_numbers.distance(LIFE[_zes['members'][0]]['pos'], LIFE[_kill_target]['pos']) _quest_item_uid = lfe.get_inventory_item_matching(LIFE[_kill_target], {'type': 'radio'}) _mission = missions.create_mission('zes_glock', target=SETTINGS['controlling'], item_uid=_item_uid, quest_item_uid=_quest_item_uid, deliver_target=_zes['members'][0], kill_target=_kill_target, location=lfe.get_current_chunk_id(LIFE[_kill_target])) lfe.add_item_to_inventory(LIFE[_zes['members'][0]], _item_uid) alife.brain.meet_alife(LIFE[_zes['members'][0]], LIFE[SETTINGS['controlling']]) alife.memory.create_question(LIFE[_zes['members'][0]], SETTINGS['controlling'], 'zes_intro', kill_target_name=' '.join(LIFE[_kill_target]['name']), kill_target_direction=language.get_real_direction(_kill_target_direction)) missions.remember_mission(LIFE[_zes['members'][0]], _mission) missions.activate_mission(LIFE[_zes['members'][0]], '1')
def control_zes(): _zes = get_faction('ZES') if not 'intro_created' in _zes['flags'] and _zes['members'] and SETTINGS['controlling']: _zes = get_faction('ZES') _zes['flags']['intro_created'] = True _item_uid = weapons.spawn_and_arm('glock', '9x19mm magazine', '9x19mm round', 17) _kill_target = get_faction('Bandits')['members'][0] _kill_target_direction = numbers.distance(LIFE[_zes['members'][0]]['pos'], LIFE[_kill_target]['pos']) _quest_item_uid = lfe.get_inventory_item_matching(LIFE[_kill_target], {'type': 'radio'}) _mission = missions.create_mission('zes_glock', target=SETTINGS['controlling'], item_uid=_item_uid, quest_item_uid=_quest_item_uid, deliver_target=_zes['members'][0], kill_target=_kill_target, location=lfe.get_current_chunk_id(LIFE[_kill_target])) lfe.add_item_to_inventory(LIFE[_zes['members'][0]], _item_uid) alife.brain.meet_alife(LIFE[_zes['members'][0]], LIFE[SETTINGS['controlling']]) alife.memory.create_question(LIFE[_zes['members'][0]], SETTINGS['controlling'], 'zes_intro', kill_target_name=' '.join(LIFE[_kill_target]['name']), kill_target_direction=language.get_real_direction(_kill_target_direction)) missions.remember_mission(LIFE[_zes['members'][0]], _mission) missions.activate_mission(LIFE[_zes['members'][0]], '1')
def tick_fields(): for territory in get_active_fields(): _spawn_chunk_keys = [k for k in territory['chunk_keys'] if WORLD_INFO['chunk_map'][k]['type'] == 'other'] if not 'create' in territory['flags'] or not territory['flags']['create']: if 'first_run' in territory['flags']: territory['flags']['create'] = random.randint(50, 60) else: territory['flags']['create'] = random.randint(150, 180) territory['flags']['first_run'] = True if SETTINGS['controlling'] and life.get_current_chunk_id(LIFE[SETTINGS['controlling']]) in _spawn_chunk_keys: gfx.message('The ground begins to shake...', style='alert') continue else: territory['flags']['create'] -= 1 continue create_burner(_spawn_chunk_keys.pop(random.randint(0, len(_spawn_chunk_keys)-1))) territory['flags']['create_amount'] -= 1 if not territory['flags']['create_amount']: territory['danger'] = None territory['flags']['create_amount'] = 0 del territory['flags']['first_run']
def draw_chunk_map(life=None, show_faction_ownership=False): _x_min = numbers.clip(CAMERA_POS[0]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size']) _y_min = numbers.clip(CAMERA_POS[1]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size']) _x_max = numbers.clip(_x_min+WINDOW_SIZE[0], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size']) _y_max = numbers.clip(_y_min+WINDOW_SIZE[1], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size']) _life_chunk_key = None if life: _life_chunk_key = lfe.get_current_chunk_id(life) for x in range(_x_min, _x_max): _d_x = x-(CAMERA_POS[0]/WORLD_INFO['chunk_size']) if 0>_d_x >= WINDOW_SIZE[0]: continue for y in range(_y_min, _y_max): _d_y = y-(CAMERA_POS[1]/WORLD_INFO['chunk_size']) _draw = True _fore_color = tcod.darker_gray _back_color = tcod.darkest_gray if 0>_d_y >= WINDOW_SIZE[1]: continue _chunk_key = '%s,%s' % (x*WORLD_INFO['chunk_size'], y*WORLD_INFO['chunk_size']) if life: if not _chunk_key in life['known_chunks']: _draw = False if _draw: _type = WORLD_INFO['chunk_map'][_chunk_key]['type'] _char = 'x' if _type in ['building', 'town']: _fore_color = tcod.light_gray _char = 'B' elif _type in ['outpost', 'factory']: _fore_color = tcod.desaturated_green _back_color = tcod.desaturated_han _char = 'M' elif _type == 'field': _fore_color = tcod.yellow elif _type == 'forest': _fore_color = tcod.dark_green elif _type in ['road', 'driveway']: _fore_color = tcod.white _back_color = tcod.black _char = '.' if _chunk_key == _life_chunk_key and time.time()%1>=.5: _fore_color = tcod.white _char = 'X' gfx.blit_char_to_view(_d_x, _d_y, _char, (_fore_color, _back_color), 'chunk_map') else: gfx.blit_char_to_view(_d_x, _d_y, 'x', (tcod.darker_gray, tcod.darkest_gray), 'chunk_map')
def get_jobs(life, group_id): _group = get_group(life, group_id) _jobs = [] _leader = LIFE[_group['leader']] if not has_camp(group_id): _nearest_camp = camps.get_nearest_known_camp(_leader) if _leader['known_camps']: _j = jobs.create_job(_leader, 'Raid', gist='start_raid', description='Raid camp %s.' % _nearest_camp['id']) _pos = lfe.get_current_chunk(_leader)['pos'] _chunk_key = lfe.get_current_chunk_id(_leader) jobs.add_task(_j, '0', 'announce_to_group', action.make_small_script(function='announce_to_group', kwargs={'group_id': group_id, 'gist': 'announce_group_job', 'message': jobs.get_job(_j)['description'], 'job_id': _j}), player_action=action.make_small_script(function='always'), description='Gather group members.') jobs.add_task(_j, '1', 'move_to_chunk', action.make_small_script(function='travel_to_position', kwargs={'pos': _pos}), player_action=action.make_small_script(function='is_in_chunk', kwargs={'chunk_key': _chunk_key}), description='Travel to position %s, %s' % (_pos[0], _pos[1]), delete_on_finish=False) jobs.add_task(_j, '2', 'wait_for_number_of_group_members_in_chunk', action.make_small_script(function='number_of_alife_in_chunk_matching', kwargs={'amount': 2, 'chunk_key': _chunk_key, 'matching': {'group': _leader['group']}}), description='Wait until everyone arrives.') #jobs.add_task(_j, '3', 'talk', # action.make_small_script(function='travel_to_position', # kwargs={'pos': chunks.get_nearest_chunk_in_list(_leader['pos'], camps.get_camp(_nearest_camp['id'])['reference'])}), # requires=['1'], # delete_on_finish=False) _jobs.append(_j) if len(_leader['known_groups'])>1: _lowest = {'score': 0, 'group': None} for group_id in [g for g in _leader['known_groups'] if not g==_leader['group']]: _score = judgement.judge_group(_leader, group_id) if not _lowest['group'] or _score < _lowest['score']: _lowest['score'] = _score _lowest['group'] = group_id print 'RAID', _lowest else: print 'ony one' return _jobs
def find_nearest_key_in_reference(life, reference_id, unknown=False, ignore_current=False, threshold=-1): _lowest = {"chunk_key": None, "distance": 9000} for _key in get_reference(reference_id): if unknown and _key in life["known_chunks"]: continue if ignore_current and lfe.get_current_chunk_id(life) == _key: print "ignoring current" if not maps.get_chunk(_key)["ground"]: continue _center = [int(val) + (WORLD_INFO["chunk_size"] / 2) for val in _key.split(",")] _distance = numbers.distance(life["pos"], _center) if not _lowest["chunk_key"] or _distance < _lowest["distance"]: _lowest["distance"] = _distance _lowest["chunk_key"] = _key if threshold > -1 and _lowest["distance"] <= threshold: break return _lowest["chunk_key"]
def find_best_chunk(life, ignore_starting=False, ignore_time=False, lost_method=None, only_unvisted=False, only_unseen=False, only_recent=False): _interesting_chunks = {} for chunk_key in life['known_chunks']: _chunk = life['known_chunks'][chunk_key] if not ignore_time and (_chunk['last_visited'] == -1 or time.time()-_chunk['last_visited']<=400): if only_unvisted and not _chunk['last_visited'] == -1: continue if only_unseen and not _chunk['last_seen'] == -1: continue _interesting_chunks[chunk_key] = life['known_chunks'][chunk_key] elif ignore_time: if only_unvisted and not _chunk['last_visited'] == -1: continue if only_unseen and not _chunk['last_seen'] == -1: continue _interesting_chunks[chunk_key] = life['known_chunks'][chunk_key] if not ignore_starting: _current_known_chunk = lfe.get_current_known_chunk(life) _initial_score = _current_known_chunk['score'] else: _current_known_chunk = None _initial_score = 0 if only_recent: _recent = -1 for chunk_key in _interesting_chunks.keys(): chunk = _interesting_chunks[chunk_key] if chunk['discovered_at']>_recent: _recent = chunk['discovered_at'] _best_chunk = {'score': _initial_score, 'chunk_key': lfe.get_current_chunk_id(life)} for chunk_key in _interesting_chunks: chunk = _interesting_chunks[chunk_key] _score = chunk['score'] if only_recent: if chunk['discovered_at']<_recent: continue if lost_method == 'furthest': chunk_center = [int(val)+(WORLD_INFO['chunk_size']/2) for val in chunk_key.split(',')] _score = numbers.distance(life['pos'], chunk_center) if ignore_starting and chunk_key == lfe.get_current_chunk_id(life): continue if _score>_best_chunk['score']: _best_chunk['score'] = _score _best_chunk['chunk_key'] = chunk_key if not _best_chunk['chunk_key'] or not _best_chunk['score']: return False return _best_chunk['chunk_key']
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})
def look(life): if not 'CAN_SEE' in life['life_flags']: return False for target_id in life['know']: if life['know'][target_id]['last_seen_time']: life['know'][target_id]['last_seen_time'] += 1 life['know'][target_id]['time_visible'] = 0 else: life['know'][target_id]['time_visible'] += 1 if 'player' in life: if life['path'] or not brain.get_flag(life, 'visible_chunks'): if SETTINGS['smp']: _visible_chunks = post_scan_surroundings(life) else: _visible_chunks = scan_surroundings(life, judge=False, get_chunks=True, ignore_chunks=0) _chunks = [maps.get_chunk(c) for c in _visible_chunks] brain.flag(life, 'visible_chunks', value=_visible_chunks) elif 'player' in life: _visible_chunks = brain.get_flag(life, 'visible_chunks') _chunks = [maps.get_chunk(c) for c in _visible_chunks] else: #This is for optimizing. Be careful if you mess with this... _nearby_alife = {} for alife in LIFE.values(): if alife['id'] == life['id']: continue if bad_numbers.distance(life['pos'], alife['pos'])<=get_vision(life) and can_see_position(life, alife['pos']): _nearby_alife[alife['id']] = {'pos': alife['pos'][:], 'stance': alife['stance']} _last_nearby_alife = brain.get_flag(life, '_nearby_alife') if not _last_nearby_alife == _nearby_alife: brain.flag(life, '_nearby_alife', value=_nearby_alife) else: for target_id in life['seen']: if life['know'][target_id]['last_seen_time']: life['know'][target_id]['last_seen_time'] = 0 return False _chunks = [maps.get_chunk(c) for c in brain.get_flag(life, 'visible_chunks')] life['seen'] = [] life['seen_items'] = [] for item_uid in life['know_items']: life['know_items'][item_uid]['last_seen_time'] += 1 for target_id in life['know']: life['know'][target_id]['last_seen_time'] += 1 if life['know'][target_id]['last_seen_time']>=10 and not life['know'][target_id]['escaped']: life['know'][target_id]['escaped'] = 1 if not 'player' in life: quick_look(life) return False for chunk in _chunks: judgement.judge_chunk_visually(life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1])) judgement.judge_chunk_life(life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1])) for ai in [LIFE[i] for i in chunk['life']]: if ai['id'] == life['id']: continue if not is_in_fov(life, ai['pos']): if ai['id'] in life['know']: life['know'][ai['id']]['time_visible'] = 0 continue if not ai['id'] in life['know']: brain.meet_alife(life, ai) _visibility = get_visiblity_of_position(life, ai['pos']) _stealth_coverage = get_stealth_coverage(ai) if _visibility < 1-_stealth_coverage: continue life['seen'].append(ai['id']) if life['think_rate'] == life['think_rate_max']: lfe.create_and_update_self_snapshot(LIFE[ai['id']]) judgement.judge_life(life, ai['id']) if ai['dead']: if 'player' in life and not life['know'][ai['id']]['dead'] and life['know'][ai['id']]['last_seen_time']>25: logic.show_event('You discover the body of %s.' % ' '.join(ai['name']), life=ai) if life['know'][ai['id']]['group']: groups.remove_member(life, life['know'][ai['id']]['group'], ai['id']) life['know'][ai['id']]['group'] = None core.record_loss(1) life['know'][ai['id']]['dead'] = True elif ai['asleep']: life['know'][ai['id']]['asleep'] = True elif not ai['asleep']: life['know'][ai['id']]['asleep'] = False life['know'][ai['id']]['last_seen_time'] = 0 life['know'][ai['id']]['last_seen_at'] = ai['pos'][:] life['know'][ai['id']]['escaped'] = False life['know'][ai['id']]['state'] = ai['state'] life['know'][ai['id']]['state_tier'] = ai['state_tier'] if brain.alife_has_flag(life, ai['id'], 'search_map'): brain.unflag_alife(life, ai['id'], 'search_map') _chunk_id = lfe.get_current_chunk_id(ai) judgement.judge_chunk(life, _chunk_id, seen=True) for item in [ITEMS[i] for i in chunk['items'] if i in ITEMS]: if not is_in_fov(life, item['pos']): continue if not item['uid'] in life['know_items']: brain.remember_item(life, item) if items.is_item_owned(item['uid']): #TODO: This doesn't work because we are specifically checking chunks if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']): life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos'] life['know_items'][item['uid']]['last_owned_by'] = item['owner'] life['know_items'][item['uid']]['last_seen_time'] = 0 continue life['seen_items'].append(item['uid']) life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:] life['know_items'][item['uid']]['last_seen_time'] = 0 life['know_items'][item['uid']]['last_owned_by'] = None life['know_items'][item['uid']]['score'] = judgement.judge_item(life, item['uid']) life['know_items'][item['uid']]['lost'] = False
def quick_look(life): _life = [] _items = [] _current_chunk = lfe.get_current_chunk_id(life) _current_chunk_pos = chunks.get_chunk(_current_chunk)['pos'] _x_chunk_min = bad_numbers.clip(_current_chunk_pos[0]-((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[0]-WORLD_INFO['chunk_size']) _y_chunk_min = bad_numbers.clip(_current_chunk_pos[1]-((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[1]-WORLD_INFO['chunk_size']) _x_chunk_max = bad_numbers.clip(_current_chunk_pos[0]+((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[0]-WORLD_INFO['chunk_size']) _y_chunk_max = bad_numbers.clip(_current_chunk_pos[1]+((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[1]-WORLD_INFO['chunk_size']) _has_ready_weapon = combat.has_ready_weapon(life) for y in range(_y_chunk_min, _y_chunk_max, WORLD_INFO['chunk_size']): for x in range(_x_chunk_min, _x_chunk_max, WORLD_INFO['chunk_size']): _chunk_key = '%s,%s' % (x, y) _chunk = chunks.get_chunk(_chunk_key) for life_id in _chunk['life']: ai = LIFE[life_id] if ai['dead']: continue if life_id == life['id']: continue if not can_see_position(life, LIFE[life_id]['pos']): continue _visibility = get_visiblity_of_position(life, ai['pos']) _stealth_coverage = get_stealth_coverage(ai) if _visibility < 1-_stealth_coverage: continue if not ai['id'] in life['know']: brain.meet_alife(life, ai) life['seen'].append(ai['id']) if life['think_rate'] == life['think_rate_max']: lfe.create_and_update_self_snapshot(LIFE[ai['id']]) judgement.judge_life(life, ai['id']) if ai['dead']: if life['know'][ai['id']]['group']: groups.remove_member(life, life['know'][ai['id']]['group'], ai['id']) life['know'][ai['id']]['group'] = None life['know'][ai['id']]['dead'] = True elif ai['asleep']: life['know'][ai['id']]['asleep'] = True elif not ai['asleep']: life['know'][ai['id']]['asleep'] = False life['know'][ai['id']]['last_seen_time'] = 0 life['know'][ai['id']]['last_seen_at'] = ai['pos'][:] life['know'][ai['id']]['escaped'] = False life['know'][ai['id']]['state'] = ai['state'] life['know'][ai['id']]['state_tier'] = ai['state_tier'] if brain.alife_has_flag(life, ai['id'], 'search_map'): brain.unflag_alife(life, ai['id'], 'search_map') _chunk_id = lfe.get_current_chunk_id(ai) judgement.judge_chunk(life, _chunk_id, seen=True) _life.append(life_id) for item_uid in _chunk['items']: if not item_uid in ITEMS: continue item = ITEMS[item_uid] if not item['uid'] in life['know_items']: brain.remember_item(life, item) if items.is_item_owned(item['uid']): continue # #TODO: This doesn't work because we are specifically checking chunks # if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']): # life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos'] # life['know_items'][item['uid']]['last_owned_by'] = item['owner'] # life['know_items'][item['uid']]['last_seen_time'] = 0 # # continue if not can_see_position(life, item['pos']): continue if not item['uid'] in life['know_items']: brain.remember_item(life, item) life['seen_items'].append(item['uid']) life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:] life['know_items'][item['uid']]['last_seen_time'] = 0 life['know_items'][item['uid']]['last_owned_by'] = None life['know_items'][item['uid']]['score'] = judgement.judge_item(life, item['uid']) life['know_items'][item['uid']]['lost'] = False _items.append(item_uid)
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, } )
def quick_look(life): _life = [] _items = [] _current_chunk = lfe.get_current_chunk_id(life) _current_chunk_pos = chunks.get_chunk(_current_chunk)['pos'] _x_chunk_min = bad_numbers.clip( _current_chunk_pos[0] - ((get_vision(life) / WORLD_INFO['chunk_size']) * WORLD_INFO['chunk_size']), 0, MAP_SIZE[0] - WORLD_INFO['chunk_size']) _y_chunk_min = bad_numbers.clip( _current_chunk_pos[1] - ((get_vision(life) / WORLD_INFO['chunk_size']) * WORLD_INFO['chunk_size']), 0, MAP_SIZE[1] - WORLD_INFO['chunk_size']) _x_chunk_max = bad_numbers.clip( _current_chunk_pos[0] + ((get_vision(life) / WORLD_INFO['chunk_size']) * WORLD_INFO['chunk_size']), 0, MAP_SIZE[0] - WORLD_INFO['chunk_size']) _y_chunk_max = bad_numbers.clip( _current_chunk_pos[1] + ((get_vision(life) / WORLD_INFO['chunk_size']) * WORLD_INFO['chunk_size']), 0, MAP_SIZE[1] - WORLD_INFO['chunk_size']) _has_ready_weapon = combat.has_ready_weapon(life) for y in range(_y_chunk_min, _y_chunk_max, WORLD_INFO['chunk_size']): for x in range(_x_chunk_min, _x_chunk_max, WORLD_INFO['chunk_size']): _chunk_key = '%s,%s' % (x, y) _chunk = chunks.get_chunk(_chunk_key) for life_id in _chunk['life']: ai = LIFE[life_id] if ai['dead']: continue if life_id == life['id']: continue if not can_see_position(life, LIFE[life_id]['pos']): continue _visibility = get_visiblity_of_position(life, ai['pos']) _stealth_coverage = get_stealth_coverage(ai) if _visibility < 1 - _stealth_coverage: continue if not ai['id'] in life['know']: brain.meet_alife(life, ai) life['seen'].append(ai['id']) if life['think_rate'] == life['think_rate_max']: lfe.create_and_update_self_snapshot(LIFE[ai['id']]) judgement.judge_life(life, ai['id']) if ai['dead']: if life['know'][ai['id']]['group']: groups.remove_member(life, life['know'][ai['id']]['group'], ai['id']) life['know'][ai['id']]['group'] = None life['know'][ai['id']]['dead'] = True elif ai['asleep']: life['know'][ai['id']]['asleep'] = True elif not ai['asleep']: life['know'][ai['id']]['asleep'] = False life['know'][ai['id']]['last_seen_time'] = 0 life['know'][ai['id']]['last_seen_at'] = ai['pos'][:] life['know'][ai['id']]['escaped'] = False life['know'][ai['id']]['state'] = ai['state'] life['know'][ai['id']]['state_tier'] = ai['state_tier'] if brain.alife_has_flag(life, ai['id'], 'search_map'): brain.unflag_alife(life, ai['id'], 'search_map') _chunk_id = lfe.get_current_chunk_id(ai) judgement.judge_chunk(life, _chunk_id, seen=True) _life.append(life_id) for item_uid in _chunk['items']: if not item_uid in ITEMS: continue item = ITEMS[item_uid] if not item['uid'] in life['know_items']: brain.remember_item(life, item) if items.is_item_owned(item['uid']): continue # #TODO: This doesn't work because we are specifically checking chunks # if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']): # life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos'] # life['know_items'][item['uid']]['last_owned_by'] = item['owner'] # life['know_items'][item['uid']]['last_seen_time'] = 0 # # continue if not can_see_position(life, item['pos']): continue if not item['uid'] in life['know_items']: brain.remember_item(life, item) life['seen_items'].append(item['uid']) life['know_items'][ item['uid']]['last_seen_at'] = item['pos'][:] life['know_items'][item['uid']]['last_seen_time'] = 0 life['know_items'][item['uid']]['last_owned_by'] = None life['know_items'][ item['uid']]['score'] = judgement.judge_item( life, item['uid']) life['know_items'][item['uid']]['lost'] = False _items.append(item_uid)
def form_scheme(force=False): print WORLD_INFO['next_scheme_timer'] if WORLD_INFO['next_scheme_timer']: WORLD_INFO['next_scheme_timer'] -= 1 return False if (WORLD_INFO['scheme'] and not force) or not SETTINGS['controlling']: return False _overwatch_mood = WORLD_INFO['overwatch']['mood'] _player = LIFE[SETTINGS['controlling']] _player_situation = core.get_player_situation() _event_names = [] if _player_situation['active_factions']: if not _player_situation['active_factions'] == [ 'ZES' ] and not random.randint(0, (len(artifacts.get_active_fields()) + 1) * 3): _event_names.append('anomaly') _event_names.append('capture') if not random.randint(0, 8): _event_names.append('resupply') if not random.randint(0, 4): _event_names.append('attract') if not _event_names: WORLD_INFO['next_scheme_timer'] = 50 return False _event_name = random.choice(_event_names) print _event_name if _event_name == 'attract': if _player_situation['enemy_factions'] and not _player_situation[ 'friendly_factions']: for enemy_faction in _player_situation['enemy_factions']: for enemy_of_enemy_faction in alife.factions.get_faction_enemies( enemy_faction): _nearest_group = alife.factions.get_nearest_group( enemy_of_enemy_faction, _player['pos']) if not _nearest_group: continue alife.factions.move_group_to( enemy_of_enemy_faction, _nearest_group, lfe.get_current_chunk_id(_player)) WORLD_INFO['next_scheme_timer'] = 250 elif _event_name == 'capture': _chosen_faction = random.choice(_player_situation['active_factions']) _chosen_group = random.choice( alife.factions.get_faction(_chosen_faction)['groups']) alife.factions.capture_territory(_chosen_faction, _chosen_group) WORLD_INFO['next_scheme_timer'] = 350 elif _event_name == 'resupply': _chunk_key = random.choice( WORLD_INFO['territories'][artifacts.find_territory( y_min=.5)]['chunk_keys']) _pos = WORLD_INFO['chunk_map'][_chunk_key]['pos'] _storage_items = [{ 'item': 'AK-74', 'rarity': 1.0 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm round', 'rarity': 0.6 }, { 'item': '5.45x39mm magazine', 'rarity': 1.0 }] _storage = [{ 'item': 'military crate', 'rarity': 1.0, 'spawn_list': _storage_items }] for faction_name in WORLD_INFO['factions']: if faction_name == 'ZES': continue _faction = WORLD_INFO['factions'][faction_name] for group_id in _faction['groups']: if not random.randint(0, 3): continue #alife.factions.move_group_to(faction_name, group_id, _chunk_key) alife.factions.resupply(faction_name, group_id, _chunk_key) events.create_cache_drop(_pos, _storage) WORLD_INFO['next_scheme_timer'] = 350 elif _event_name == 'anomaly': _territory_id = events.create_anomaly_field(_player_situation, y_min=.65) for faction_name in _player_situation['active_factions']: if faction_name == 'ZES': continue _faction = WORLD_INFO['factions'][faction_name] for group_id in _faction['groups']: if random.randint(0, 1): continue _chunk_key = random.choice( WORLD_INFO['territories'][_territory_id]['chunk_keys']) maps.load_cluster_at_position_if_needed( WORLD_INFO['chunk_map'][_chunk_key]['pos']) alife.factions.move_group_to(faction_name, group_id, _chunk_key) WORLD_INFO['next_scheme_timer'] = 350
def form_scheme(force=False): if (WORLD_INFO['scheme'] or (WORLD_INFO['ticks']-WORLD_INFO['last_scheme_time'])<200) and not force or not SETTINGS['controlling']: return False _overwatch_mood = WORLD_INFO['overwatch']['mood'] core.handle_tracked_alife() if _overwatch_mood == 'rest': return False _player_situation = core.get_player_situation() if _overwatch_mood == 'hurt': if hurt_player(_player_situation): WORLD_INFO['last_scheme_time'] = WORLD_INFO['ticks'] return True elif _overwatch_mood == 'intrigue': if intrigue_player(_player_situation): WORLD_INFO['last_scheme_time'] = WORLD_INFO['ticks'] return True elif _overwatch_mood == 'help': if help_player(_player_situation): WORLD_INFO['last_scheme_time'] = WORLD_INFO['ticks'] return True #if _player_situation['armed']: _i = random.randint(0, 3)+10 if _i == 1: _military_group_leader = get_group_leader_with_motive('military') _bandit_group_leader = get_group_leader_with_motive('crime', online=False) #TODO: Actual bandit camp location if _military_group_leader and _bandit_group_leader: _bandit_group_location = lfe.get_current_chunk_id(LIFE[_bandit_group_leader]) order_group(LIFE[_military_group_leader], LIFE[_military_group_leader]['group'], STAGE_RAIDING, 30, chunk_key=_bandit_group_location) alife.groups.discover_group(LIFE[_military_group_leader], LIFE[_bandit_group_leader]['group']) alife.groups.declare_group_hostile(LIFE[_military_group_leader], LIFE[_military_group_leader]['group'], LIFE[_bandit_group_leader]['group']) elif _i == 2: _spawn_pos = spawns.get_spawn_in_ref('farms') _real_direction = language.get_real_direction(numbers.direction_to((MAP_SIZE[0]/2, MAP_SIZE[1]/2), _spawn_pos)) spawn_life('loner', _spawn_pos, 35, injuries={'llowerleg': {'cut': 1}}) _messages = [{'text': 'Hello? Can anyone hear me?'}, {'text': 'Bandits robbed me and left me to bleed out...'}, {'text': 'I\'m by a farm to the %s.' % _real_direction}, {'text': 'They might still be around. Please hurry!'}] events.broadcast(_messages, 40) elif 1 == 1: _bandit_group_leader = core.get_group_leader_with_motive('crime', online=True) _military_group_leader = core.get_group_leader_with_motive('military', online=False) if _military_group_leader and _bandit_group_leader: _bandit_group_location = lfe.get_current_chunk_id(LIFE[_bandit_group_leader]) _military_group_location = lfe.get_current_chunk_id(LIFE[_military_group_leader]) order_group(LIFE[_bandit_group_leader], LIFE[_bandit_group_leader]['group'], STAGE_RAIDING, 500, chunk_key=_military_group_location) alife.groups.discover_group(LIFE[_bandit_group_leader], LIFE[_military_group_leader]['group']) alife.groups.declare_group_hostile(LIFE[_bandit_group_leader], LIFE[_bandit_group_leader]['group'], LIFE[_military_group_leader]['group']) _real_direction = language.get_real_direction(numbers.direction_to((MAP_SIZE[0]/2, MAP_SIZE[1]/2), alife.chunks.get_chunk(_military_group_location)['pos'])) _messages = [{'text': 'Attention all neutral and bandit squads.'}, {'text': 'We finally got solid contact on military in the %s compound.' % _real_direction}, {'text': 'We\'re located near coords %s and heading out soon.' % (', '.join(_bandit_group_location.split(',')))}] events.broadcast(_messages, 40)
def hurt_player(situation): _player = LIFE[SETTINGS['controlling']] if situation['group']: if situation['armed']: _bandit_group_leader = get_group_leader_with_motive('crime', online=True) _military_group_leader = get_group_leader_with_motive('military', online=False) if not _military_group_leader: _military_group_leader = spawns.generate_group('soldier', amount=3, spawn_chunks=[spawns.get_spawn_in_ref('outposts', chunk_key=True)])[0] if not _bandit_group_leader: _chunk_key = alife.chunks.get_chunk_key_at(spawns.get_spawn_point_around(_military_group_leader['pos'], area=150, min_area=100)) _bandit_group_leader = spawns.generate_group('bandit', amount=5, spawn_chunks=[_chunk_key])[0] _bandit_group_location = lfe.get_current_chunk_id(_bandit_group_leader) _military_group_location = lfe.get_current_chunk_id(_military_group_leader) order_group(_bandit_group_leader, _bandit_group_leader['group'], STAGE_RAIDING, 500, chunk_key=_military_group_location) alife.groups.discover_group(_bandit_group_leader, _military_group_leader['group']) alife.groups.declare_group_hostile(_bandit_group_leader, _bandit_group_leader['group'], _military_group_leader['group']) _real_direction = language.get_real_direction(numbers.direction_to((MAP_SIZE[0]/2, MAP_SIZE[1]/2), alife.chunks.get_chunk(_military_group_location)['pos'])) _messages = [{'text': 'Attention all neutral and bandit squads.'}, {'text': 'We finally got solid contact on military in the %s compound.' % _real_direction}, {'text': 'We\'re located near coords %s and heading out soon.' % (', '.join(_bandit_group_location.split(',')))}] events.broadcast(_messages, 40) core.record_encounter(len(alife.groups.get_group(_military_group_leader, _military_group_leader['group'])['members'])) _player_group_leader = LIFE[alife.groups.get_leader(_player, situation['group'])] for friendly_member in alife.groups.get_group(_player_group_leader, situation['group'])['members']: for hostile_member in alife.groups.get_group(_military_group_leader, _military_group_leader['group'])['members']: _target = alife.brain.meet_alife(LIFE[friendly_member], LIFE[hostile_member]) _target['last_seen_time'] = 1 _target['escaped'] = 1 _target['last_seen_at'] = LIFE[hostile_member]['pos'][:] alife.stats.establish_hostile(LIFE[friendly_member], hostile_member) for hostile_member in alife.groups.get_group(_military_group_leader, _military_group_leader['group'])['members']: for friendly_member in alife.groups.get_group(_player_group_leader, situation['group'])['members']: _target = alife.brain.meet_alife(LIFE[hostile_member], LIFE[friendly_member]) _target['last_seen_time'] = 1 _target['escaped'] = 1 _target['last_seen_at'] = LIFE[friendly_member]['pos'][:] alife.stats.establish_hostile(LIFE[hostile_member], friendly_member) return True elif situation['armed']: _town_chunk_keys = [] for ref in WORLD_INFO['refs']['towns']: _town_chunk_keys.extend(ref) _nearest_town_chunk_key = alife.chunks.get_nearest_chunk_in_list(_player['pos'], _town_chunk_keys) _town_chunk = alife.chunks.get_chunk(_nearest_town_chunk_key) _distance_to_nearst_town = numbers.distance(_player['pos'], _town_chunk['pos']) _spawn_distance = 15*WORLD_INFO['chunk_size'] if len(situation['online_alife']) == len(situation['trusted_online_alife']): if _distance_to_nearst_town<=50: _group_spawn_velocity = numbers.velocity(numbers.direction_to(_player['pos'], _town_chunk['pos']), _spawn_distance+(50-numbers.clip(_distance_to_nearst_town, 0, 50))) _group_spawn_pos = [int(round(_player['pos'][0]+_group_spawn_velocity[0])), int(round(_player['pos'][1]+_group_spawn_velocity[1]))] _group_spawn_pos[0] = numbers.clip(_group_spawn_pos[0], 0, MAP_SIZE[0]) _group_spawn_pos[1] = numbers.clip(_group_spawn_pos[1], 0, MAP_SIZE[1]) _group_spawn_chunk_key = alife.chunks.get_chunk_key_at(spawns.get_spawn_point_around(_group_spawn_pos, area=30)) _alife = spawns.generate_group('bandit', amount=2, spawn_chunks=[_group_spawn_chunk_key]) for ai in _alife: alife.brain.meet_alife(ai, _player) alife.stats.establish_hostile(ai, _player['id']) core.record_encounter(2, life_ids=[i['id'] for i in _alife]) if random.randint(0, 1) or 1: _spawn_chunk_key = spawns.get_spawn_point_around(_group_spawn_pos, area=90, min_area=60, chunk_key=True) _other_group = spawns.generate_group('loner', amount=1, spawn_chunks=[_spawn_chunk_key]) for ai in _other_group: for ai2 in _alife: _target = alife.brain.meet_alife(ai, ai2) _target['last_seen_time'] = 1 _target['escaped'] = 1 _target['last_seen_at'] = ai2['pos'][:] alife.stats.establish_hostile(ai, ai2['id']) for ai2 in _alife: for ai in _other_group: _target = alife.brain.meet_alife(ai2, ai) _target['last_seen_time'] = 1 _target['escaped'] = 1 _target['last_seen_at'] = ai['pos'][:] alife.stats.establish_hostile(ai2, ai['id']) _messages = [{'text': 'I\'m pinned down in the village!'}, {'text': 'Anyone nearby?'}] events.broadcast(_messages, 0) return True elif 1==2: _spawn_chunk_key = spawns.get_spawn_point_around(_player['pos'], min_area=125, area=200, chunk_key=True) _group = spawns.generate_group('loner', amount=1, spawn_chunks=[_spawn_chunk_key]) core.record_encounter(1, life_ids=[l['id'] for l in _group]) for ai in _group: events.attract_tracked_alife_to(spawns.get_spawn_point_around(_player['pos'], min_area=10, area=100)) return False
def form_scheme(force=False): print WORLD_INFO['next_scheme_timer'] if WORLD_INFO['next_scheme_timer']: WORLD_INFO['next_scheme_timer'] -= 1 return False if (WORLD_INFO['scheme'] and not force) or not SETTINGS['controlling']: return False _overwatch_mood = WORLD_INFO['overwatch']['mood'] _player = LIFE[SETTINGS['controlling']] _player_situation = core.get_player_situation() _event_names = [] if _player_situation['active_factions']: if not _player_situation['active_factions'] == ['ZES'] and not random.randint(0, (len(artifacts.get_active_fields())+1)*3): _event_names.append('anomaly') _event_names.append('capture') if not random.randint(0, 8): _event_names.append('resupply') if not random.randint(0, 4): _event_names.append('attract') if not _event_names: WORLD_INFO['next_scheme_timer'] = 50 return False _event_name = random.choice(_event_names) print _event_name if _event_name == 'attract': if _player_situation['enemy_factions'] and not _player_situation['friendly_factions']: for enemy_faction in _player_situation['enemy_factions']: for enemy_of_enemy_faction in alife.factions.get_faction_enemies(enemy_faction): _nearest_group = alife.factions.get_nearest_group(enemy_of_enemy_faction, _player['pos']) if not _nearest_group: continue alife.factions.move_group_to(enemy_of_enemy_faction, _nearest_group, lfe.get_current_chunk_id(_player)) WORLD_INFO['next_scheme_timer'] = 250 elif _event_name == 'capture': _chosen_faction = random.choice(_player_situation['active_factions']) _chosen_group = random.choice(alife.factions.get_faction(_chosen_faction)['groups']) alife.factions.capture_territory(_chosen_faction, _chosen_group) WORLD_INFO['next_scheme_timer'] = 350 elif _event_name == 'resupply': _chunk_key = random.choice(WORLD_INFO['territories'][artifacts.find_territory(y_min=.5)]['chunk_keys']) _pos = WORLD_INFO['chunk_map'][_chunk_key]['pos'] _storage_items = [{'item': 'AK-74', 'rarity': 1.0}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm round', 'rarity': 0.6}, {'item': '5.45x39mm magazine', 'rarity': 1.0}] _storage = [{'item': 'military crate', 'rarity': 1.0, 'spawn_list': _storage_items}] for faction_name in WORLD_INFO['factions']: if faction_name == 'ZES': continue _faction = WORLD_INFO['factions'][faction_name] for group_id in _faction['groups']: if not random.randint(0, 3): continue #alife.factions.move_group_to(faction_name, group_id, _chunk_key) alife.factions.resupply(faction_name, group_id, _chunk_key) events.create_cache_drop(_pos, _storage) WORLD_INFO['next_scheme_timer'] = 350 elif _event_name == 'anomaly': _territory_id = events.create_anomaly_field(_player_situation, y_min=.65) for faction_name in _player_situation['active_factions']: if faction_name == 'ZES': continue _faction = WORLD_INFO['factions'][faction_name] for group_id in _faction['groups']: if random.randint(0, 1): continue _chunk_key = random.choice(WORLD_INFO['territories'][_territory_id]['chunk_keys']) maps.load_cluster_at_position_if_needed(WORLD_INFO['chunk_map'][_chunk_key]['pos']) alife.factions.move_group_to(faction_name, group_id, _chunk_key) WORLD_INFO['next_scheme_timer'] = 350
def look(life): if not 'CAN_SEE' in life['life_flags']: return False for target_id in life['know']: if life['know'][target_id]['last_seen_time']: life['know'][target_id]['last_seen_time'] += 1 life['know'][target_id]['time_visible'] = 0 else: life['know'][target_id]['time_visible'] += 1 if 'player' in life: if life['path'] or not brain.get_flag(life, 'visible_chunks'): if SETTINGS['smp']: _visible_chunks = post_scan_surroundings(life) else: _visible_chunks = scan_surroundings(life, judge=False, get_chunks=True, ignore_chunks=0) _chunks = [maps.get_chunk(c) for c in _visible_chunks] brain.flag(life, 'visible_chunks', value=_visible_chunks) elif 'player' in life: _visible_chunks = brain.get_flag(life, 'visible_chunks') _chunks = [maps.get_chunk(c) for c in _visible_chunks] else: #This is for optimizing. Be careful if you mess with this... _nearby_alife = {} for alife in LIFE.values(): if alife['id'] == life['id']: continue if bad_numbers.distance( life['pos'], alife['pos']) <= get_vision(life) and can_see_position( life, alife['pos']): _nearby_alife[alife['id']] = { 'pos': alife['pos'][:], 'stance': alife['stance'] } _last_nearby_alife = brain.get_flag(life, '_nearby_alife') if not _last_nearby_alife == _nearby_alife: brain.flag(life, '_nearby_alife', value=_nearby_alife) else: for target_id in life['seen']: if life['know'][target_id]['last_seen_time']: life['know'][target_id]['last_seen_time'] = 0 return False _chunks = [ maps.get_chunk(c) for c in brain.get_flag(life, 'visible_chunks') ] life['seen'] = [] life['seen_items'] = [] for item_uid in life['know_items']: life['know_items'][item_uid]['last_seen_time'] += 1 for target_id in life['know']: life['know'][target_id]['last_seen_time'] += 1 if life['know'][target_id]['last_seen_time'] >= 10 and not life[ 'know'][target_id]['escaped']: life['know'][target_id]['escaped'] = 1 if not 'player' in life: quick_look(life) return False for chunk in _chunks: judgement.judge_chunk_visually( life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1])) judgement.judge_chunk_life( life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1])) for ai in [LIFE[i] for i in chunk['life']]: if ai['id'] == life['id']: continue if not is_in_fov(life, ai['pos']): if ai['id'] in life['know']: life['know'][ai['id']]['time_visible'] = 0 continue if not ai['id'] in life['know']: brain.meet_alife(life, ai) _visibility = get_visiblity_of_position(life, ai['pos']) _stealth_coverage = get_stealth_coverage(ai) if _visibility < 1 - _stealth_coverage: continue life['seen'].append(ai['id']) if life['think_rate'] == life['think_rate_max']: lfe.create_and_update_self_snapshot(LIFE[ai['id']]) judgement.judge_life(life, ai['id']) if ai['dead']: if 'player' in life and not life['know'][ ai['id']]['dead'] and life['know'][ ai['id']]['last_seen_time'] > 25: logic.show_event('You discover the body of %s.' % ' '.join(ai['name']), life=ai) if life['know'][ai['id']]['group']: groups.remove_member(life, life['know'][ai['id']]['group'], ai['id']) life['know'][ai['id']]['group'] = None core.record_loss(1) life['know'][ai['id']]['dead'] = True elif ai['asleep']: life['know'][ai['id']]['asleep'] = True elif not ai['asleep']: life['know'][ai['id']]['asleep'] = False life['know'][ai['id']]['last_seen_time'] = 0 life['know'][ai['id']]['last_seen_at'] = ai['pos'][:] life['know'][ai['id']]['escaped'] = False life['know'][ai['id']]['state'] = ai['state'] life['know'][ai['id']]['state_tier'] = ai['state_tier'] if brain.alife_has_flag(life, ai['id'], 'search_map'): brain.unflag_alife(life, ai['id'], 'search_map') _chunk_id = lfe.get_current_chunk_id(ai) judgement.judge_chunk(life, _chunk_id, seen=True) for item in [ITEMS[i] for i in chunk['items'] if i in ITEMS]: if not is_in_fov(life, item['pos']): continue if not item['uid'] in life['know_items']: brain.remember_item(life, item) if items.is_item_owned(item['uid']): #TODO: This doesn't work because we are specifically checking chunks if item['owner'] and lfe.item_is_equipped( LIFE[item['owner']], item['uid']): life['know_items'][item['uid']]['last_seen_at'] = LIFE[ item['owner']]['pos'] life['know_items'][ item['uid']]['last_owned_by'] = item['owner'] life['know_items'][item['uid']]['last_seen_time'] = 0 continue life['seen_items'].append(item['uid']) life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:] life['know_items'][item['uid']]['last_seen_time'] = 0 life['know_items'][item['uid']]['last_owned_by'] = None life['know_items'][item['uid']]['score'] = judgement.judge_item( life, item['uid']) life['know_items'][item['uid']]['lost'] = False
def get_jobs(life, group_id): _group = get_group(life, group_id) _jobs = [] _leader = LIFE[_group['leader']] if not has_camp(group_id): _nearest_camp = camps.get_nearest_known_camp(_leader) if _leader['known_camps']: _j = jobs.create_job(_leader, 'Raid', gist='start_raid', description='Raid camp %s.' % _nearest_camp['id']) _pos = lfe.get_current_chunk(_leader)['pos'] _chunk_key = lfe.get_current_chunk_id(_leader) jobs.add_task( _j, '0', 'announce_to_group', action.make_small_script(function='announce_to_group', kwargs={ 'group_id': group_id, 'gist': 'announce_group_job', 'message': jobs.get_job(_j)['description'], 'job_id': _j }), player_action=action.make_small_script(function='always'), description='Gather group members.') jobs.add_task( _j, '1', 'move_to_chunk', action.make_small_script(function='travel_to_position', kwargs={'pos': _pos}), player_action=action.make_small_script( function='is_in_chunk', kwargs={'chunk_key': _chunk_key}), description='Travel to position %s, %s' % (_pos[0], _pos[1]), delete_on_finish=False) jobs.add_task(_j, '2', 'wait_for_number_of_group_members_in_chunk', action.make_small_script( function='number_of_alife_in_chunk_matching', kwargs={ 'amount': 2, 'chunk_key': _chunk_key, 'matching': { 'group': _leader['group'] } }), description='Wait until everyone arrives.') #jobs.add_task(_j, '3', 'talk', # action.make_small_script(function='travel_to_position', # kwargs={'pos': chunks.get_nearest_chunk_in_list(_leader['pos'], camps.get_camp(_nearest_camp['id'])['reference'])}), # requires=['1'], # delete_on_finish=False) _jobs.append(_j) if len(_leader['known_groups']) > 1: _lowest = {'score': 0, 'group': None} for group_id in [ g for g in _leader['known_groups'] if not g == _leader['group'] ]: _score = judgement.judge_group(_leader, group_id) if not _lowest['group'] or _score < _lowest['score']: _lowest['score'] = _score _lowest['group'] = group_id print 'RAID', _lowest else: print 'ony one' return _jobs