just a quick design query. I have a (simplified) class setup like so:
+ Actor
|
--+ Enemy
| | * member::_weapon
| | function::fire_weapon() calls _weapon->fire()
| |
| --+ Grunt
| |
| --+ SquadLeader
|
--+ Weapon
| | * member::_attached -> grunt/leader, variable is pointer-to-Enemy
| |
| --+ AssaultRifle
| function::fire() spawns Bullet
|
--+ Bullet
* member::_instigator -> AssaultRifle/other_weapon
I'm trying to think of the best way to track back who is the 'killer' of an enemy, when damaged by a bullet. Since the Weapon only has a pointer to an Enemy class (which is abstract), I need to obtain which Grunt/SquadLeader is the one responsible.
From what I know, I see four choices: use RTTI, use a visitor-style implementation, store identifiers within constructors, or just redesign it.
Is there another alternative, or what would you say is the best method to pull off what I'm trying to achieve? I have code in place that ensures a weapon can only fire if it is attached to an enemy, and a Bullet (probably later changed to a projectile) can only be 'fired' from a subclass of weapon (since weapon itself is abstract too), and would like to try and keep these restrictions if possible.
This project itself is going to be an AI implementation test before trying to utilize it within the Source engine, but I want to test outside of engine restrictions first to work out the kinks and get a suitable design. Other parts of this code are subject to the same type of problem as this direct one, so 'fixing' this will also be applied to the rest (such as Actors 'move' function, tracking back the outermost class to determine *what* actually moved).
Any comments welcome