コード例 #1
0
ファイル: sight.py プロジェクト: lawanfalalu/Reactor-3
def _scan_surroundings(center_chunk_key,
                       chunk_size,
                       vision,
                       ignore_chunks=[],
                       chunk_map=WORLD_INFO['chunk_map']):
    _center_chunk_pos = maps.get_chunk(center_chunk_key)['pos']
    #_center_chunk_pos[0] = ((_center_chunk_pos[0]/chunk_size)*chunk_size)+(chunk_size/2)
    #_center_chunk_pos[1] = ((_center_chunk_pos[1]/chunk_size)*chunk_size)+(chunk_size/2)
    _chunks = set()
    _chunk_map = set(chunk_map.keys())

    for _x_mod, _y_mod in render_los.draw_circle(0, 0,
                                                 ((vision * 2) / chunk_size)):
        x_mod = _center_chunk_pos[0] + (_x_mod * chunk_size
                                        )  #(_x_mod/chunk_size)*chunk_size
        y_mod = _center_chunk_pos[1] + (_y_mod * chunk_size)
        #print x_mod, y_mod, _center_chunk_pos

        _chunk_key = '%s,%s' % (x_mod, y_mod)

        if _chunk_key in _chunks:
            continue

        if not ignore_chunks == 0 and _chunk_key in ignore_chunks:
            continue
        elif isinstance(ignore_chunks, list):
            ignore_chunks.append(_chunk_key)

        if chunk_map and not _chunk_key in chunk_map:
            continue

        _chunks.add(_chunk_key)

    return list(_chunks)
コード例 #2
0
ファイル: sight.py プロジェクト: lawanfalalu/Reactor-3
def generate_los(life,
                 target,
                 at,
                 source_map,
                 score_callback,
                 invert=False,
                 ignore_starting=False):
    _stime = time.time()
    _cover = {'pos': None, 'score': 9000}

    _x = bad_numbers.clip(at[0] - (SETTINGS['los'] / 2), 0,
                          MAP_SIZE[0] - (SETTINGS['los'] / 2))
    _y = bad_numbers.clip(at[1] - (SETTINGS['los'] / 2), 0,
                          MAP_SIZE[1] - (SETTINGS['los'] / 2))
    _top_left = (_x, _y, at[2])

    target_los = render_fast_los.render_fast_los(at, SETTINGS['los'],
                                                 source_map)

    for pos in render_los.draw_circle(life['pos'][0], life['pos'][1], 30):
        x = pos[0] - _top_left[0]
        y = pos[1] - _top_left[1]

        if pos[0] < 0 or pos[1] < 0 or pos[0] >= MAP_SIZE[0] or pos[
                1] >= MAP_SIZE[0]:
            continue

        if x < 0 or y < 0 or x >= target_los.shape[1] or y >= target_los.shape[
                0]:
            continue

        if life['pos'][0] - _top_left[0] >= target_los.shape[
                1] or life['pos'][1] - _top_left[1] >= target_los.shape[0]:
            continue

        if target_los[life['pos'][1] - _top_left[1], life['pos'][0] -
                      _top_left[0]] == invert and not ignore_starting:
            _cover['pos'] = life['pos'][:]
            return False

        if source_map[pos[0]][pos[1]][at[2] +
                                      1] or source_map[pos[0]][pos[1]][at[2] +
                                                                       2]:
            continue

        if target_los[y, x] == invert:
            #TODO: Additional scores, like distance from target
            _score = score_callback(life, target, pos)

            if _score < _cover['score']:
                _cover['score'] = _score
                _cover['pos'] = list(pos)

    #print time.time()-_stime
    if not _cover['pos']:
        print 'Nowhere to hide', target['life']['name'], _top_left

        return False

    return _cover
