Esempio n. 1
0
def draw_walk_path():
	_walk_path = ui_squad_control.WALK_PATH
	
	if not _walk_path:
		return
	
	_width = display.get_surface('life')['width']
	_height = display.get_surface('life')['height']
	_entity = ui_squad_control.get_selected_squad_member()
	_action_points = _entity['stats']['action_points']
	
	for x, y in _walk_path:
		_x = x - camera.X
		_y = y - camera.Y
		
		if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
			continue
		
		if _action_points < 0:
			_fore_color = (200, 0, 0)
			_char = chr(176)
		
		else:
			_fore_color = (200, 200, 200)
			_char = chr(177)
		
		display.write_char('nodes', _x, _y, _char, fore_color=_fore_color)
		_action_points -= constants.IDLE_COST
		_action_points -= movement.get_move_cost(_entity)
Esempio n. 2
0
def draw_path(entity, x_mod=0, y_mod=0):
	_last_x, _last_y = (0, 0)
	_node_ids = entity['node_grid']['path'][:]
	_action_time_max = 0
	_surface_width = display.get_surface('nodes')['width']
	_surface_height = display.get_surface('nodes')['height']
	
	for node_id in _node_ids:
		_node = entity['node_grid']['nodes'][node_id]
		
		if not _last_x:
			_last_x, _last_y = movement.get_position(entity)
		
		if (_last_x, _last_y) == (_node['node']['x'], _node['node']['y']):
			continue
		
		_node['node']['busy_pos'] = []
		
		if _node['node']['draw_path'] and not _node['node']['path']:
			_path = pathfinding.astar((_last_x, _last_y), (_node['node']['x'], _node['node']['y']), zones.get_active_astar_map(), zones.get_active_weight_map())
			
			if (_node['node']['x'], _node['node']['y']) in _path:
				_path.remove((_node['node']['x'], _node['node']['y']))
			
			_node['node']['path'] = _path
		
		_move_cost = 0
		for pos in _node['node']['path']:
			for node_id in _node_ids:
				_check_node = entity['node_grid']['nodes'][node_id]['node']
				
				if not _check_node['action_time']:
					continue
				
				if (_check_node['x'], _check_node['y']) == pos:
					_action_time_max = _check_node['action_time']
			
			if _action_time_max and _move_cost <= _action_time_max:
				_color_mod = int(round(200*numbers.clip(_move_cost/float(_action_time_max), .75, 1)))
				_color = (_color_mod, 0, 0)
				
				_node['node']['busy_pos'].append(pos)
			
			else:
				_color = (200, 200, 200)
			
			if _action_time_max:
				_move_cost += movement.get_move_cost(entity)
				
				if _move_cost >= _action_time_max:
					_action_time_max = 0
					_move_cost = 0
			
			if pos[0]-x_mod < 0 or pos[1]-y_mod < 0 or pos[0]-x_mod >= _surface_width or pos[1]-y_mod >= _surface_height:
				continue
			
			display.write_char('nodes', pos[0]-x_mod, pos[1]-y_mod, chr(177), fore_color=_color)
		
		if _node['node']['draw_path']:
			_last_x, _last_y = (_node['node']['x'], _node['node']['y'])
Esempio n. 3
0
def draw_item_labels():
	_camera_x, _camera_y = camera.X, camera.Y
	_width = display.get_surface('life')['width']
	_height = display.get_surface('life')['height']
	
	if settings.OBSERVER_MODE:
		_draw_items = entities.get_entity_group('items')
	else:
		_draw_items = [item for _items in PLAYER['ai']['visible_items'].values() for item in _items]
	
	for entity_id in _draw_items:
		if not entity_id in entities.ENTITIES:
			continue
		
		_entity = entities.get_entity(entity_id)
		
		if _entity['stats']['owner']:
			continue
		
		_x, _y = movement.get_position(_entity)
		_x -= _camera_x
		_y -= _camera_y
		
		if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
			continue
		
		_label = _entity['stats']['name']
		_render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label))
		_render_y = numbers.clip(_y + 2, 0, _height)
		
		if _render_y == _y:
			_render_y -= 1
		
		display.write_string('ui', _render_x, _render_y, _label)
Esempio n. 4
0
def draw_walk_path():
    _walk_path = ui_squad_control.WALK_PATH

    if not _walk_path:
        return

    _width = display.get_surface('life')['width']
    _height = display.get_surface('life')['height']
    _entity = ui_squad_control.get_selected_squad_member()
    _action_points = _entity['stats']['action_points']

    for x, y in _walk_path:
        _x = x - camera.X
        _y = y - camera.Y

        if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
            continue

        if _action_points < 0:
            _fore_color = (200, 0, 0)
            _char = chr(176)

        else:
            _fore_color = (200, 200, 200)
            _char = chr(177)

        display.write_char('nodes', _x, _y, _char, fore_color=_fore_color)
        _action_points -= constants.IDLE_COST
        _action_points -= movement.get_move_cost(_entity)
Esempio n. 5
0
def draw_life_memory():
	_camera_x, _camera_y = camera.X, camera.Y
	_width = display.get_surface('life')['width']
	_height = display.get_surface('life')['height']
	_draw_life = set()
	_can_see_life = set()
	_last_seen_locations = {}
		
	for squad_id in entities.get_entity_group('squads'):
		_squad = entities.get_entity(squad_id)
		
		if not _squad['faction'] == 'Rogues':
			continue
		
		for member_id in _squad['members']:
			_member = entities.get_entity(member_id)
			_can_see_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES])
			_draw_life.update(_member['ai']['targets'] - _member['ai']['visible_life'])
			
			for memory_id in _member['ai']['life_memory'].keys():
				if not member_id in _last_seen_locations and _member['ai']['life_memory'][memory_id]['last_seen_at']:
					_last_seen_locations[memory_id] = _member['ai']['life_memory'][memory_id]['last_seen_at']
	
	_draw_life = list(_draw_life)

	for entity_id in _draw_life:
		if entity_id in _can_see_life or not entity_id in entities.ENTITIES:
			continue
		
		if not entity_id in _last_seen_locations:
			continue
		
		_entity = entities.get_entity(entity_id)
		_x, _y = _last_seen_locations[entity_id]
		_x -= _camera_x
		_y -= _camera_y
		
		if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
			continue
		
		if time.time() % 1 >= .5:
			_char = _entity['tile']['char']
			_fore_color = _entity['tile']['fore_color']
		else:
			_char = '!'
			_fore_color = (255, 0, 0)
		
		_render_x = numbers.clip(_x - len(_char)/2, 0, _width - len(_char) - 1)
		_render_y = numbers.clip(_y, 0, _height)
		
		#if _x - len(_char)/2 < 0 or _x + len(_char)/2 >= _width:
		#	continue
		
		if _render_y == _y:
			_render_y += 2
		
		display.write_string('ui', _render_x, _render_y, _char, fore_color=_fore_color)
Esempio n. 6
0
def draw_long_range_life():
	_camera_x, _camera_y = camera.X, camera.Y
	_width = display.get_surface('life')['width']
	_height = display.get_surface('life')['height']
	_draw_life_targets = set()
	
	if settings.OBSERVER_MODE:
		_draw_life = entities.get_entity_group('life')
	else:
		_draw_life = set()
		
		for squad_id in entities.get_entity_group('squads'):
			_squad = entities.get_entity(squad_id)
			
			if not _squad['faction'] == 'Rogues':
				continue
			
			for member_id in _squad['members']:
				_member = entities.get_entity(member_id)
				_draw_life.add(member_id)
				_draw_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES])
				_draw_life_targets.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and _member['ai']['life_memory'][i]['is_target'] and i in entities.ENTITIES])
		
		_draw_life = list(_draw_life)
	
	for entity_id in _draw_life:
		_entity = entities.get_entity(entity_id)
		_x, _y = movement.get_position(_entity)
		_x -= _camera_x
		_y -= _camera_y
		
		if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
			_x = numbers.clip(_x, 0, _width-1)
			_y = numbers.clip(_y, 0, _height-1)
		else:
			continue
		
		if time.time() % 1 >= .5:
			_char = 'X'
		else:
			_char = 'O'
		
		if entity_id in _draw_life_targets:
			_fore_color = (255, 0, 0)
			_back_color = (100, 0, 0)
		else:
			_fore_color = (255, 255, 255)
			_back_color = (100, 100, 100)
		
		display.write_string('ui', _x, _y, _char, fore_color=_fore_color, back_color=_back_color)
Esempio n. 7
0
def post_process_clouds(width, height, passes, noise, inside):
	global CLOUD_X, CLOUD_Y
	
	_clouds = numpy.zeros((height, width))
	_clouds += 1.6
	_zoom = 2.0
	_clouds_x = (display.get_surface('tiles')['start_x']*.016)+CLOUD_X
	_clouds_y = (display.get_surface('tiles')['start_y']*.016)+(CLOUD_X * -.5)
	_size = 100.0
	_sunlight = SUNLIGHT
	
	if settings.TICK_MODE == 'normal':
		CLOUD_X -= numbers.clip(.003 * (settings.PLAN_TICK_RATE * .75), .003, 1)
	
	#HUGE decrease in FPS when using workers
	'''_worker = workers.counter_2d(width,
Esempio n. 8
0
def draw_life_labels():
    _camera_x, _camera_y = camera.X, camera.Y
    _width = display.get_surface('life')['width']
    _height = display.get_surface('life')['height']

    if settings.OBSERVER_MODE:
        _draw_life = entities.get_entity_group('life')
    else:
        _draw_life = [
            i for i in PLAYER['ai']['life_memory']
            if PLAYER['ai']['life_memory'][i]['can_see']
        ]

        if PLAYER['_id'] in entities.ENTITIES:
            _draw_life.append(PLAYER['_id'])

    for entity_id in _draw_life:
        _entity = entities.get_entity(entity_id)
        _x, _y = movement.get_position(_entity)
        _x -= _camera_x
        _y -= _camera_y

        if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
            continue

        _back_color = None

        if settings.OBSERVER_MODE:
            _label = _entity['ai']['current_action']
        else:
            _label = life.get_status_string(_entity)

            if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][
                    entity_id]['mission_related'] and time.time() % 1 >= .5:
                _back_color = (200, 0, 0)

        _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label))
        _render_y = numbers.clip(_y - 2, 0, _height)

        if _render_y == _y:
            _render_y += 2

        display.write_string('ui',
                             _render_x,
                             _render_y,
                             _label,
                             back_color=_back_color)
Esempio n. 9
0
def render_map(tile_map, width, height):
	_surface = display.get_surface('tiles')
	
	for y in range(height):
		for x in range(width):
			_tile = tile_map[y][x]
			
			display._set_char('tiles', _tile['x'], _tile['y'], _tile['c'], _tile['c_f'], _tile['c_b'])
Esempio n. 10
0
def post_process_clouds(width, height, passes, noise, inside):
    global CLOUD_X, CLOUD_Y

    _clouds = numpy.zeros((height, width))
    _clouds += 1.6
    _zoom = 2.0
    _clouds_x = (display.get_surface('tiles')['start_x'] * .016) + CLOUD_X
    _clouds_y = (display.get_surface('tiles')['start_y'] * .016) + (CLOUD_X *
                                                                    -.5)
    _size = 100.0
    _sunlight = SUNLIGHT

    if settings.TICK_MODE == 'normal':
        CLOUD_X -= numbers.clip(.003 * (settings.PLAN_TICK_RATE * .75), .003,
                                1)

    #HUGE decrease in FPS when using workers
    '''_worker = workers.counter_2d(width,
Esempio n. 11
0
def draw_life_labels():
	_camera_x, _camera_y = camera.X, camera.Y
	_width = display.get_surface('life')['width']
	_height = display.get_surface('life')['height']
	
	if settings.OBSERVER_MODE:
		_draw_life = entities.get_entity_group('life')
	else:
		_draw_life = [i for i in PLAYER['ai']['life_memory'] if PLAYER['ai']['life_memory'][i]['can_see']]
		
		if PLAYER['_id'] in entities.ENTITIES:
			_draw_life.append(PLAYER['_id'])
	
	for entity_id in _draw_life:
		_entity = entities.get_entity(entity_id)
		_x, _y = movement.get_position(_entity)
		_x -= _camera_x
		_y -= _camera_y
		
		if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
			continue
		
		_back_color = None
		
		if settings.OBSERVER_MODE:
			_label = _entity['ai']['current_action']
		else:
			_label = life.get_status_string(_entity)
			
			if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][entity_id]['mission_related'] and time.time() % 1 >= .5:
				_back_color = (200, 0, 0)
		
		_render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label))
		_render_y = numbers.clip(_y - 2, 0, _height)
		
		if _render_y == _y:
			_render_y += 2
		
		display.write_string('ui', _render_x, _render_y, _label, back_color=_back_color)
