def get_spawn_point(randomize=False, zone_entry_point=False): if zone_entry_point: _pos = [random.randint(150, 250), random.randint(850, 900), 2] return spawns.get_spawn_point_around(_pos, area=100) if WORLD_INFO['reference_map']['roads'] and not randomize: _entry_road_keys = [] for road in WORLD_INFO['reference_map']['roads']: for chunk_key in alife.references.get_reference(road): _pos = WORLD_INFO['chunk_map'][chunk_key]['pos'] if len(mapgen.get_neighbors_of_type(WORLD_INFO, chunk_key, 'any')) <= 3: _entry_road_keys.append(chunk_key) if _entry_road_keys: _spawn_pos = random.choice(WORLD_INFO['chunk_map'][random.choice(_entry_road_keys)]['ground']) return [_spawn_pos[0], _spawn_pos[1], 2] _start_seed = random.randint(0, 3) if not _start_seed: _spawn = (random.randint(0, MAP_SIZE[0]-1), 0, 2) elif _start_seed == 1: _spawn = (MAP_SIZE[0]-1, random.randint(0, MAP_SIZE[1]-1), 2) elif _start_seed == 2: _spawn = (random.randint(0, MAP_SIZE[0]-1), MAP_SIZE[1]-1, 2) else: _spawn = (0, random.randint(0, MAP_SIZE[1]-1), 2) return _spawn
def path_along_reference(life, ref_type): _best_reference = _find_best_unknown_reference(life, ref_type)["reference"] if not _best_reference: print "NO BEST", ref_type return False _starting_chunk_key = find_nearest_key_in_reference(life, _best_reference) _chunk_path_keys = [] _directions = {} for neighbor_key in mapgen.get_neighbors_of_type(WORLD_INFO, _starting_chunk_key, ref_type, diagonal=True): if maps.get_chunk(neighbor_key) == lfe.get_current_chunk(life): continue _neighbor_pos = [int(val) + (WORLD_INFO["chunk_size"] / 2) for val in neighbor_key.split(",")] _cent = ( lfe.get_current_chunk(life)["pos"][0] + (WORLD_INFO["chunk_size"] / 2), lfe.get_current_chunk(life)["pos"][1] + (WORLD_INFO["chunk_size"] / 2), ) _neighbor_direction = numbers.direction_to(_cent, _neighbor_pos) _directions[_neighbor_direction] = {"key": neighbor_key, "score": 9999} _best_dir = {"dir": -1, "score": 0} for mod in range(-45, 361, 45): _new_dir = life["discover_direction"] + mod if _new_dir >= 360: _new_dir -= 360 if _new_dir in _directions: _score = 0 if _directions[_new_dir]["key"] in life["known_chunks"]: continue _score += (180 - (abs(_new_dir - life["discover_direction"]))) / 45 _score += life["discover_direction_history"].count(_new_dir) if _score >= _best_dir["score"]: if _score == _best_dir["score"]: _chunk = maps.get_chunk(_directions[_new_dir]["key"]) _best_dir["dir"] = _new_dir _best_dir["score"] = _score if _best_dir["dir"] == -1: return None # print _best_dir,_directions[_best_dir['dir']] life["discover_direction_history"].append(life["discover_direction"]) if len(life["discover_direction_history"]) >= 5: life["discover_direction_history"].pop(0) life["discover_direction"] = _best_dir["dir"] return _directions[_best_dir["dir"]]["key"]
def path_along_reference(life, ref_type): _reference = WORLD_INFO['references'][WORLD_INFO['reference_map']['roads'][0]] _visible_chunks = alife.brain.get_flag(life, 'visible_chunks') _starting_chunk_key = alife.chunks.get_nearest_chunk_in_list(life['pos'], _reference, check_these_chunks_first=_visible_chunks) _chunk_path_keys = [] _directions = {} for neighbor_key in mapgen.get_neighbors_of_type(WORLD_INFO, _starting_chunk_key, ref_type, diagonal=True): if maps.get_chunk(neighbor_key) == lfe.get_current_chunk(life): continue _neighbor_pos = [int(val)+(WORLD_INFO['chunk_size']/2) for val in neighbor_key.split(',')] _cent = (lfe.get_current_chunk(life)['pos'][0]+(WORLD_INFO['chunk_size']/2), lfe.get_current_chunk(life)['pos'][1]+(WORLD_INFO['chunk_size']/2)) _neighbor_direction = numbers.direction_to(_cent, _neighbor_pos) _directions[_neighbor_direction] = {'key': neighbor_key, 'score': 9999} _best_dir = {'dir': -1, 'score': 0} for mod in range(-45, 361, 45): _new_dir = life['discover_direction']+mod if _new_dir>=360: _new_dir -= 360 if _new_dir in _directions: _score = 0 if _directions[_new_dir]['key'] in life['known_chunks']: continue _score += (180-(abs(_new_dir-life['discover_direction'])))/45 _score += life['discover_direction_history'].count(_new_dir) if _score>=_best_dir['score']: if _score==_best_dir['score']: _chunk = maps.get_chunk(_directions[_new_dir]['key']) _best_dir['dir'] = _new_dir _best_dir['score'] = _score if _best_dir['dir'] == -1: return None #print _best_dir,_directions[_best_dir['dir']] life['discover_direction_history'].append(life['discover_direction']) if len(life['discover_direction_history'])>=5: life['discover_direction_history'].pop(0) life['discover_direction'] = _best_dir['dir'] return _directions[_best_dir['dir']]['key']
def get_spawn_point(randomize=False, zone_entry_point=False): if zone_entry_point: _pos = [random.randint(150, 250), random.randint(850, 900), 2] return spawns.get_spawn_point_around(_pos, area=100) if WORLD_INFO['reference_map']['roads'] and not randomize: _entry_road_keys = [] for road in WORLD_INFO['reference_map']['roads']: for chunk_key in alife.references.get_reference(road): _pos = WORLD_INFO['chunk_map'][chunk_key]['pos'] if len( mapgen.get_neighbors_of_type(WORLD_INFO, chunk_key, 'any')) <= 3: _entry_road_keys.append(chunk_key) if _entry_road_keys: _spawn_pos = random.choice(WORLD_INFO['chunk_map'][random.choice( _entry_road_keys)]['ground']) return [_spawn_pos[0], _spawn_pos[1], 2] _start_seed = random.randint(0, 3) if not _start_seed: _spawn = (random.randint(0, MAP_SIZE[0] - 1), 0, 2) elif _start_seed == 1: _spawn = (MAP_SIZE[0] - 1, random.randint(0, MAP_SIZE[1] - 1), 2) elif _start_seed == 2: _spawn = (random.randint(0, MAP_SIZE[0] - 1), MAP_SIZE[1] - 1, 2) else: _spawn = (0, random.randint(0, MAP_SIZE[1] - 1), 2) return _spawn