def get_target_to_follow(life): _highest = {'id': None, 'score': 0} for target_id in get_trusted(life, visible=False, only_recent=False): if not lfe.execute_raw(life, 'follow', 'follow_target_if', life_id=target_id): continue _score = 0 _known_target = brain.knows_alife_by_id(life, target_id) if not _known_target['last_seen_at']: continue if _known_target['escaped'] == 2: continue #_score += _known_target['trust'] if life['group'] and groups.is_leader(life, life['group'], target_id) and groups.get_stage(life, life['group']) == STAGE_RAIDING: _score += 1 if _score > _highest['score']: _highest['id'] = target_id _highest['score'] = _score return _highest['id']
def get_target_to_follow(life): _highest = {"id": None, "score": 1} for target_id in get_trusted(life, visible=False, only_recent=False): if not lfe.execute_raw(life, "follow", "follow_target_if", life_id=target_id): continue _score = 0 _known_target = brain.knows_alife_by_id(life, target_id) if not _known_target["last_seen_at"]: continue if _known_target["escaped"] == 2: continue _score += _known_target["trust"] if life["group"] and groups.is_leader(life, life["group"], target_id): _score += 1 if _score >= _highest["score"]: _highest["id"] = target_id _highest["score"] = _score return _highest["id"]
def desires_to_create_camp(life): if not 'CAN_GROUP' in life['life_flags']: return False if life['group'] and not groups.get_camp(life['group']) and groups.is_leader(life, life['group'], life['id']): if len(groups.get_group(life, life['group'])['members'])>1: return True return False
def desires_to_create_camp(life): if not 'CAN_GROUP' in life['life_flags']: return False if life['group'] and not groups.get_camp( life['group']) and groups.is_leader(life, life['group'], life['id']): if len(groups.get_group(life, life['group'])['members']) > 1: return True return False
def react_to_tension(life, life_id): if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']: return False if life['group'] and not groups.is_leader( life, life['group'], life['id']) and groups.get_leader( life, life['group']): if sight.can_see_target(life, groups.get_leader( life, life['group'])) and sight.can_see_target( LIFE[life_id], groups.get_leader(life, life['group'])): return False _disarm = brain.get_alife_flag(life, life_id, 'disarm') if _disarm: #For now... if not sight.can_see_position(life, LIFE[life_id]['pos']): groups.announce(life, life['group'], 'attacked_by_hostile', filter_if=lambda life_id: brain.knows_alife_by_id( life, life_id)['last_seen_time'] <= 30, target_id=life_id) return False for item_uid in lfe.get_all_visible_items(LIFE[life_id]): if ITEMS[item_uid]['type'] == 'gun': break else: brain.unflag_alife(life, life_id, 'disarm') speech.start_dialog(life, life_id, 'clear_drop_weapon') return False _time_elapsed = WORLD_INFO['ticks'] - _disarm if _time_elapsed > 135 and not speech.has_sent(life, life_id, 'threaten'): speech.start_dialog(life, life_id, 'threaten') speech.send(life, life_id, 'threaten') elif _time_elapsed > 185: speech.start_dialog(life, life_id, 'establish_hostile') elif not speech.has_sent(life, life_id, 'confront'): speech.start_dialog(life, life_id, 'confront') speech.send(life, life_id, 'confront')
def wants_group_member(life, life_id): if not life['group']: return False if groups.is_member(life, life['group'], life_id): return False if not groups.is_leader(life, life['group'], life['id']): return False if not lfe.execute_raw(life, 'group', 'wants_group_member', life_id=life_id): return False _know = brain.knows_alife_by_id(life, life_id) if not _know: return False if not judgement.can_trust(life, life_id): return False return True
def react_to_tension(life, life_id): if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']: return False if life['group'] and not groups.is_leader(life, life['group'], life['id']) and groups.get_leader(life, life['group']): if sight.can_see_target(life, groups.get_leader(life, life['group'])) and sight.can_see_target(LIFE[life_id], groups.get_leader(life, life['group'])): return False _disarm = brain.get_alife_flag(life, life_id, 'disarm') if _disarm: #For now... if not sight.can_see_position(life, LIFE[life_id]['pos']): groups.announce(life, life['group'], 'attacked_by_hostile', filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30, target_id=life_id) return False for item_uid in lfe.get_all_visible_items(LIFE[life_id]): if ITEMS[item_uid]['type'] == 'gun': break else: brain.unflag_alife(life, life_id, 'disarm') speech.start_dialog(life, life_id, 'clear_drop_weapon') return False _time_elapsed = WORLD_INFO['ticks']-_disarm if _time_elapsed>135 and not speech.has_sent(life, life_id, 'threaten'): speech.start_dialog(life, life_id, 'threaten') speech.send(life, life_id, 'threaten') elif _time_elapsed>185: speech.start_dialog(life, life_id, 'establish_hostile') elif not speech.has_sent(life, life_id, 'confront'): speech.start_dialog(life, life_id, 'confront') speech.send(life, life_id, 'confront')
def wants_group_member(life, life_id): if not life['group']: return False if groups.is_member(life, life['group'], life_id): return False if not groups.is_leader(life, life['group'], life['id']): return False if not lfe.execute_raw( life, 'group', 'wants_group_member', life_id=life_id): return False _know = brain.knows_alife_by_id(life, life_id) if not _know: return False if not judgement.can_trust(life, life_id): return False return True
def desires_first_contact_with(life, life_id): #print life['name'], LIFE[life_id]['name'],brain.knows_alife_by_id(life, life_id)['alignment'] if not brain.knows_alife_by_id(life, life_id)['alignment'] == 'neutral': return False if life['group'] and not groups.is_leader(life, life['group'], life['id']): #Don't talk if we're in a group and near our leader. #TODO: #judgement Even then, we should consider having group members avoid non-members regardless. #TODO: #judgement How do group types play into this? _leader = brain.knows_alife_by_id(life, groups.get_leader(life, life['group'])) if _leader: #TODO: #judgement Placeholder for future logic. if numbers.distance(life['pos'], _leader['life']['pos']) < 100: return False if life['stats']['motive_for_crime']>=4: return True if life['stats']['sociability']>=6: return True return False
def desires_first_contact_with(life, life_id): #print life['name'], LIFE[life_id]['name'],brain.knows_alife_by_id(life, life_id)['alignment'] if not brain.knows_alife_by_id(life, life_id)['alignment'] == 'neutral': return False if life['group'] and not groups.is_leader(life, life['group'], life['id']): #Don't talk if we're in a group and near our leader. #TODO: #judgement Even then, we should consider having group members avoid non-members regardless. #TODO: #judgement How do group types play into this? _leader = brain.knows_alife_by_id( life, groups.get_leader(life, life['group'])) if _leader: #TODO: #judgement Placeholder for future logic. if numbers.distance(life['pos'], _leader['life']['pos']) < 100: return False if life['stats']['motive_for_crime'] >= 4: return True if life['stats']['sociability'] >= 6: return True return False
def judge_chunk(life, chunk_id, visited=False, seen=False, checked=True, investigate=False): if lfe.ticker(life, "judge_tick", 30): return False chunk = maps.get_chunk(chunk_id) _score = 0 if not chunk_id in life["known_chunks"]: life["known_chunks"][chunk_id] = { "last_visited": -1, "last_seen": -1, "last_checked": -1, "discovered_at": WORLD_INFO["ticks"], "flags": {}, "life": [], } _camp = chunks.get_global_flag(chunk_id, "camp") if _camp and not _camp in life["known_camps"]: camps.discover_camp(life, _camp) _known_chunk = life["known_chunks"][chunk_id] if seen: _known_chunk["last_seen"] = WORLD_INFO["ticks"] if visited: _known_chunk["last_visited"] = WORLD_INFO["ticks"] _known_chunk["last_seen"] = WORLD_INFO["ticks"] if checked: _known_chunk["last_checked"] = WORLD_INFO["ticks"] _trusted = 0 for _target in life["know"].values(): if not _target["last_seen_at"]: continue _is_here = False _actually_here = False if chunks.position_is_in_chunk(_target["last_seen_at"], chunk_id) and not _target["life"]["path"]: _is_here = True elif ( not _target["last_seen_time"] and _target["life"]["path"] and chunks.position_is_in_chunk(lfe.path_dest(_target["life"]), chunk_id) ): _is_here = True if chunks.position_is_in_chunk(_target["life"]["pos"], chunk_id): _actually_here = True if _is_here: if not _target["life"]["id"] in _known_chunk["life"]: _known_chunk["life"].append(_target["life"]["id"]) if is_target_dangerous(life, _target["life"]["id"]): _score -= 10 elif life["group"] and groups.is_leader(life, life["group"], _target["life"]["id"]): _trusted += _target["trust"] else: if _target["life"]["id"] in _known_chunk["life"]: _known_chunk["life"].remove(_target["life"]["id"]) if investigate and not visited: chunks.flag(life, chunk_id, "investigate", True) elif visited and chunks.get_flag(life, chunk_id, "investigate"): chunks.unflag(life, chunk_id, "investigate") if chunks.get_flag(life, chunk_id, "investigate"): _score += 5 # for camp in life['known_camps']: # if not chunk_id in camps.get_camp(camp)['reference']: # continue # if not life['camp'] == camp['id']: # continue # if stats.desires_shelter(life): # _score += judge_camp(life, life['camp']) if lfe.execute_raw(life, "discover", "remember_shelter"): judge_shelter(life, chunk_id) # if stats.desires_interaction(life): # _score += _trusted if seen: pass # TODO: Still a good idea... maybe use for shelter? # for item in chunk['items']: # _item = brain.remember_known_item(life, item) # if _item: # _score += _item['score'] life["known_chunks"][chunk_id]["score"] = _score return _score
def get_minimum_camp_score(life): if life['group'] and groups.is_leader(life, life['group'], life['id']): return len(groups.get_group(life, life['group'])['members']) return 3
def judge_chunk(life, chunk_id, visited=False, seen=False, checked=True, investigate=False): if lfe.ticker(life, 'judge_tick', 30): return False chunk = maps.get_chunk(chunk_id) _score = 0 if not chunk_id in life['known_chunks']: life['known_chunks'][chunk_id] = {'last_visited': -1, 'last_seen': -1, 'last_checked': -1, 'discovered_at': WORLD_INFO['ticks'], 'flags': {}, 'life': []} _camp = chunks.get_global_flag(chunk_id, 'camp') if _camp and not _camp in life['known_camps']: camps.discover_camp(life, _camp) _known_chunk = life['known_chunks'][chunk_id] if seen: _known_chunk['last_seen'] = WORLD_INFO['ticks'] if visited: _known_chunk['last_visited'] = WORLD_INFO['ticks'] _known_chunk['last_seen'] = WORLD_INFO['ticks'] if checked: _known_chunk['last_checked'] = WORLD_INFO['ticks'] _trusted = 0 for _target in life['know'].values(): if not _target['last_seen_at']: continue _is_here = False _actually_here = False if chunks.position_is_in_chunk(_target['last_seen_at'], chunk_id) and not _target['life']['path']: _is_here = True elif not _target['last_seen_time'] and _target['life']['path'] and chunks.position_is_in_chunk(lfe.path_dest(_target['life']), chunk_id): _is_here = True if chunks.position_is_in_chunk(_target['life']['pos'], chunk_id): _actually_here = True if _is_here: if not _target['life']['id'] in _known_chunk['life']: _known_chunk['life'].append(_target['life']['id']) if is_target_dangerous(life, _target['life']['id']): _score -= 10 elif life['group'] and groups.is_leader(life, life['group'], _target['life']['id']): _trusted += _target['trust'] else: if _target['life']['id'] in _known_chunk['life']: _known_chunk['life'].remove(_target['life']['id']) if investigate and not visited: chunks.flag(life, chunk_id, 'investigate', True) elif visited and chunks.get_flag(life, chunk_id, 'investigate'): chunks.unflag(life, chunk_id, 'investigate') if chunks.get_flag(life, chunk_id, 'investigate'): _score += 5 #for camp in life['known_camps']: # if not chunk_id in camps.get_camp(camp)['reference']: # continue #if not life['camp'] == camp['id']: # continue #if stats.desires_shelter(life): # _score += judge_camp(life, life['camp']) if lfe.execute_raw(life, 'discover', 'remember_shelter'): judge_shelter(life, chunk_id) #if stats.desires_interaction(life): # _score += _trusted if seen: pass #TODO: Still a good idea... maybe use for shelter? #for item in chunk['items']: # _item = brain.remember_known_item(life, item) # if _item: # _score += _item['score'] life['known_chunks'][chunk_id]['score'] = _score return _score