Esempio n. 12
0
def draw_item_labels():
    _camera_x, _camera_y = camera.X, camera.Y
    _width = display.get_surface('life')['width']
    _height = display.get_surface('life')['height']

    if settings.OBSERVER_MODE:
        _draw_items = entities.get_entity_group('items')
    else:
        _draw_items = [
            item for _items in PLAYER['ai']['visible_items'].values()
            for item in _items
        ]

    for entity_id in _draw_items:
        if not entity_id in entities.ENTITIES:
            continue

        _entity = entities.get_entity(entity_id)

        if _entity['stats']['owner']:
            continue

        _x, _y = movement.get_position(_entity)
        _x -= _camera_x
        _y -= _camera_y

        if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
            continue

        _label = _entity['stats']['name']
        _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label))
        _render_y = numbers.clip(_y + 2, 0, _height)

        if _render_y == _y:
            _render_y -= 1

        display.write_string('ui', _render_x, _render_y, _label)
Esempio n. 13
0
def draw_path(entity, x_mod=0, y_mod=0):
    _last_x, _last_y = (0, 0)
    _node_ids = entity['node_grid']['path'][:]
    _action_time_max = 0
    _surface_width = display.get_surface('nodes')['width']
    _surface_height = display.get_surface('nodes')['height']

    for node_id in _node_ids:
        _node = entity['node_grid']['nodes'][node_id]

        if not _last_x:
            _last_x, _last_y = movement.get_position(entity)

        if (_last_x, _last_y) == (_node['node']['x'], _node['node']['y']):
            continue

        _node['node']['busy_pos'] = []

        if _node['node']['draw_path'] and not _node['node']['path']:
            _path = pathfinding.astar((_last_x, _last_y),
                                      (_node['node']['x'], _node['node']['y']),
                                      zones.get_active_astar_map(),
                                      zones.get_active_weight_map())

            if (_node['node']['x'], _node['node']['y']) in _path:
                _path.remove((_node['node']['x'], _node['node']['y']))

            _node['node']['path'] = _path

        _move_cost = 0
        for pos in _node['node']['path']:
            for node_id in _node_ids:
                _check_node = entity['node_grid']['nodes'][node_id]['node']

                if not _check_node['action_time']:
                    continue

                if (_check_node['x'], _check_node['y']) == pos:
                    _action_time_max = _check_node['action_time']

            if _action_time_max and _move_cost <= _action_time_max:
                _color_mod = int(
                    round(200 * numbers.clip(
                        _move_cost / float(_action_time_max), .75, 1)))
                _color = (_color_mod, 0, 0)

                _node['node']['busy_pos'].append(pos)

            else:
                _color = (200, 200, 200)

            if _action_time_max:
                _move_cost += movement.get_move_cost(entity)

                if _move_cost >= _action_time_max:
                    _action_time_max = 0
                    _move_cost = 0

            if pos[0] - x_mod < 0 or pos[1] - y_mod < 0 or pos[
                    0] - x_mod >= _surface_width or pos[
                        1] - y_mod >= _surface_height:
                continue

            display.write_char('nodes',
                               pos[0] - x_mod,
                               pos[1] - y_mod,
                               chr(177),
                               fore_color=_color)

        if _node['node']['draw_path']:
            _last_x, _last_y = (_node['node']['x'], _node['node']['y'])
