Ejemplo n.º 1
0
def _cleanup(entity):
    if entity["_id"] in ONLINE_ENTITIES:
        ONLINE_ENTITIES.remove(entity["_id"])

    elif entity["_id"] in OFFLINE_ENTITIES:
        OFFLINE_ENTITIES.remove(entity["_id"])

    _x, _y = movement.get_position(entity)

    if flags.has_flag(entity, "fire_data"):
        _fire_data = flags.get_flag(entity, "fire_data")
        _node = entities.get_entity(zones.get_active_node_grid()[_fire_data["node"]])

        entities.trigger_event(_node, "set_flag", flag="owner", value=None)
        flags.delete_flag(entity, "fire_data")

    _item_id = items.corpse(_x, _y, entity["tile"]["char"], entity["_id"])["_id"]

    entities.trigger_event(entity, "handle_corpse", corpse_id=_item_id)
Ejemplo n.º 2
0
Archivo: ai.py Proyecto: penny64/r3-tdw
def _cleanup(entity):
    if entity['_id'] in ONLINE_ENTITIES:
        ONLINE_ENTITIES.remove(entity['_id'])

    elif entity['_id'] in OFFLINE_ENTITIES:
        OFFLINE_ENTITIES.remove(entity['_id'])

    _x, _y = movement.get_position(entity)

    if flags.has_flag(entity, 'fire_data'):
        _fire_data = flags.get_flag(entity, 'fire_data')
        _node = entities.get_entity(
            zones.get_active_node_grid()[_fire_data['node']])

        entities.trigger_event(_node, 'set_flag', flag='owner', value=None)
        flags.delete_flag(entity, 'fire_data')

    _item_id = items.corpse(_x, _y, entity['tile']['char'],
                            entity['_id'])['_id']

    entities.trigger_event(entity, 'handle_corpse', corpse_id=_item_id)
Ejemplo n.º 3
0
def search_for_target(entity):
	_lost_targets = entity['ai']['targets_to_search']
	_inside = zones.get_active_inside_positions()
	
	if not _lost_targets:
		print 'Trying to search with no lost targets'
		
		return
	
	_closest_target = {'distance': 0, 'target_id': None}
	
	for target_id in _lost_targets:
		_memory = entity['ai']['life_memory'][target_id]
		_distance = numbers.distance(movement.get_position(entity), _memory['last_seen_at'])
		
		if not _closest_target['target_id'] or _distance < _closest_target['distance']:
			_closest_target['target_id'] = target_id
			_closest_target['distance'] = _distance
	
	_target = entities.get_entity(_closest_target['target_id'])
	_solids = zones.get_active_solids(entity)
	
	if flags.has_flag(entity, 'search_nodes'):
		_search_for_target(entity, _target['_id'])
		
		return
	
	_x, _y = movement.get_position(entity)
	_tx, _ty = entity['ai']['life_memory'][_target['_id']]['last_seen_at']
	_nodes_to_search = {}
	
	if entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']:
		_vx, _vy = entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']
		_tx + _vx*6
		_ty + _vy*6
	
	entities.trigger_event(entity, 'set_flag', flag='search_nodes', value=_nodes_to_search)
	
	for node_x, node_y in zones.get_active_node_grid():
		_distance = numbers.distance((_tx, _ty), (node_x, node_y))
		
		if _distance >= 30:
			continue
		
		if not (node_x, node_y) in _inside:
			continue
		
		_continue = False
		
		for pos in shapes.line((_tx, _ty), (node_x, node_y)):
			if pos in _solids:
				_continue = True
				
				break
		
		if _continue:
			continue
		
		if _distance in _nodes_to_search:
			if not (node_x, node_y) in _nodes_to_search[_distance]:
				_nodes_to_search[_distance].append((node_x, node_y))
		else:
			_nodes_to_search[_distance] = [(node_x, node_y)]
