Ejemplo n.º 1
0
 def _pre_manufacture(self, name):
     return self.manufacture(name, MutableOffsets(0, 0, 0),
                             MutableDegrees(0, 0,
                                            0), MutableOffsets(0, 0, 0),
                             MutableDegrees(0, 0,
                                            0), MutableOffsets(0, 0, 0),
                             MutableDegrees(0, 0, 0))
Ejemplo n.º 2
0
 def setup(self):
     spmf = ShipPartModelFactory()
     null_offset = MutableOffsets(0, 0, 0)
     null_rotation = MutableDegrees(0, 0, 0)
     target = spmf.manufacture("generator", position=(10, 0, 0))
     cockpit = spmf.manufacture("cockpit")
     parts = {cockpit, target}
     self.ship = ShipModel("foo", parts, null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__())
     self.drydock = Drydock(0,
                            1000,
                            0,
                            1000,
                            self.ship,
                            view_factory=FakeFactory())
     self.ship = self.drydock.ship
     self.target_item: DockableItem = [
         item for item in self.drydock.items
         if item.model.name == "generator"
     ][0]
     self.target_item.held = True
     self.target_item._highlight = True
     self.target = self.target_item.model
     self.cockpit_item: DockableItem = [
         item for item in self.drydock.items if item.model.name == "cockpit"
     ][0]
     self.cockpit = self.cockpit_item.model
     self.ship_rebuild_callback = MagicMock()
     self.ship.observe(self.ship_rebuild_callback, "rebuild")
     self.target_callback = MagicMock()
     self.target.observe(self.target_callback, "move")
Ejemplo n.º 3
0
 def setup(self):
     spmf = ShipPartModelFactory()
     null_offset = MutableOffsets(0, 0, 0)
     null_rotation = MutableDegrees(0, 0, 0)
     self.target = spmf.manufacture("shield", position=(10, 0, 0))
     self.other = spmf.manufacture("shield")
     parts = {self.other, self.target}
     self.ship = ShipModel("foo", parts, null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__())
Ejemplo n.º 4
0
 def setup(self):
     spmf = ShipPartModelFactory()
     null_offset = MutableOffsets(0, 0, 0)
     null_rotation = MutableDegrees(0, 0, 0)
     self.generator = spmf.manufacture("generator", position=(1.5, 0, 0))
     self.cockpit = spmf.manufacture("cockpit")
     parts = {self.cockpit, self.generator}
     self.ship = ShipModel("foo", parts, null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__())
     self.target = list(self.ship._connections)[0]
Ejemplo n.º 5
0
 def setup(self):
     spmf = ShipPartModelFactory()
     null_offset = MutableOffsets(0, 0, 0)
     null_rotation = MutableDegrees(0, 0, 0)
     self.shield1 = spmf.manufacture("shield", position=(2, 0, 0))
     self.obstacles = {
         spmf.manufacture("generator", position=(0, 0, y))
         for y in range(-4, 4)
     }
     self.shield2 = spmf.manufacture("shield", position=(-2, 0, 0))
     parts = self.obstacles | {self.shield1, self.shield2}
     self.ship = ShipModel("foo", parts, null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__())
Ejemplo n.º 6
0
 def setup(self):
     spmf = ShipPartModelFactory()
     null_offset = MutableOffsets(0, 0, 0)
     null_rotation = MutableDegrees(0, 0, 0)
     self.shield1 = spmf.manufacture("shield", position=(2.5, 0, 0))
     self.obstacles = {spmf.manufacture("generator", position=(0, 0, 0))}
     self.shield2 = spmf.manufacture("shield", position=(-2.5, 0, 0))
     parts = self.obstacles | {self.shield1, self.shield2}
     self.ship = ShipModel("foo", parts, null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__(),
                           null_rotation.__copy__(), null_offset.__copy__())
     self.target = [
         c for c in self.ship._connections
         if set(c._ship_parts) == {self.shield1, self.shield2}
     ][0]
Ejemplo n.º 7
0
 def __init__(self, view_class=BaseView):
     self.meshes = {}
     self.mesh_factory = factory
     self._view_class = view_class
     self.pre_factorized_views = []
     if view_class == BaseView:
         above_camera = MutableOffsets(0, -100, 0)
         zero = MutableOffsets(0, 0, 0)
         no_angle = MutableDegrees(0, 0, 0)
         no_acceleration = MutableOffsets(0, 0, 0)
         no_torque = MutableDegrees(0, 0, 0)
         bb = Polygon.manufacture([(0, 0)])
         self.dummy_model = BaseModel(position=above_camera, rotation=no_angle,
                                      movement=zero, spin=no_angle, acceleration=no_acceleration,
                                      torque=no_torque, bounding_box=bb)
         self.pre_factorized_views = [self._prefactorize() for i in range(200)]
Ejemplo n.º 8
0
 def __init__(self, x=0, y=0, z=0, pitch=0, yaw=0, roll=0, name=None):
     Observable.__init__(self)
     self._position = MutableOffsets(x, y, z)
     self._rotation = MutableDegrees(pitch, yaw, roll)
     self._mesh_name = name
     self._name = name
     self.material_value = 0.0
     self._mass = 1