Esempio n. 14
0
def draw_long_range_life():
    _camera_x, _camera_y = camera.X, camera.Y
    _width = display.get_surface('life')['width']
    _height = display.get_surface('life')['height']
    _draw_life_targets = set()

    if settings.OBSERVER_MODE:
        _draw_life = entities.get_entity_group('life')
    else:
        _draw_life = set()

        for squad_id in entities.get_entity_group('squads'):
            _squad = entities.get_entity(squad_id)

            if not _squad['faction'] == 'Rogues':
                continue

            for member_id in _squad['members']:
                _member = entities.get_entity(member_id)
                _draw_life.add(member_id)
                _draw_life.update([
                    i for i in _member['ai']['life_memory']
                    if _member['ai']['life_memory'][i]['can_see']
                    and i in entities.ENTITIES
                ])
                _draw_life_targets.update([
                    i for i in _member['ai']['life_memory']
                    if _member['ai']['life_memory'][i]['can_see']
                    and _member['ai']['life_memory'][i]['is_target']
                    and i in entities.ENTITIES
                ])

        _draw_life = list(_draw_life)

    for entity_id in _draw_life:
        _entity = entities.get_entity(entity_id)
        _x, _y = movement.get_position(_entity)
        _x -= _camera_x
        _y -= _camera_y

        if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
            _x = numbers.clip(_x, 0, _width - 1)
            _y = numbers.clip(_y, 0, _height - 1)
        else:
            continue

        if time.time() % 1 >= .5:
            _char = 'X'
        else:
            _char = 'O'

        if entity_id in _draw_life_targets:
            _fore_color = (255, 0, 0)
            _back_color = (100, 0, 0)
        else:
            _fore_color = (255, 255, 255)
            _back_color = (100, 100, 100)

        display.write_string('ui',
                             _x,
                             _y,
                             _char,
                             fore_color=_fore_color,
                             back_color=_back_color)
Esempio n. 15
0
def draw_life_memory():
    _camera_x, _camera_y = camera.X, camera.Y
    _width = display.get_surface('life')['width']
    _height = display.get_surface('life')['height']
    _draw_life = set()
    _can_see_life = set()
    _last_seen_locations = {}

    for squad_id in entities.get_entity_group('squads'):
        _squad = entities.get_entity(squad_id)

        if not _squad['faction'] == 'Rogues':
            continue

        for member_id in _squad['members']:
            _member = entities.get_entity(member_id)
            _can_see_life.update([
                i for i in _member['ai']['life_memory']
                if _member['ai']['life_memory'][i]['can_see']
                and i in entities.ENTITIES
            ])
            _draw_life.update(_member['ai']['targets'] -
                              _member['ai']['visible_life'])

            for memory_id in _member['ai']['life_memory'].keys():
                if not member_id in _last_seen_locations and _member['ai'][
                        'life_memory'][memory_id]['last_seen_at']:
                    _last_seen_locations[memory_id] = _member['ai'][
                        'life_memory'][memory_id]['last_seen_at']

    _draw_life = list(_draw_life)

    for entity_id in _draw_life:
        if entity_id in _can_see_life or not entity_id in entities.ENTITIES:
            continue

        if not entity_id in _last_seen_locations:
            continue

        _entity = entities.get_entity(entity_id)
        _x, _y = _last_seen_locations[entity_id]
        _x -= _camera_x
        _y -= _camera_y

        if _x < 0 or _y < 0 or _x >= _width or _y >= _height:
            continue

        if time.time() % 1 >= .5:
            _char = _entity['tile']['char']
            _fore_color = _entity['tile']['fore_color']
        else:
            _char = '!'
            _fore_color = (255, 0, 0)

        _render_x = numbers.clip(_x - len(_char) / 2, 0,
                                 _width - len(_char) - 1)
        _render_y = numbers.clip(_y, 0, _height)

        #if _x - len(_char)/2 < 0 or _x + len(_char)/2 >= _width:
        #	continue

        if _render_y == _y:
            _render_y += 2

        display.write_string('ui',
                             _render_x,
                             _render_y,
                             _char,
                             fore_color=_fore_color)