Ejemplo n.º 4
0
def draw():
	global MOVIE_TIME, MOVIE_TIME_MAX

	if settings.OBSERVER_MODE:
		_draw_life = entities.get_entity_group('life')
		_draw_items = entities.get_entity_group('items')
	else:
		_draw_life = set()
		_draw_items = 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 = list(_draw_life)

	for entity_id in _draw_life:
		entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	for entity_id in entities.get_entity_group('nodes'):
		entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	if settings.SHOW_NODE_GRID:
		for entity_id in zones.get_active_node_grid().values():
			entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	for entity_id in entities.get_entity_groups(['ui_effects', 'ui_effects_freetick']):
		entities.trigger_event(entities.get_entity(entity_id), 'draw')

	for entity_id in entities.get_entity_groups(['effects', 'effects_freetick']):
		entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	for entity_id in entities.get_entity_group('contexts'):
		entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	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

		entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y)

	ui_draw.draw_status_bar(planning=settings.TICK_MODE == 'strategy',
	                        executing=not settings.TICK_MODE == 'strategy',
	                        execute_speed=settings.PLAN_TICK_RATE_STRING,
	                        selecting=nodes.SELECTING_TARGET_CALLBACK)

	#if settings.TICK_MODE == 'strategy':
	#	ui_draw.draw_item_labels()
	
	if '--labels' in sys.argv:
		ui_draw.draw_life_labels()
	
	ui_draw.draw_long_range_life()
	ui_draw.draw_life_memory()
	ui_draw.draw_walk_path()
	#ui_draw.draw_mission_details()
	ui_draw.draw_turn_bar()

	if '--fps' in sys.argv:
		ui_draw.draw_fps()

	events.trigger_event('post_process')
	
	#display.reset_surface_shaders('tiles')
	
	#_zone = zones.ZONES[zones.ACTIVE_ZONE]	
	#for shader in _zone['shaders']:
	#	display.apply_surface_shader('tiles', shader, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT)
	
	if ui_director.HAS_FOCUS:
		ui_director.draw()
	
	display.blit_surface('effects')
	display.blit_surface('nodes')
	display.blit_surface('items')
	display.blit_surface('life')
	display.blit_surface('ui')
	display.blit_surface('ui_menus')
	display.blit_surface('ui_dialogs')

	if ui_panel.ACTIVE_MENU:
		display.blit_surface_viewport('ui_inventory', 0, 0, 35, constants.MAP_VIEW_HEIGHT, dx=constants.MAP_VIEW_WIDTH-35)

	if settings.SHOW_NODE_GRID:
		display.blit_surface('node_grid')

	events.trigger_event('draw')

	if '--record' in sys.argv:
		MOVIE_TIME += 1
	
		if MOVIE_TIME == MOVIE_TIME_MAX:
			display.screenshot('screenshot-%s.bmp' % time.time())
			
			MOVIE_TIME = 0
