예제 #1
0
파일: nodes.py 프로젝트: witheld9/r3-tdw
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'])
예제 #2
0
파일: ui_draw.py 프로젝트: witheld9/r3-tdw
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)
예제 #3
0
파일: ui_draw.py 프로젝트: penny64/r3-tdw
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)
예제 #4
0
파일: nodes.py 프로젝트: witheld9/r3-tdw
def _create_node(entity, x, y, draw_path=False, passive=True, action_time=0, name='Node', callback_on_touch=True):
	global LAST_CLICKED_POS
	
	_path_index = -1
	
	if LAST_CLICKED_POS:
		_node_positions = [(p['node']['x'], p['node']['y']) for p in entity['node_grid']['nodes'].values() if not p['node']['name'] == chr(31)]
		
		for node_id in entity['node_grid']['path'][:]:
			_last_node = entity['node_grid']['nodes'][node_id]
			
			if LAST_CLICKED_POS in _last_node['node']['path']:
				_move_cost = 0
				
				for pos in _last_node['node']['path'][_last_node['node']['path'].index(LAST_CLICKED_POS):]:
					_move_cost += movement.get_move_cost(entity)
					
					if _move_cost < action_time and pos in _node_positions:
						return
				
				_path_index = entity['node_grid']['path'].index(node_id)
				entity['node_grid']['nodes'][entity['node_grid']['path'][_path_index]]['node']['action_time'] = action_time
				
				break
		
		LAST_CLICKED_POS = None	
	
	_node = entities.create_entity(group='nodes')
	_node['x'] = x
	_node['y'] = y
	_node['name'] = name
	_node['draw_path'] = draw_path
	_node['path'] = []
	_node['owner_id'] = entity['_id']
	_node['action_time'] = action_time
	_node['busy_pos'] = []
	
	tile.register(_node, surface='nodes')	
	entities.trigger_event(_node, 'set_position', x=x, y=y)
		
	if _path_index == -1:
		_path_index = len(entity['node_grid']['path'])
	
	entity['node_grid']['nodes'][_node['_id']] = {'node': _node,
	                                              'passive': passive,
	                                              'callback': None,
	                                              'call_on_touch': callback_on_touch}
	entity['node_grid']['path'].insert(_path_index, _node['_id'])
	
	return _node
예제 #5
0
def draw_raid_info(squad_id, camp_id):
    _camp = world_strategy.MAP['grid'][camp_id]
    _squad = entities.get_entity(squad_id)
    _travel_distance = numbers.distance(movement.get_position_via_id(squad_id),
                                        camp_id)
    _highest_speed = 0
    _cost = ai_squads.get_attack_cost(_squad, camp_id)

    for member_id in _squad['members']:
        _member = entities.get_entity(member_id)
        _speed = movement.get_move_cost(_member)

        if _speed > _highest_speed:
            _highest_speed = _speed

    _travel_time = _travel_distance * (_highest_speed * 80)
    _time_string = '%s hours %s minutes' % (_travel_time / 60, _travel_time -
                                            ((_travel_time / 60) * 60))
    _info = 'Right Click Camp to Confirm Order, ESC to cancel'

    if time.time() % 1 >= .5:
        _info_color = (200, 0, 0)

    else:
        _info_color = (200, 80, 80)

    display.write_string('ui_bar',
                         (constants.WINDOW_WIDTH / 2) - (len(_info) / 2),
                         0,
                         _info,
                         fore_color=_info_color)

    display.write_string('ui_bar',
                         1,
                         1,
                         'Raid Order',
                         fore_color=(200, 50, 70))

    flavor_print(1, 3, [('Risk: ', 'Low', constants.STATUS_GOOD),
                        ('Cost: $ ', '%i' % _cost, constants.STATUS_GOOD),
                        ('Supplies needed: ', '%i' % 12, constants.STATUS_OK),
                        ('Travel time: ', _time_string, constants.STATUS_OK)])

    flavor_print(35, 3, [('Test value: ', 'Low', constants.STATUS_GOOD)])
