예제 #1
0
def handle_input():
    global _DEBUG_ORD, SELECTED_CAMP, SELECTED_SQUAD

    events.trigger_event('input')

    if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
        if not DRAW_MODE == 'news':
            if SELECTED_SQUAD:
                SELECTED_SQUAD = None

                if SELECTED_CAMP:
                    set_draw_mode('camp_info')

                else:
                    set_draw_mode('news')

            else:
                SELECTED_SQUAD = None
                SELECTED_CAMP = None

                set_draw_mode('news')

        else:
            return False

    if controls.get_input_char_pressed('z'):
        _DEBUG_ORD -= 1
        print _DEBUG_ORD

    elif controls.get_input_char_pressed('x'):
        _DEBUG_ORD += 1
        print _DEBUG_ORD

    return True
def test_state_events():
    module_engine.load_module("framework.tests.resources.state_events.testMod1")
    mod1 = module_engine.get_modules("test1")
    assert mod1.index is 1
    events.trigger_event("test", "tester")
    time.sleep(.1)
    assert mod1.index is 2
    mod1.reset()
    assert mod1.index is 1
    events.start_event("test", "Tester")
    time.sleep(.1)
    assert mod1.index is 2
    mod1.reset()
    assert mod1.index is 1
    events.repeat_callbacks("test1")
    time.sleep(.1)
    assert mod1.index is 2
    events.stop_event("test", "Tester")
    time.sleep(.1)
    mod1.reset()
    assert mod1.index is 1
    events.repeat_callbacks("test")
    time.sleep(.1)
    assert mod1.index is 1
    module_engine.kill_all_modules()
    events.remove_callbacks()
예제 #3
0
def handle_input():
	global _DEBUG_ORD, SELECTED_CAMP, SELECTED_SQUAD
	
	events.trigger_event('input')
	
	if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
		if not DRAW_MODE == 'news':
			if SELECTED_SQUAD:
				SELECTED_SQUAD = None
				
				if SELECTED_CAMP:
					set_draw_mode('camp_info')
				
				else:
					set_draw_mode('news')
			
			else:
				SELECTED_SQUAD = None
				SELECTED_CAMP = None
				
				set_draw_mode('news')
		
		else:
			return False
	
	if controls.get_input_char_pressed('z'):
		_DEBUG_ORD -= 1
		print _DEBUG_ORD
	
	elif controls.get_input_char_pressed('x'):
		_DEBUG_ORD += 1
		print _DEBUG_ORD
	
	return True
예제 #4
0
def loop():
    if not handle_input():
        return False

    tick()
    draw()

    events.trigger_event("draw")
    return True
예제 #5
0
def loop():
    if not handle_input():
        return False

    tick()
    draw()

    events.trigger_event('draw')
    return True
예제 #6
0
def loop():
    global UNSCRAMBLE_TO, WHITE_VALUE, SUBTITLE_COLOR

    for i in range(len(COMPANY_STRING)):
        if i > UNSCRAMBLE_TO:
            _char = random.choice(COMPANY_STRING)
            _gray_color = int(round(255 * (UNSCRAMBLE_TO / i))) + random.randint(-15, 15)
            _fore_color = (_gray_color, _gray_color, _gray_color)

        else:
            _char = COMPANY_STRING[i]
            _r = numbers.clip(WHITE_VALUE - random.randint(0, 90), 0, 255)
            _g = _r
            _b = _r

            _fore_color = _r, _g, _b

        display.write_char(
            "text",
            (constants.WINDOW_WIDTH / 2) + i - (len(COMPANY_STRING) / 2),
            (constants.WINDOW_HEIGHT / 2) - 1,
            _char,
            fore_color=_fore_color,
        )

    display.write_string(
        "text",
        (constants.WINDOW_WIDTH / 2) - (len(SUBTITLE_TEXT) / 2),
        (constants.WINDOW_HEIGHT / 2) + 1,
        SUBTITLE_TEXT,
        fore_color=(SUBTITLE_COLOR, SUBTITLE_COLOR, SUBTITLE_COLOR),
    )

    if UNSCRAMBLE_TO > 6:
        SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR + 2, 0, 255)

    if UNSCRAMBLE_TO > 25:
        WHITE_VALUE -= 2

        SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR - 6, 0, 255)

    if UNSCRAMBLE_TO > 38:
        return False

    display.blit_surface("text")

    events.trigger_event("draw")

    UNSCRAMBLE_TO += 0.1

    return True