Ejemplo n.º 5
0
def draw():
    global MOVIE_TIME, MOVIE_TIME_MAX

    if settings.OBSERVER_MODE:
        _draw_life = entities.get_entity_group('life')
        _draw_items = entities.get_entity_group('items')
    else:
        _draw_life = set()
        _draw_items = 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 = list(_draw_life)

    for entity_id in _draw_life:
        entities.trigger_event(entities.get_entity(entity_id),
                               'draw',
                               x_mod=camera.X,
                               y_mod=camera.Y)

    for entity_id in entities.get_entity_group('nodes'):
        entities.trigger_event(entities.get_entity(entity_id),
                               'draw',
                               x_mod=camera.X,
                               y_mod=camera.Y)

    if settings.SHOW_NODE_GRID:
        for entity_id in zones.get_active_node_grid().values():
            entities.trigger_event(entities.get_entity(entity_id),
                                   'draw',
                                   x_mod=camera.X,
                                   y_mod=camera.Y)

    for entity_id in entities.get_entity_groups(
        ['ui_effects', 'ui_effects_freetick']):
        entities.trigger_event(entities.get_entity(entity_id), 'draw')

    for entity_id in entities.get_entity_groups(
        ['effects', 'effects_freetick']):
        entities.trigger_event(entities.get_entity(entity_id),
                               'draw',
                               x_mod=camera.X,
                               y_mod=camera.Y)

    for entity_id in entities.get_entity_group('contexts'):
        entities.trigger_event(entities.get_entity(entity_id),
                               'draw',
                               x_mod=camera.X,
                               y_mod=camera.Y)

    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

        entities.trigger_event(entities.get_entity(entity_id),
                               'draw',
                               x_mod=camera.X,
                               y_mod=camera.Y)

    ui_draw.draw_status_bar(planning=settings.TICK_MODE == 'strategy',
                            executing=not settings.TICK_MODE == 'strategy',
                            execute_speed=settings.PLAN_TICK_RATE_STRING,
                            selecting=nodes.SELECTING_TARGET_CALLBACK)

    #if settings.TICK_MODE == 'strategy':
    #	ui_draw.draw_item_labels()

    if '--labels' in sys.argv:
        ui_draw.draw_life_labels()

    ui_draw.draw_long_range_life()
    ui_draw.draw_life_memory()
    ui_draw.draw_walk_path()
    #ui_draw.draw_mission_details()
    ui_draw.draw_turn_bar()

    if '--fps' in sys.argv:
        ui_draw.draw_fps()

    events.trigger_event('post_process')

    #display.reset_surface_shaders('tiles')

    #_zone = zones.ZONES[zones.ACTIVE_ZONE]
    #for shader in _zone['shaders']:
    #	display.apply_surface_shader('tiles', shader, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT)

    if ui_director.HAS_FOCUS:
        ui_director.draw()

    display.blit_surface('effects')
    display.blit_surface('nodes')
    display.blit_surface('items')
    display.blit_surface('life')
    display.blit_surface('ui')
    display.blit_surface('ui_menus')
    display.blit_surface('ui_dialogs')

    if ui_panel.ACTIVE_MENU:
        display.blit_surface_viewport('ui_inventory',
                                      0,
                                      0,
                                      35,
                                      constants.MAP_VIEW_HEIGHT,
                                      dx=constants.MAP_VIEW_WIDTH - 35)

    if settings.SHOW_NODE_GRID:
        display.blit_surface('node_grid')

    events.trigger_event('draw')

    if '--record' in sys.argv:
        MOVIE_TIME += 1

        if MOVIE_TIME == MOVIE_TIME_MAX:
            display.screenshot('screenshot-%s.bmp' % time.time())

            MOVIE_TIME = 0
Ejemplo n.º 6
0
def search_for_target(entity):
    _lost_targets = entity['ai']['targets_to_search']
    _inside = zones.get_active_inside_positions()

    if not _lost_targets:
        print 'Trying to search with no lost targets'

        return

    _closest_target = {'distance': 0, 'target_id': None}

    for target_id in _lost_targets:
        _memory = entity['ai']['life_memory'][target_id]
        _distance = numbers.distance(movement.get_position(entity),
                                     _memory['last_seen_at'])

        if not _closest_target[
                'target_id'] or _distance < _closest_target['distance']:
            _closest_target['target_id'] = target_id
            _closest_target['distance'] = _distance

    _target = entities.get_entity(_closest_target['target_id'])
    _solids = zones.get_active_solids(entity)

    if flags.has_flag(entity, 'search_nodes'):
        _search_for_target(entity, _target['_id'])

        return

    _x, _y = movement.get_position(entity)
    _tx, _ty = entity['ai']['life_memory'][_target['_id']]['last_seen_at']
    _nodes_to_search = {}

    if entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']:
        _vx, _vy = entity['ai']['life_memory'][
            _target['_id']]['last_seen_velocity']
        _tx + _vx * 6
        _ty + _vy * 6

    entities.trigger_event(entity,
                           'set_flag',
                           flag='search_nodes',
                           value=_nodes_to_search)

    for node_x, node_y in zones.get_active_node_grid():
        _distance = numbers.distance((_tx, _ty), (node_x, node_y))

        if _distance >= 30:
            continue

        if not (node_x, node_y) in _inside:
            continue

        _continue = False

        for pos in shapes.line((_tx, _ty), (node_x, node_y)):
            if pos in _solids:
                _continue = True

                break

        if _continue:
            continue

        if _distance in _nodes_to_search:
            if not (node_x, node_y) in _nodes_to_search[_distance]:
                _nodes_to_search[_distance].append((node_x, node_y))
        else:
            _nodes_to_search[_distance] = [(node_x, node_y)]