コード例 #3
0
ファイル: sight.py プロジェクト: flags/Reactor-3
def _scan_surroundings(center_chunk_key, chunk_size, vision, ignore_chunks=[], chunk_map=WORLD_INFO['chunk_map']):
	_center_chunk_pos = maps.get_chunk(center_chunk_key)['pos']
	#_center_chunk_pos[0] = ((_center_chunk_pos[0]/chunk_size)*chunk_size)+(chunk_size/2)
	#_center_chunk_pos[1] = ((_center_chunk_pos[1]/chunk_size)*chunk_size)+(chunk_size/2)
	_chunks = set()
	_chunk_map = set(chunk_map.keys())
	
	for _x_mod, _y_mod in render_los.draw_circle(0, 0, ((vision*2)/chunk_size)):
		x_mod = _center_chunk_pos[0]+(_x_mod*chunk_size) #(_x_mod/chunk_size)*chunk_size
		y_mod = _center_chunk_pos[1]+(_y_mod*chunk_size)
		#print x_mod, y_mod, _center_chunk_pos
		
		_chunk_key = '%s,%s' % (x_mod, y_mod)
		
		if _chunk_key in _chunks:
			continue
		
		if not ignore_chunks==0 and _chunk_key in ignore_chunks:
			continue
		elif isinstance(ignore_chunks, list):
			ignore_chunks.append(_chunk_key)
		
		if chunk_map and not _chunk_key in chunk_map:
			continue
		
		_chunks.add(_chunk_key)
	
	return list(_chunks)
コード例 #4
0
ファイル: sight.py プロジェクト: lawanfalalu/Reactor-3
def _generate_los(life,
                  target,
                  at,
                  source_map,
                  score_callback,
                  invert=False,
                  ignore_starting=False):
    #Step 1: Locate cover
    _cover = {'pos': None, 'score': 9000}

    #TODO: Unchecked Cython flag
    _x = bad_numbers.clip(at[0] - (MAP_WINDOW_SIZE[0] / 2), 0, MAP_SIZE[0])
    _y = bad_numbers.clip(at[1] - (MAP_WINDOW_SIZE[1] / 2), 0, MAP_SIZE[1])
    _top_left = (_x, _y, at[2])
    target_los = render_los.render_los(source_map,
                                       at,
                                       top_left=_top_left,
                                       no_edge=False)

    for pos in render_los.draw_circle(life['pos'][0], life['pos'][1], 30):
        x = pos[0] - _top_left[0]
        y = pos[1] - _top_left[1]

        if pos[0] < 0 or pos[1] < 0 or pos[0] >= MAP_SIZE[0] or pos[
                1] >= MAP_SIZE[0]:
            continue

        if x < 0 or y < 0 or x >= target_los.shape[1] or y >= target_los.shape[
                0]:
            continue

        if life['pos'][0] - _top_left[0] >= target_los.shape[
                0] or life['pos'][1] - _top_left[1] >= target_los.shape[1]:
            continue

        if target_los[life['pos'][1] - _top_left[1], life['pos'][0] -
                      _top_left[0]] == invert and not ignore_starting:
            _cover['pos'] = life['pos'][:]
            return False

        if source_map[pos[0]][pos[1]][at[2] +
                                      1] or source_map[pos[0]][pos[1]][at[2] +
                                                                       2]:
            continue

        if target_los[y, x] == invert:
            #TODO: Additional scores, like distance from target
            _score = score_callback(life, target['life'], pos)

            if _score < _cover['score']:
                _cover['score'] = _score
                _cover['pos'] = list(pos)

    if not _cover['pos']:
        print 'Nowhere to hide'
        return False

    return _cover
コード例 #5
0
ファイル: effects.py プロジェクト: nathantypanski/Reactor-3
def create_smoke_cloud(pos, size, color=tcod.gray, age=0, factor_distance=False):
	for new_pos in render_los.draw_circle(pos[0], pos[1], size):
		if not gfx.position_is_in_frame(pos):
			continue
		 
		if not alife.sight._can_see_position(pos, new_pos, distance=False):
			continue
		
		_age_mod = 1
		if factor_distance:
			_age_mod = 1-numbers.clip(numbers.distance(pos, new_pos)/float(size), 0.1, 1)
		
		create_smoke(new_pos, color=color, age=age*_age_mod)