예제 #7
0
def loop():
    global UNSCRAMBLE_TO, WHITE_VALUE, SUBTITLE_COLOR

    for i in range(len(COMPANY_STRING)):
        if i > UNSCRAMBLE_TO:
            _char = random.choice(COMPANY_STRING)
            _gray_color = int(round(
                255 * (UNSCRAMBLE_TO / i))) + random.randint(-15, 15)
            _fore_color = (_gray_color, _gray_color, _gray_color)

        else:
            _char = COMPANY_STRING[i]
            _r = numbers.clip(WHITE_VALUE - random.randint(0, 90), 0, 255)
            _g = _r
            _b = _r

            _fore_color = _r, _g, _b

        display.write_char('text', (constants.WINDOW_WIDTH / 2) + i -
                           (len(COMPANY_STRING) / 2),
                           (constants.WINDOW_HEIGHT / 2) - 1,
                           _char,
                           fore_color=_fore_color)

    display.write_string(
        'text', (constants.WINDOW_WIDTH / 2) - (len(SUBTITLE_TEXT) / 2),
        (constants.WINDOW_HEIGHT / 2) + 1,
        SUBTITLE_TEXT,
        fore_color=(SUBTITLE_COLOR, SUBTITLE_COLOR, SUBTITLE_COLOR))

    if UNSCRAMBLE_TO > 6:
        SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR + 2, 0, 255)

    if UNSCRAMBLE_TO > 25:
        WHITE_VALUE -= 2

        SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR - 6, 0, 255)

    if UNSCRAMBLE_TO > 38:
        return False

    display.blit_surface('text')

    events.trigger_event('draw')

    UNSCRAMBLE_TO += .1

    return True
예제 #8
0
def handle_input():
    events.trigger_event('input')

    if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
        return False

    if controls.get_input_char_pressed('\r'):
        return False

    elif controls.get_input_char_pressed(' '):
        roll()

    elif controls.get_input_char_pressed('k'):
        display.screenshot('screenshot-%s.bmp' % time.time())

    return True
예제 #9
0
def handle_input():
	events.trigger_event('input')
	
	if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
		return False
	
	if controls.get_input_char_pressed('\r'):
		return False
	
	elif controls.get_input_char_pressed(' '):
		roll()
	
	elif controls.get_input_char_pressed('k'):
		display.screenshot('screenshot-%s.bmp' % time.time())
	
	return True
def test_basic_events():
    module_engine.load_module("framework.tests.resources.basic_events.testMod1")
    module_engine.load_module("framework.tests.resources.basic_events.testMod2")
    mod1 = module_engine.get_modules("test1")
    mod2 = module_engine.get_modules("test2")
    assert mod1.index is 1
    mod1.set_callback()
    assert mod1.index is 1
    mod2.fireEvent()
    time.sleep(.1)
    assert mod1.index is 2
    events.trigger_event("test", "tester")
    time.sleep(.1)
    assert mod1.index is 3
    module_engine.kill_all_modules()
    events.remove_callbacks()
