Exemplo n.º 1
0
def can_see_chunk_from_pos(pos1, chunk_key, distance=True, vision=10):
	_fast_see = _can_see_chunk_quick(pos1, chunk_key, vision)
	
	if _fast_see:
		return _fast_see
	
	chunk = maps.get_chunk(chunk_key)
	
	for y in range(chunk['pos'][1], chunk['pos'][1]+WORLD_INFO['chunk_size']):
		for x in range(chunk['pos'][0], chunk['pos'][0]+WORLD_INFO['chunk_size']):
			if ((x-chunk['pos'][0] >= 0 and x-chunk['pos'][0] <= WORLD_INFO['chunk_size']-1) and y-chunk['pos'][1] in [0, WORLD_INFO['chunk_size']-1]) or\
			   ((y-chunk['pos'][1] >= 0 and y-chunk['pos'][1] <= WORLD_INFO['chunk_size']-1) and x-chunk['pos'][0] in [0, WORLD_INFO['chunk_size']-1]):
				_can_see = sight._can_see_position(pos1, (x, y), distance=distance, max_length=vision)
				
				if _can_see:
					return _can_see
	
	return False
Exemplo n.º 2
0
def _can_see_chunk_quick(start_pos, chunk_id, vision):
	chunk = maps.get_chunk(chunk_id)
	
	if not len(chunk['ground']):
		return False
	
	for pos in [(0, 0), (1, 0), (0, 1), (1, 1)]:
		_x = pos[0]*WORLD_INFO['chunk_size']
		_y = pos[1]*WORLD_INFO['chunk_size']
		
		if _x:
			_x -= 1
		if _y:
			_y -= 1
		
		_can_see = sight._can_see_position(start_pos, (chunk['pos'][0]+_x, chunk['pos'][1]+_y), max_length=vision)
		
		if _can_see:
			return _can_see
	
	return False