예제 #6
0
def draw_raid_info(squad_id, camp_id):
    _camp = world_strategy.MAP["grid"][camp_id]
    _squad = entities.get_entity(squad_id)
    _travel_distance = numbers.distance(movement.get_position_via_id(squad_id), camp_id)
    _highest_speed = 0
    _cost = ai_squads.get_attack_cost(_squad, camp_id)

    for member_id in _squad["members"]:
        _member = entities.get_entity(member_id)
        _speed = movement.get_move_cost(_member)

        if _speed > _highest_speed:
            _highest_speed = _speed

    _travel_time = _travel_distance * (_highest_speed * 80)
    _time_string = "%s hours %s minutes" % (_travel_time / 60, _travel_time - ((_travel_time / 60) * 60))
    _info = "Right Click Camp to Confirm Order, ESC to cancel"

    if time.time() % 1 >= 0.5:
        _info_color = (200, 0, 0)

    else:
        _info_color = (200, 80, 80)

    display.write_string("ui_bar", (constants.WINDOW_WIDTH / 2) - (len(_info) / 2), 0, _info, fore_color=_info_color)

    display.write_string("ui_bar", 1, 1, "Raid Order", fore_color=(200, 50, 70))

    flavor_print(
        1,
        3,
        [
            ("Risk: ", "Low", constants.STATUS_GOOD),
            ("Cost: $ ", "%i" % _cost, constants.STATUS_GOOD),
            ("Supplies needed: ", "%i" % 12, constants.STATUS_OK),
            ("Travel time: ", _time_string, constants.STATUS_OK),
        ],
    )

    flavor_print(35, 3, [("Test value: ", "Low", constants.STATUS_GOOD)])
예제 #7
0
파일: nodes.py 프로젝트: penny64/r3-tdw
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'])
예제 #8
0
파일: nodes.py 프로젝트: penny64/r3-tdw
def _create_node(entity,
                 x,
                 y,
                 draw_path=False,
                 passive=True,
                 action_time=0,
                 name='Node',
                 callback_on_touch=True):
    global LAST_CLICKED_POS

    _path_index = -1

    if LAST_CLICKED_POS:
        _node_positions = [(p['node']['x'], p['node']['y'])
                           for p in entity['node_grid']['nodes'].values()
                           if not p['node']['name'] == chr(31)]

        for node_id in entity['node_grid']['path'][:]:
            _last_node = entity['node_grid']['nodes'][node_id]

            if LAST_CLICKED_POS in _last_node['node']['path']:
                _move_cost = 0

                for pos in _last_node['node']['path'][
                        _last_node['node']['path'].index(LAST_CLICKED_POS):]:
                    _move_cost += movement.get_move_cost(entity)

                    if _move_cost < action_time and pos in _node_positions:
                        return

                _path_index = entity['node_grid']['path'].index(node_id)
                entity['node_grid']['nodes'][entity['node_grid']['path'][
                    _path_index]]['node']['action_time'] = action_time

                break

        LAST_CLICKED_POS = None

    _node = entities.create_entity(group='nodes')
    _node['x'] = x
    _node['y'] = y
    _node['name'] = name
    _node['draw_path'] = draw_path
    _node['path'] = []
    _node['owner_id'] = entity['_id']
    _node['action_time'] = action_time
    _node['busy_pos'] = []

    tile.register(_node, surface='nodes')
    entities.trigger_event(_node, 'set_position', x=x, y=y)

    if _path_index == -1:
        _path_index = len(entity['node_grid']['path'])

    entity['node_grid']['nodes'][_node['_id']] = {
        'node': _node,
        'passive': passive,
        'callback': None,
        'call_on_touch': callback_on_touch
    }
    entity['node_grid']['path'].insert(_path_index, _node['_id'])

    return _node