예제 #11
0
def _start_battle(attacking_squads=[], defending_squads=[]):
	global FADER
	
	create()
	
	_width, _height, _node_grid, _node_sets, _weight_map, _tile_map, _solids, _fsl, _trees, _inside, _lights, _spawns = mapgen_arena.generate(200, 200)
	_zone = zones.create('swamps', _width, _height, _node_grid, _node_sets, _weight_map, _tile_map, _solids, _fsl, _trees, _inside, _lights, _spawns)
	_attacking_spawn_x, _attacking_spawn_y = random.choice(list(_spawns['attacking']))
	_attacking_spawn_positions = [(x, y) for x, y in shapes.circle(_attacking_spawn_x, _attacking_spawn_y, 5) if not (x, y) in _solids]
	
	for squad_id in attacking_squads:
		_squad = entities.get_entity(squad_id)
		
		for member_id in _squad['members']:
			_member = entities.get_entity(member_id)
			_spawn_x, _spawn_y = _attacking_spawn_positions.pop(random.randint(0, len(_attacking_spawn_positions) - 1))
			
			entities.trigger_event(_member, 'set_position', x=_spawn_x, y=_spawn_y)
	
	_defending_spawn_x, _defending_spawn_y = random.choice(list(_spawns['defending']))
	_attacking_spawn_positions = [(x, y) for x, y in shapes.circle(_defending_spawn_x, _defending_spawn_y, 5) if not (x, y) in _solids]
	
	for squad_id in defending_squads:
		_squad = entities.get_entity(squad_id)
		
		for member_id in _squad['members']:
			_member = entities.get_entity(member_id)
			_spawn_x, _spawn_y = _attacking_spawn_positions.pop(random.randint(0, len(_attacking_spawn_positions) - 1))
			
			entities.trigger_event(_member, 'set_position', x=_spawn_x, y=_spawn_y)

	zones.activate(_zone)
	
	FADER = entities.create_entity()
	timers.register(FADER)
	fade_in()
	
	display.blit_background('tiles')
	
	while loop():
		events.trigger_event('cleanup')
예제 #12
0
def draw():
    if SELECTED_SQUAD:
        _x, _y = movement.get_position(entities.get_entity(SELECTED_SQUAD))
        _selected_grid = _x, _y

    else:
        _selected_grid = None

    ui_strategy.draw_map_grid(selected_grid=_selected_grid,
                              fade=FADE_VALUE / 255.0)
    ui_strategy.draw_squads(selected_squad=SELECTED_SQUAD)
    ui_strategy.draw_time()
    ui_strategy.draw_money()

    if DRAW_MODE == 'squad_info':
        ui_strategy.draw_squad_info(SELECTED_SQUAD)

    elif DRAW_MODE == 'camp_info':
        ui_strategy.draw_camp_info(SELECTED_CAMP)

    elif DRAW_MODE == 'news':
        ui_strategy.draw_news(NEWS)

    elif DRAW_MODE == 'raid':
        ui_strategy.draw_raid_info(SELECTED_SQUAD, SELECTED_CAMP)
        ui_strategy.draw_raid_path(MAP_PATH)

        display.blit_surface('map_path')

    display.blit_surface('map_markers')
    display.blit_surface('map_squads')
    display.blit_surface_viewport('ui_bar',
                                  0,
                                  0,
                                  constants.WINDOW_WIDTH,
                                  constants.WINDOW_HEIGHT -
                                  constants.STRAT_MAP_HEIGHT,
                                  dy=constants.STRAT_MAP_HEIGHT)

    events.trigger_event('draw')
    display.reset_surface_shaders('map')
    def run(self, task):
        #Configure the navigator and mark position
        self.navigator_config_stream.push({"max_values": [5, 2], "cycles_per_second": 60, "precision": .2}, self.subsystem, autolock=True)
        events.trigger_event("drivetrain.mark", self.subsystem)
        time.sleep(.05)

        #Get the autonomous config
        config = self.autonomous_config_stream.get({"distance_from_tape": 10})

        #Set the navigator's goal and let it run!
        self.navigator_goals_stream.push([(0, config["distance_from_tape"])], self.subsystem, autolock=True)
        events.start_event("navigator.run", self.subsystem)
        time.sleep(.05)

        #Wait for it to finish
        while task.active and self.navigator_status_stream.get(1) is 0:
            time.sleep(.5)

        #Stop it and check for errors
        events.stop_event("navigator.run", self.subsystem)
        if self.navigator_status_stream.get(1) is -1:
            raise Exception("Error in navigator execution")
