Commit 6b770d73 authored by Gerhard Stein's avatar Gerhard Stein

Function pointer mapped

parent fcd7ae37
......@@ -185,7 +185,7 @@ int16_t CGalaxySpriteObject::getActionNumber()
{ return m_ActionNumber; }
void CGalaxySpriteObject::setActionForce(size_t ActionNumber)
void CGalaxySpriteObject::setActionForce(const size_t ActionNumber)
{
m_ActionNumber = ActionNumber;
m_Action.setActionFormat(m_ActionBaseOffset + 30*m_ActionNumber);
......
......@@ -26,7 +26,7 @@ public:
bool getActionNumber(int16_t ActionNumber);
bool getActionStatus(int16_t ActionNumber);
int16_t getActionNumber();
void setActionForce(size_t ActionNumber);
virtual void setActionForce(const size_t ActionNumber);
void setAction(size_t ActionNumber);
void setActionSprite();
void processActionRoutine();
......
......@@ -60,4 +60,13 @@ void CStunnable::processGettingStunned()
void CStunnable::processStunned()
{ }
void CStunnable::setActionForce(const size_t ActionNumber)
{
CGalaxySpriteObject::setAction(ActionNumber);
if( mActionMap.find(ActionNumber) != mActionMap.end() )
mp_processState = mActionMap[ActionNumber];
}
};
......@@ -10,6 +10,7 @@
#include "engine/galaxy/CGalaxySpriteObject.h"
#include "engine/galaxy/ai/CBullet.h"
#include <map>
namespace galaxy
{
......@@ -38,9 +39,12 @@ public:
*/
void processStunned();
void setActionForce(const size_t ActionNumber);
protected:
bool m_stunned;
void (CStunnable::*mp_processState)();
std::map< size_t, void (CStunnable::*)() > mActionMap;
};
}
......
......@@ -14,6 +14,14 @@
namespace galaxy {
enum SLUGACTIONS
{
A_SLUG_MOVE = 0, /* Ordinary slug_move action */
A_SLUG_POOING = 2,
A_SLUG_STUNNED = 3,
A_SLUG_STUNNED_ALT = 4
};
const int SLUG_MOVE_SPEED = 1;
const int SLUG_MOVE_TIMER = 10;
......@@ -24,9 +32,13 @@ CStunnable(pmap, foeID, x, y),
m_ObjectPtrs(ObjectPtrs),
m_timer(0)
{
mActionMap[A_SLUG_MOVE] = (void (CStunnable::*)()) &CPoisonSlug::processCrawling;
mActionMap[A_SLUG_POOING] = (void (CStunnable::*)()) &CPoisonSlug::processPooing;
mActionMap[A_SLUG_STUNNED] = &CStunnable::processGettingStunned;
mActionMap[A_SLUG_STUNNED_ALT] = &CStunnable::processGettingStunned;
setupGalaxyObjectOnMap(0x2012, A_SLUG_MOVE);
mp_processState = (void (CStunnable::*)()) &CPoisonSlug::processCrawling;
m_hDir = LEFT;
}
......@@ -58,7 +70,6 @@ void CPoisonSlug::processCrawling()
if( getProbability(30) )
{
m_timer = 0;
mp_processState = (void (CStunnable::*)()) &CPoisonSlug::processPooing;
setAction( A_SLUG_POOING );
playSound( SOUND_SLUG_DEFECATE );
m_ObjectPtrs.push_back(new CSlugSlime(mp_Map, 0, getXLeftPos(), getYDownPos()-(8<<STC)));
......@@ -80,10 +91,7 @@ void CPoisonSlug::processCrawling()
void CPoisonSlug::processPooing()
{
if( getActionStatus(A_SLUG_MOVE) )
{
setAction(A_SLUG_MOVE);
mp_processState = (void (CStunnable::*)()) &CPoisonSlug::processCrawling;
}
}
......@@ -97,7 +105,6 @@ void CPoisonSlug::getTouchedBy(CSpriteObject &theObject)
// Was it a bullet? Than make it stunned.
if( dynamic_cast<CBullet*>(&theObject) )
{
mp_processState = &CStunnable::processGettingStunned;
setAction( rand()%2 ? A_SLUG_STUNNED : A_SLUG_STUNNED_ALT );
dead = true;
theObject.dead = true;
......
......@@ -15,10 +15,6 @@
namespace galaxy {
#define A_SLUG_MOVE 0 /* Ordinary slug_move action */
#define A_SLUG_POOING 2
#define A_SLUG_STUNNED 3
#define A_SLUG_STUNNED_ALT 4
class CPoisonSlug : public CStunnable
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment