def judge_shelter(life, chunk_id): chunk = WORLD_INFO["chunk_map"][chunk_id] _known_chunk = life["known_chunks"][chunk_id] _score = 0 if not chunk["type"] in ["building", "town", "outpost"]: return 0 if not chunks.get_flag(life, chunk_id, "shelter"): _cover = [] for pos in chunk["ground"]: for z in range(life["pos"][2] + 1, MAP_SIZE[2]): WORLD_INFO["map"][pos[0]][pos[1]][z] if WORLD_INFO["map"][pos[0]][pos[1]][z]: _cover.append(list(pos)) if not _cover: return 0 chunks.flag(life, chunk_id, "shelter_cover", _cover) chunks.flag(life, chunk_id, "shelter", len(chunks.get_flag(life, chunk_id, "shelter_cover"))) return True
def judge_shelter(life, chunk_id): chunk = WORLD_INFO['chunk_map'][chunk_id] _known_chunk = life['known_chunks'][chunk_id] _score = 0 if not chunk['type'] in ['building', 'town', 'outpost']: return 0 if not chunks.get_flag(life, chunk_id, 'shelter'): _cover = [] for pos in chunk['ground']: for z in range(life['pos'][2]+1, MAP_SIZE[2]): WORLD_INFO['map'][pos[0]][pos[1]][z] if WORLD_INFO['map'][pos[0]][pos[1]][z]: _cover.append(list(pos)) break if not _cover: return 0 chunks.flag(life, chunk_id, 'shelter_cover', _cover) chunks.flag(life, chunk_id, 'shelter', len(chunks.get_flag(life, chunk_id, 'shelter_cover'))) return True
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 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