예제 #14
0
def draw():
	if SELECTED_SQUAD:
		_x, _y = movement.get_position(entities.get_entity(SELECTED_SQUAD))
		_selected_grid = _x, _y
	
	else:
		_selected_grid = None
	
	ui_strategy.draw_map_grid(selected_grid=_selected_grid, fade=FADE_VALUE/255.0)
	ui_strategy.draw_squads(selected_squad=SELECTED_SQUAD)	
	ui_strategy.draw_time()
	ui_strategy.draw_money()
	
	if DRAW_MODE == 'squad_info':
		ui_strategy.draw_squad_info(SELECTED_SQUAD)
	
	elif DRAW_MODE == 'camp_info':
		ui_strategy.draw_camp_info(SELECTED_CAMP)
	
	elif DRAW_MODE == 'news':
		ui_strategy.draw_news(NEWS)
	
	elif DRAW_MODE == 'raid':
		ui_strategy.draw_raid_info(SELECTED_SQUAD, SELECTED_CAMP)
		ui_strategy.draw_raid_path(MAP_PATH)
		
		display.blit_surface('map_path')
	
	display.blit_surface('map_markers')
	display.blit_surface('map_squads')
	display.blit_surface_viewport('ui_bar',
	                              0,
	                              0,
	                              constants.WINDOW_WIDTH,
	                              constants.WINDOW_HEIGHT-constants.STRAT_MAP_HEIGHT,
	                              dy=constants.STRAT_MAP_HEIGHT)
	
	events.trigger_event('draw')
	display.reset_surface_shaders('map')
예제 #15
0
def handle_input():
    global MENU_ITEM_SELECTED

    events.trigger_event("input")

    if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
        return False

    if controls.get_input_char_pressed("s"):
        MENU_ITEM_SELECTED += 1

    elif controls.get_input_char_pressed("w"):
        MENU_ITEM_SELECTED -= 1

    MENU_ITEM_SELECTED = numbers.clip(MENU_ITEM_SELECTED, 0, 2)

    if controls.get_input_char_pressed("\r"):
        return False

    if controls.get_input_char_pressed("k"):
        display.screenshot("screenshot-%s.bmp" % time.time())

    return True
예제 #16
0
def handle_input():
    global MENU_ITEM_SELECTED

    events.trigger_event('input')

    if controls.get_input_ord_pressed(constants.KEY_ESCAPE):
        return False

    if controls.get_input_char_pressed('s'):
        MENU_ITEM_SELECTED += 1

    elif controls.get_input_char_pressed('w'):
        MENU_ITEM_SELECTED -= 1

    MENU_ITEM_SELECTED = numbers.clip(MENU_ITEM_SELECTED, 0, 2)

    if controls.get_input_char_pressed('\r'):
        return False

    if controls.get_input_char_pressed('k'):
        display.screenshot('screenshot-%s.bmp' % time.time())

    return True
예제 #17
0
def main():
    if not '--dev' in sys.argv:
        #world_action.create()
        world_intro.create()

        #while world_intro.loop():
        #	events.trigger_event('cleanup')

        world_menu.create()

        while world_menu.loop():
            events.trigger_event('cleanup')

    #world_hire.create()

    #while world_hire.loop():
    #	events.trigger_event('cleanup')

    world_strategy.create()

    while world_strategy.loop():
        events.trigger_event('cleanup')

    framework.shutdown()
예제 #18
0
파일: main.py 프로젝트: witheld9/r3-tdw
def main():
	if not '--dev' in sys.argv:
		#world_action.create()
		world_intro.create()
		
		#while world_intro.loop():
		#	events.trigger_event('cleanup')
		
		world_menu.create()
		
		while world_menu.loop():
			events.trigger_event('cleanup')
	
	#world_hire.create()
	
	#while world_hire.loop():
	#	events.trigger_event('cleanup')
	
	world_strategy.create()	
	
	while world_strategy.loop():
		events.trigger_event('cleanup')

	framework.shutdown()
 def fireEvent(self):
     events.trigger_event("test", self.subsystem)
