The HeavyCruiser model was originally created by nicolasc, and I'm adding textures, collisionboxes and everything else needed to make it playable in the game. Most of the texturing as well as collisionboxes and the ship's flight characteristics are done, but the ship still is only one single entity (I cut the model into different parts, but they are all attached to the same entity).
So I started thinking about how to implement the structure of a big ship with different destructible parts, as well as about how to add turrets to it.
(In the following I will refer to the 'main' ship-body which is controlled by the player as BigShip. The parts attached to it are ShipParts, and there's Turrets too.)
My first attempt to add the Turret (the already implemented one) to the ship in XML failed due to Turrets being SpaceShips, which cannot be attached in XML like normal Static or MovableEntities (Console output: Warning (internal): Cannot attach a dynamic object to a WorldEntity.) The same applies to other ShipParts: Attaching them as StaticEntity makes them part of the BigShip, but they are not individually destructible. So something new needs to be done. (It doesn't need to be actually done to finish my ticket, but it would be good to have an idea on how to continue, and create a new ticket for it.)
I've never really coded before (apart from Informatik I and II exercises), so instead of just knocking an ugly makeshift solution together it's probably better to ask people with a bit more experience >.<
Anyhow, here's what I've thought about so far:
Originally I thought it would be good if in the end ShipParts can simply be attached to BigShips like any other Entity, resulting in the corresponding XML to look something like this:
Code: Select all
<BigShip [parameters]>
<engines>
...
</engines>
<attached>
<Model [parameters] />
<ShipPart [parameters]>
<attached>
<Model [parameters] />
</attached>
<collisionShapes>
...
</collisionShapes>
</ShipPart>
<ShipPart [parameters]>
...
</ShipPart>
</attached>
<collisionShapes>
...
</collisionShapes>
<BigShip>
Create some sort of DestructibleEntity, which is a StaticEntity, but has health, is able to receive damage and get destroyed. It can be used for other simple destructible objects such as asteroids or crates too.
A ShipPart class would build on that interface. ShipParts would have a pointer to their 'parent' BigShip and be able to modify that parent's values upon being destroyed (e.g. disable weapons/shields or weakening engines).
A new BigShip class extends the existing SpaceShip class. BigShip reads the XML ShipPart Objects and calls the ShipPart constructors. BigShips has parameters which can be changed by its child ShipParts and vice versa (e.g. BigShip can deflect damage to certain parts)
A new Turret class, which is a ShipPart, but needs a controller and weapons added.


So Jo suggested simply using Pawns instead.
Alternative, probably better approach:
Both ShipParts and Turrets are Pawns. They have a pointer to their 'parent' BigShip, while BigShip has pointers to its ShipParts. Every tick their position and rotation is moved according to their 'parent' BigShips movement. (This should be possible with some vector calculations.)
Again, ShipPart and Turret can change BigShip's parameters and vice versa.
This way we don't need to worry about <attach>ing the Entity, since the entity follows the BigShip by itself. Also the Pawn already offers hitdetection, weapons and other fancy stuff.
(Jo also brought up the idea of a 'docking' function for SpaceShips or Pawns in general, which could have other applications than BigShips)

Now, I'd like to hear your ideas/feedback.

Maybe you have a completely different ingenious idea? Or maybe there is a feature already included which I'm not aware of which could be useful?
Thanks