コード例 #6
0
ファイル: sight.py プロジェクト: flags/Reactor-3
def generate_los(life, target, at, source_map, score_callback, invert=False, ignore_starting=False):
	_stime = time.time()
	_cover = {'pos': None,'score': 9000}
	
	_x = bad_numbers.clip(at[0]-(SETTINGS['los']/2),0,MAP_SIZE[0]-(SETTINGS['los']/2))
	_y = bad_numbers.clip(at[1]-(SETTINGS['los']/2),0,MAP_SIZE[1]-(SETTINGS['los']/2))
	_top_left = (_x,_y,at[2])
	
	target_los = render_fast_los.render_fast_los(at,
		SETTINGS['los'],
		source_map)
	
	for pos in render_los.draw_circle(life['pos'][0],life['pos'][1],30):
		x = pos[0]-_top_left[0]
		y = pos[1]-_top_left[1]
		
		if pos[0]<0 or pos[1]<0 or pos[0]>=MAP_SIZE[0] or pos[1]>=MAP_SIZE[0]:
			continue
		
		if x<0 or y<0 or x>=target_los.shape[1] or y>=target_los.shape[0]:
			continue
		
		if life['pos'][0]-_top_left[0]>=target_los.shape[1] or life['pos'][1]-_top_left[1]>=target_los.shape[0]:
			continue
		
		if target_los[life['pos'][1]-_top_left[1],life['pos'][0]-_top_left[0]]==invert and not ignore_starting:
			_cover['pos'] = life['pos'][:]
			return False
		
		if source_map[pos[0]][pos[1]][at[2]+1] or source_map[pos[0]][pos[1]][at[2]+2]:
			continue
		
		if target_los[y,x] == invert:
			#TODO: Additional scores, like distance from target
			_score = score_callback(life, target, pos)
			
			if _score<_cover['score']:
				_cover['score'] = _score
				_cover['pos'] = list(pos)
	
	#print time.time()-_stime
	if not _cover['pos']:
		print 'Nowhere to hide', target['life']['name'], _top_left
				
		return False
	
	return _cover
コード例 #7
0
def create_smoke_cloud(pos,
                       size,
                       color=tcod.gray,
                       age=0,
                       factor_distance=False):
    for new_pos in render_los.draw_circle(pos[0], pos[1], size):
        if not gfx.position_is_in_frame(pos):
            continue

        if not alife.sight._can_see_position(pos, new_pos, distance=False):
            continue

        _age_mod = 1
        if factor_distance:
            _age_mod = 1 - numbers.clip(
                numbers.distance(pos, new_pos) / float(size), 0.1, 1)

        create_smoke(new_pos, color=color, age=age * _age_mod)
コード例 #8
0
ファイル: sight.py プロジェクト: flags/Reactor-3
def _generate_los(life,target,at,source_map,score_callback,invert=False,ignore_starting=False):
	#Step 1: Locate cover
	_cover = {'pos': None,'score': 9000}
	
	#TODO: Unchecked Cython flag
	_x = bad_numbers.clip(at[0]-(MAP_WINDOW_SIZE[0]/2),0,MAP_SIZE[0])
	_y = bad_numbers.clip(at[1]-(MAP_WINDOW_SIZE[1]/2),0,MAP_SIZE[1])
	_top_left = (_x,_y,at[2])
	target_los = render_los.render_los(source_map,at,top_left=_top_left,no_edge=False)
	
	for pos in render_los.draw_circle(life['pos'][0],life['pos'][1],30):
		x = pos[0]-_top_left[0]
		y = pos[1]-_top_left[1]
		
		if pos[0]<0 or pos[1]<0 or pos[0]>=MAP_SIZE[0] or pos[1]>=MAP_SIZE[0]:
			continue
		
		if x<0 or y<0 or x>=target_los.shape[1] or y>=target_los.shape[0]:
			continue
		
		if life['pos'][0]-_top_left[0]>=target_los.shape[0] or life['pos'][1]-_top_left[1]>=target_los.shape[1]:
			continue
		
		if target_los[life['pos'][1]-_top_left[1],life['pos'][0]-_top_left[0]]==invert and not ignore_starting:
			_cover['pos'] = life['pos'][:]
			return False
		
		if source_map[pos[0]][pos[1]][at[2]+1] or source_map[pos[0]][pos[1]][at[2]+2]:
			continue
		
		if target_los[y,x] == invert:
			#TODO: Additional scores, like distance from target
			_score = score_callback(life,target['life'],pos)
			
			if _score<_cover['score']:
				_cover['score'] = _score
				_cover['pos'] = list(pos)
	
	if not _cover['pos']:
		print 'Nowhere to hide'		
		return False
	
	return _cover