예제 #20
0
def _start_battle(attacking_squads=[], defending_squads=[]):
    global FADER

    create()

    _width, _height, _node_grid, _node_sets, _weight_map, _tile_map, _solids, _fsl, _trees, _inside, _lights, _spawns = mapgen_arena.generate(
        200, 200)
    _zone = zones.create('swamps', _width, _height, _node_grid, _node_sets,
                         _weight_map, _tile_map, _solids, _fsl, _trees,
                         _inside, _lights, _spawns)
    _attacking_spawn_x, _attacking_spawn_y = random.choice(
        list(_spawns['attacking']))
    _attacking_spawn_positions = [
        (x, y)
        for x, y in shapes.circle(_attacking_spawn_x, _attacking_spawn_y, 5)
        if not (x, y) in _solids
    ]

    for squad_id in attacking_squads:
        _squad = entities.get_entity(squad_id)

        for member_id in _squad['members']:
            _member = entities.get_entity(member_id)
            _spawn_x, _spawn_y = _attacking_spawn_positions.pop(
                random.randint(0,
                               len(_attacking_spawn_positions) - 1))

            entities.trigger_event(_member,
                                   'set_position',
                                   x=_spawn_x,
                                   y=_spawn_y)

    _defending_spawn_x, _defending_spawn_y = random.choice(
        list(_spawns['defending']))
    _attacking_spawn_positions = [
        (x, y)
        for x, y in shapes.circle(_defending_spawn_x, _defending_spawn_y, 5)
        if not (x, y) in _solids
    ]

    for squad_id in defending_squads:
        _squad = entities.get_entity(squad_id)

        for member_id in _squad['members']:
            _member = entities.get_entity(member_id)
            _spawn_x, _spawn_y = _attacking_spawn_positions.pop(
                random.randint(0,
                               len(_attacking_spawn_positions) - 1))

            entities.trigger_event(_member,
                                   'set_position',
                                   x=_spawn_x,
                                   y=_spawn_y)

    zones.activate(_zone)

    FADER = entities.create_entity()
    timers.register(FADER)
    fade_in()

    display.blit_background('tiles')

    while loop():
        events.trigger_event('cleanup')
예제 #21
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
예제 #22
0
def loop():
    global PLAYER_HAS_SHOOT_TIMER

    events.trigger_event('input')

    if not settings.TICK_MODE == 'strategy' and not (
        (ui_dialog.ACTIVE_DIALOG and ui_director.PAUSE) or ui_menu.ACTIVE_MENU
            or ui_director.PAUSE):
        _has_action = False

        _check_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)

                _check_life.add(member_id)
                _check_life.update([
                    i for i in _member['ai']['life_memory']
                    if _member['ai']['life_memory'][i]['can_see']
                    and i in entities.ENTITIES
                ])

        _check_life = list(_check_life)

        #_check_life =
        #_check_life.append(PLAYER['_id'])

        for entity_id in _check_life:
            if timers.has_timer_with_name(entities.get_entity(entity_id),
                                          'shoot'):
                _has_action = True

                break

        if _has_action:
            _ticks_per_tick = 1

        else:
            _ticks_per_tick = settings.PLAN_TICK_RATE

        for _ in range(_ticks_per_tick):
            if settings.TICK_MODE == 'strategy':
                break

            ai_flow.logic()
            events.trigger_event('logic')
            tick()
            free_tick()

    else:
        ai_flow.logic()
        free_tick()

    if pathfinding.wait_for_astar():
        pass

    if not handle_input():
        return False

    events.trigger_event('tick')
    events.trigger_event('camera')

    draw()

    return True
