I have used inheritance alot in my current project and I couldn't emphisize how important types in types are. Especially when the game is very dynamic. Here's one example of my type structure
For example the WeaponBullet object has a field Parent.WeaponMount, WeaponMount has a field Parent.Weapon and Owner.PlayersShip, PlayerShip has fields Parent.Ship and Owner.Player . So when going through the bullets, to find out which Player shot this bullet, I code Shooter.Player=This\Parent\Owner\Owner . Why have PlayerShip and Ship as different types? Say the Ship type has attributes maxShields, mass, maxSpeed etc. Those fields are static information that does not change for this ship type. So the PlayerShip type has fields ShieldCharge etc. which is dynamic information. Always separate static and dynamic information to types of their own. You save memory and have some strictness in your code.
But what about going downwards in the hierarchy? There are two options. Let's think the PlayerShip can have several WeaponMounts. This can be done by having a field in PlayerShip
WeaponMounts.WeaponMount[7]
Which is a collection of pointers to WeaponMounts this PlayerShip has. This of course restricts the amount of weapons to eight. What about limitless amount? Object chain!
Now going through the weapons of certain PlayerShip is easy.
I could go on and on about this.
Player Ship | | PlayersShip Weapon | | \ / WeaponMount | WeaponBullet
For example the WeaponBullet object has a field Parent.WeaponMount, WeaponMount has a field Parent.Weapon and Owner.PlayersShip, PlayerShip has fields Parent.Ship and Owner.Player . So when going through the bullets, to find out which Player shot this bullet, I code Shooter.Player=This\Parent\Owner\Owner . Why have PlayerShip and Ship as different types? Say the Ship type has attributes maxShields, mass, maxSpeed etc. Those fields are static information that does not change for this ship type. So the PlayerShip type has fields ShieldCharge etc. which is dynamic information. Always separate static and dynamic information to types of their own. You save memory and have some strictness in your code.
But what about going downwards in the hierarchy? There are two options. Let's think the PlayerShip can have several WeaponMounts. This can be done by having a field in PlayerShip
WeaponMounts.WeaponMount[7]
Which is a collection of pointers to WeaponMounts this PlayerShip has. This of course restricts the amount of weapons to eight. What about limitless amount? Object chain!
Type PlayerShip Field Parent.Ship Field Owner.Player Field PosX# Field PosY# Field WeaponMounts.WPChain End Type Type WeaponMount Field Parent.Weapon Field Owner.PlayerShip Field FireCoolOff% End Type Type WPChain Field Obj.WeaponMount Field NextWP.WPChain EndType P1.PlayerShip = New PlayerShip W1.WeaponMount = New WeaponMount W1C.WPChain = New WPChain W1C\Obj = W1 P1\WeaponMounts = W1C W2.WeaponMount = New WeaponMount W2C.WPChain = New WPChain W2C\Obj = W2 W1C\NextWP = W2C
Now going through the weapons of certain PlayerShip is easy.
Local WPC.WPChain = P1\WeaponMounts While WPC<>null ; do what you want with WPC\Obj WPC = WPC\NextWP Wend
I could go on and on about this.