So to give a little back drop on my problem, I'm currently (attempting) to make a SHMUP and I've just made a State Machine and base State class (each templates for the type of object that it's for... States are singletons... Most of this is chunks I got from the book Programming Game AI By Example).
So I have a Singleton template, just the standard Meyer's implementation.
I have the State Machine template which holds states of it's own template type, and lastly the State template.
So in my base enemy class I have the State Machine declared as:
Code: Select all
StateMachine<Enemy>* m_pStateMachine;
Now I make a basic enemy, a Grunt, and make a state for it:
Code: Select all
class Grunt_Idle : public State<Grunt>
Then I initialize the state machine like:
Code: Select all
m_pStateMachine = new StateMachine<Grunt>(this);
Error... Can't convert parameter 1 from StateMachine<Grunt>* to StateMachine<entity_type>*... I just assumed that would work because inheritance established that "A Grunt IS AN Enemy". So when that failed, I initialized the StateMachine like this:
Code: Select all
m_pStateMachine = new Statemachine<Enemy>(this);
Alright, that works, but now I get an error when I try to set the state:
Code: Select all
m_pStateMachine->SetCurrentState(Singleton<Grunt_Idle>::GetInstance());
Another error... Can't convert parameter 1 from Grunt_Idle* to State<entity_type>*... Again, I assumed that because a Grunt is an enemy, it would work...
Here's the declaration of Grunt_Idle:
Code: Select all
class Grunt_Idle : public State<Grunt>
So I could probably just chain everything up to the base Enemy class, but my problem is, what if I need the state to access sub class specific data? So... I'm sure there's a way to accomplish it, Thanks in advance for any help!