예제 #23
0
    def run(self, task):
        auto_start_time = time.time()

        try:
            #Get auto config
            config = self.autonomous_config.get({"second_shot": 7, "first_shot": 12, "distance_from_tape": 3, "start_position": 1})

            #Configure navigator
            self.navigator_config.push({"max_values": [5, 5], "cycles_per_second": 10, "precision": .2}, self.subsystem, autolock=True)

            #Mark drivetrain
            events.trigger_event("drivetrain.mark", self.subsystem)

            #Drop Arms
            self.intake_control_stream.push({"controlling": True, "arms_down": True, "flipper_out": True, "intake_motor": 0}, self.subsystem, autolock=True)

            #Trigger Vision
            wpilib.SmartDashboard.PutNumber("hot goal", 0)
            wpilib.SmartDashboard.PutBoolean("do vision", True)

            #Drive to line
            self.navigator_goals.push([(0, config["distance_from_tape"])], self.subsystem, autolock=True)
            events.start_event("navigator.run", self.subsystem)

            time.sleep(.2)
            start_time = time.time()
            #Loop until either we are told to stop, the navigator is done, it has taken too much time,
            # or the light sensor reports that we are on the line.
            while self.navigator_status.get(1) is 0 and time.time() - start_time < 5 and self.light_sensor.get() < 2.5:
                if not task.active:
                    raise self.EndAutoError()
                time.sleep(.2)

            #Stop the bot
            events.stop_event("navigator.run", self.subsystem)

            #Wait a bit for things to settle
            time.sleep(1)

            #Check hot goal and wait if the goal we are on is cold
            hot_goal = wpilib.SmartDashboard.GetNumber("hot goal")
            if config["start_position"] != hot_goal:
                #How long do we sleep if we want to wake up at the 5 second mark of autonomous mode?
                sleep_time = time.time() - (5 + auto_start_time)
                if sleep_time > 0:
                    time.sleep(sleep_time)

            #Charge!

            #What is the target for our shot?
            current_distance = self.drivetrain_state_stream.get({"distance": 0})["distance"]
            shot_point = (18 - config["first_shot"]) + current_distance
            target_drive = (18 - config["second_shot"]) + current_distance

            self.navigator_goals.push([(0, target_drive)], self.subsystem, autolock=True)

            #Run navigator until we are at shot_point
            events.start_event("navigator.run", self.subsystem)
            start_time = time.time()
            pos = self.drivetrain_state_stream.get({"distance": 0})
            while self.navigator_status.get(1) is 0 and time.time() - start_time < 5 and abs(pos["distance"] - shot_point) > 1:
                pos = self.drivetrain_state_stream.get({"distance": 0})
                if not task.active:
                    raise self.EndAutoError()
                time.sleep(.1)

            #Shoot
            events.trigger_event("shoot_cannon", self.subsystem)

            #Run intake
            self.intake_control_stream.push({"controlling": True, "arms_down": True, "flipper_out": True, "intake_motor": .5}, self.subsystem, autolock=True)

            #Wait for finish of drive arc
            while self.navigator_status.get(1) is 0 and time.time() - start_time < 7:
                time.sleep(.5)
                if not task.active:
                    raise self.EndAutoError()

            #wait for ball presence
            while not self.ballpresense_switch.get():
                if not task.active:
                    raise self.EndAutoError()
                time.sleep(.2)

            #Shoot
            events.trigger_event("shoot_cannon", self.subsystem)

        except self.EndAutoError:
            pass

        #Stop navigator
        events.stop_event("navigator.run", self.subsystem)

        #Stop intake
        self.intake_control_stream.push({"controlling": False, "arms_down": True, "flipper_out": True, "intake_motor": 0}, self.subsystem, autolock=True)
        logging.info("End of Autonomous")
예제 #24
0
def loop():
	global PLAYER_HAS_SHOOT_TIMER
	
	events.trigger_event('input')

	if not settings.TICK_MODE == 'strategy' and not ((ui_dialog.ACTIVE_DIALOG and ui_director.PAUSE) or ui_menu.ACTIVE_MENU or ui_director.PAUSE):
		_has_action = False
		
		_check_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)
				
				_check_life.add(member_id)
				_check_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES])

		_check_life = list(_check_life)
		
		#_check_life = 
		#_check_life.append(PLAYER['_id'])
		
		for entity_id in _check_life:
			if timers.has_timer_with_name(entities.get_entity(entity_id), 'shoot'):
				_has_action = True
				
				break
		
		if _has_action:
			_ticks_per_tick = 1
		
		else:
			_ticks_per_tick = settings.PLAN_TICK_RATE
		
		for _ in range(_ticks_per_tick):
			if settings.TICK_MODE == 'strategy':
				break
			
			ai_flow.logic()
			events.trigger_event('logic')
			tick()
			free_tick()
	
	else:
		ai_flow.logic()
		free_tick()

	if pathfinding.wait_for_astar():
		pass

	if not handle_input():
		return False

	events.trigger_event('tick')	
	events.trigger_event('camera')
	
	draw()

	return True
예제 #25
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