Exemplo n.º 1
0
def _test_acceleration(direction,
                       expected_position,
                       orientation={},
                       keep_mass=True,
                       reactor_power=20):
    # Generate the components and build the ship
    thruster = Thruster(max_force=10.0)
    reactor = Reactor(max_output=reactor_power)
    panel = ShipPanel(side=directions.COUNTER_DIRECTIONS[direction],
                      thrusters=[thruster])
    ship = Ship(
        **{
            "reactors": [reactor],
            F"{direction}_panel": panel,
            directions.YAW: orientation.get(directions.YAW, 0),
            directions.ROLL: orientation.get(directions.ROLL, 0),
            directions.PITCH: orientation.get(directions.PITCH, 0),
        })

    # Set total mass to 1 in order to negate any mass affects on propulsion
    if not keep_mass:
        ship.mass = 1

    # Set thruster throttle to 50%
    for thruster in ship.get_thrusters_by_orientation(direction):
        thruster.throttle = 1.0

    # Apply acceleration for one tick
    ship.apply_acceleration_vectors()

    # Error
    assert ship.position == expected_position, \
        F"{ship.position} != {expected_position}"
def test_reaction_wheel_degredation():
    ship = Ship(reaction_wheels=[
        ReactionWheel(
            axis=directions.ROLL, rotation=directions.CLOCKWISE, max_force=15)
    ])
    for reaction_wheel in ship.reaction_wheels:
        reaction_wheel.throttle = 1.2

    for _ in range(0, 100):
        ship.apply_acceleration_vectors()

    # Assert that reaction wheel integrity meets expected values
    assert ship.reaction_wheels[0].integrity == 0.996, \
        F"{ship.reaction_wheels[0].integrity} != {0.996}"
def test_thruster_degredation():
    # Generate the components and build the ship
    thruster = Thruster(max_force=10.0)
    panel = ShipPanel(
        side=directions.FORWARD,
        thrusters=[thruster]
    )
    ship = Ship(**{F"{directions.FORWARD}_panel": panel})

    # Set thruster throttle to 120%
    for thruster in ship.thrusters:
        thruster.throttle = 1.2

    # Apply acceleration for one hundred ticks
    for _ in range(0, 100):
        ship.apply_acceleration_vectors()

    # Error
    assert ship.thrusters[0].integrity == 0.996, \
        F"{ship.thrusters[0].integrity} != {0.996}"
Exemplo n.º 4
0
def _test_rotation(direction, axis, expected_orientation={}, keep_mass=True):
    assert True
    return
    ship = Ship(reaction_wheels=[
        ReactionWheel(axis=axis, rotation=direction, max_force=15)
    ])
    if not keep_mass:
        ship.mass = 1
    for reaction_wheel in ship.reaction_wheels:
        reaction_wheel.throttle = 0.5

    ship.apply_acceleration_vectors()
    assert ship.get_yaw(math.DEGREES) == \
        expected_orientation.get(directions.YAW, 0), \
        F"{ship.get_yaw(math.DEGREES)} != " \
        F"{expected_orientation.get(directions.YAW, 0)}"
    assert ship.get_roll(math.DEGREES) == \
        expected_orientation.get(directions.ROLL, 0), \
        F"{ship.get_roll(math.DEGREES)} != " \
        F"{expected_orientation.get(directions.ROLL, 0)}"
    assert ship.get_pitch(math.DEGREES) == \
        expected_orientation.get(directions.PITCH, 0), \
        F"{ship.get_pitch(math.DEGREES)} != " \
        F"{expected_orientation.get(directions.PITCH, 0)}"