Ejemplo n.º 9
0
 def manufacture(position, rotation=None):
     position = MutableOffsets(*position)
     rotation = rotation or (0, 0, 0)
     rotation = MutableDegrees(*rotation)
     movement = MutableOffsets(0, 0, 0)
     spin = MutableDegrees(0, 0, 0)
     acceleration = MutableOffsets(0, 0, 0)
     torque = MutableDegrees(0, 0, 0)
     coords = [(-sin(radians(d)), cos(radians(d)))
               for d in range(0, 360, 18)]
     distances = [abs(normalvariate(25, 5)) for _ in coords]
     coords = [(x * d, y * d) for (x, y), d in zip(coords, distances)]
     bounding_box = MultiPolygon.manufacture(coords=coords,
                                             x=position.x,
                                             y=position.z,
                                             rotation=rotation.yaw)
     return AsteroidModel(position, rotation, movement, spin, acceleration,
                          torque, bounding_box)
Ejemplo n.º 10
0
 def manufacture(self, name, position: MutableOffsets,
                 rotation: MutableDegrees, movement: MutableOffsets,
                 spin: MutableDegrees, acceleration: MutableOffsets,
                 torque: MutableDegrees) -> PlasmaModel:
     if self.projectiles[name]:
         return self.repurpose(name, position, rotation, movement, spin,
                               acceleration, torque)
     #  config = deepcopy(self.projectiles[name])
     bounding_box = MultiPolygon.manufacture([(-.1, -.1), (.1, -.1),
                                              (.1, .1), (-.1, .1)],
                                             x=position.x,
                                             y=position.z,
                                             rotation=rotation.yaw)
     projectile = PlasmaModel(position.__copy__(), rotation.__copy__(),
                              movement.__copy__(), spin.__copy__(),
                              acceleration.__copy__(), torque.__copy__(),
                              bounding_box)
     return projectile
Ejemplo n.º 11
0
 def _manufacture(self, name, ship_model: ShipModel,
                  ship_part_model: ShipPartModel) -> PlasmaModel:
     yaw_radian = ship_model.rotation.yaw_radian + ship_part_model.rotation.yaw_radian
     position = ship_part_model.position.__copy__()
     position.set(position.x, position.y, position.z - 5)
     ship_model.mutate_offsets_to_global(position)
     rotation = ship_model.rotation.__copy__()
     movement = MutableOffsets(-sin(yaw_radian) * 125, 0,
                               -cos(yaw_radian) * 125)
     #movement += ship_model.global_momentum_at(ship_part_model.position).forces
     movement += ship_model.movement
     spin = -ship_model.spin
     acceleration = MutableOffsets(0, 0, 0)
     torque = MutableDegrees(0, 0, 0)
     return self.factory.manufacture(name, position, rotation, movement,
                                     spin, acceleration, torque)
Ejemplo n.º 12
0
 def __init__(self, left, right, bottom, top, model: BaseModel):
     super().__init__(left, right, bottom, top)
     self._model = None
     self._view_scale = 1.
     self._view: BaseView = None
     self._position = MutableOffsets(0, 0, 0)
     self._rotation = MutableDegrees(0, 0, 0)
     padding = 20
     font_size = 12
     x = left + padding
     y = top - (font_size + padding)
     self._info_label = Label("N/A",
                              font_name='Courier New',
                              font_size=font_size,
                              x=x,
                              y=y,
                              multiline=True,
                              width=self.width - padding * 2)
     self.set_model(model)
Ejemplo n.º 13
0
    def manufacture(self,
                    name,
                    position=None,
                    rotation=None,
                    movement=None,
                    spin=None,
                    acceleration=None,
                    torque=None) -> ShipModel:
        config = deepcopy(self.ships[name])
        center_of_mass = MutableOffsets(0, 0, 0)
        parts = self.ship_part_model_factory.manufacture_all(
            config['parts'], center_of_mass)

        ship_id = "Ship {}".format(self.ship_id_counter)
        self.ship_id_counter += 1
        position = position or (0, 0, 0)
        rotation = rotation or (0, 0, 0)
        movement = movement or (0, 0, 0)
        spin = spin or (0, 0, 0)
        acceleration = acceleration or (0, 0, 0)
        torque = torque or (0, 0, 0)
        position = MutableOffsets(*position)
        rotation = MutableDegrees(*rotation)
        movement = MutableOffsets(*movement)
        spin = MutableUnboundDegrees(*spin)
        acceleration = MutableOffsets(*acceleration)
        torque = MutableUnboundDegrees(*torque)
        ship = ShipModel(ship_id=ship_id,
                         parts=parts,
                         position=position,
                         rotation=rotation,
                         movement=movement,
                         spin=spin,
                         acceleration=acceleration,
                         torque=torque,
                         center_of_mass=center_of_mass)
        #  for part in parts:
        #      part.observe(self.jettison_exploding_part_function(ship, part), "explode")
        return ship