Commit 43fa7fcb authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

Cleanups

parent b6d783af
......@@ -72,11 +72,6 @@ GsPythonModule::~GsPythonModule()
}
GsPythonFunc::~GsPythonFunc()
{
Py_XDECREF(mpFunction);
}
bool
GsPythonModule::
......@@ -88,6 +83,11 @@ load(const std::string &modName,
return (mpModule != nullptr) ? true : false;
}
GsPythonFunc::~GsPythonFunc()
{
Py_XDECREF(mpFunction);
}
bool
GsPythonFunc::
load(GsPythonModule &module,
......
......@@ -63,6 +63,12 @@ mSprVar(spriteVar)
}
#if USE_PYTHON3
bool CSpriteObject::loadAiGetterBool(const std::string &pyMethodStr, bool &value)
{
return loadAiGetterBool(mModule.rawPtr(), pyMethodStr, value);
}
bool CSpriteObject::loadAiGetterBool(PyObject * pModule, const std::string &pyMethodStr, bool &value)
{
// pFunc is a new reference
......@@ -150,43 +156,35 @@ bool CSpriteObject::loadAiGetterInteger(PyObject * pModule, const std::string &p
bool CSpriteObject::loadPythonScripts(const std::string &scriptBaseName)
{
auto pModule = gPython.loadModule( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
if (pModule != nullptr)
{
loadAiGetterBool(pModule, "canRecoverFromStun", mRecoverFromStun);
loadAiGetterBool(pModule, "turnAroundOnCliff", mTurnAroundOnCliff);
mModule.load( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
loadAiGetterBool(pModule, "endGameOnDefeat", mEndGameOnDefeat);
if(!mModule)
return false;
loadAiGetterBool(pModule, "isInvincible", mInvincible);
loadAiGetterBool("canRecoverFromStun", mRecoverFromStun);
loadAiGetterBool(pModule, "willNeverStop", mNeverStop);
loadAiGetterBool("turnAroundOnCliff", mTurnAroundOnCliff);
loadAiGetterBool(pModule, "isStunnableWithPogo", mPogoStunnable);
loadAiGetterBool("endGameOnDefeat", mEndGameOnDefeat);
loadAiGetterBool(pModule, "isStunnableWithJump", mJumpStunnable);
loadAiGetterBool("isInvincible", mInvincible);
loadAiGetterBool(pModule, "mayShoot", mMayShoot);
loadAiGetterBool("willNeverStop", mNeverStop);
int health = mHealthPoints;
loadAiGetterInteger(pModule, "healthPoints", health);
mHealthPoints = health;
loadAiGetterBool("isStunnableWithPogo", mPogoStunnable);
int walksound = mWalkSound;
loadAiGetterInteger(pModule, "walkSound", walksound);
mWalkSound = GameSound(walksound);
loadAiGetterBool("isStunnableWithJump", mJumpStunnable);
loadAiGetterBool("mayShoot", mMayShoot);
Py_DECREF(pModule);
}
else
{
return false;
}
auto pModule = mModule.rawPtr();
int health = mHealthPoints;
loadAiGetterInteger(pModule, "healthPoints", health);
mHealthPoints = health;
//Py_Finalize();
int walksound = mWalkSound;
loadAiGetterInteger(pModule, "walkSound", walksound);
mWalkSound = GameSound(walksound);
return true;
......
......@@ -372,6 +372,10 @@ class CSpriteObject
#if USE_PYTHON3
bool loadAiGetterBool(const std::string &pyMethodStr, bool &value);
/**
* @brief loadAiGetterInteger
* @param pModule
......
......@@ -92,35 +92,28 @@ CAmpton::CAmpton(CMap *pmap, const Uint16 foeID, const Uint32 x, const Uint32 y)
bool CAmpton::loadPythonScripts(const std::string &scriptBaseName)
{
#if USE_PYTHON3
auto pModule = gPython.loadModule( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
#if USE_PYTHON3
if (pModule != nullptr)
{
loadAiGetterBool(pModule, "screamAfterShoot", mScreamAfterShoot);
loadAiGetterBool(pModule, "mayShoot", mMayShoot);
mModule.load( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
loadAiGetterBool(pModule, "allowClimbing", mAllowClimbing);
if(!mModule)
return false;
int health = mHealthPoints;
loadAiGetterInteger(pModule, "healthPoints", health);
mHealthPoints = health;
int walksound = mWalkSound;
loadAiGetterInteger(pModule, "walkSound", walksound);
mWalkSound = GameSound(walksound);
loadAiGetterBool("screamAfterShoot", mScreamAfterShoot);
loadAiGetterBool("mayShoot", mMayShoot);
loadAiGetterBool("allowClimbing", mAllowClimbing);
auto pModule = mModule.rawPtr();
int health = mHealthPoints;
loadAiGetterInteger(pModule, "healthPoints", health);
mHealthPoints = health;
Py_DECREF(pModule);
}
else
{
return false;
}
int walksound = mWalkSound;
loadAiGetterInteger(pModule, "walkSound", walksound);
mWalkSound = GameSound(walksound);
//Py_Finalize();
#endif
#endif
return true;
}
......
......@@ -81,26 +81,15 @@ mKeenNearby(false)
bool CRoboRed::loadPythonScripts(const std::string &scriptBaseName)
{
#if USE_PYTHON3
auto pModule = gPython.loadModule( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
mModule.load( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
if (pModule != nullptr)
{
loadAiGetterBool(pModule, "isInvincible", mInvincible);
loadAiGetterBool(pModule, "willNeverStop", mNeverStop);
loadAiGetterBool(pModule, "alternateShoot", mAlternateShot);
loadAiGetterBool(pModule, "mayJiggle", mJiggle);
Py_DECREF(pModule);
}
else
{
if(!mModule)
return false;
}
//Py_Finalize();
loadAiGetterBool("isInvincible", mInvincible);
loadAiGetterBool("willNeverStop", mNeverStop);
loadAiGetterBool("alternateShoot", mAlternateShot);
loadAiGetterBool("mayJiggle", mJiggle);
#endif
return true;
......
......@@ -66,23 +66,15 @@ mTimer(0)
bool CShikadi::loadPythonScripts(const std::string &scriptBaseName)
{
#if USE_PYTHON3
auto pModule = gPython.loadModule( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
if (pModule != nullptr)
{
//loadAiGetterBool(pModule, "moreAgressive", mMoreAgressive);
mp_processState = static_cast<GASOFctr>(&CShikadi::processPython);
mModule.load( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
mModule.load( "shikadi", JoinPaths(gKeenFiles.gameDir ,"ai") );
mProcessFunc.load(mModule, "process");
}
else
{
if(!mModule)
return false;
}
//Py_Finalize();
mp_processState = static_cast<GASOFctr>(&CShikadi::processPython);
mProcessFunc.load(mModule, "process");
#endif
return true;
}
......
......@@ -66,20 +66,14 @@ CStunnable(pmap, foeID, x, y)
bool CShikadiMaster::loadPythonScripts(const std::string &scriptBaseName)
{
#if USE_PYTHON3
auto pModule = gPython.loadModule( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
if (pModule != nullptr)
{
loadAiGetterBool(pModule, "moreAgressive", mMoreAgressive);
mModule.load( scriptBaseName, JoinPaths(gKeenFiles.gameDir ,"ai") );
Py_DECREF(pModule);
}
else
{
if(!mModule)
return false;
}
//Py_Finalize();
loadAiGetterBool(mModule.rawPtr(), "moreAgressive", mMoreAgressive);
#endif
return true;
}
......
......@@ -3,9 +3,7 @@
CCarrier::CCarrier(CMap* pmap, Uint32 x, Uint32 y, object_t type) :
CVorticonSpriteObject(pmap, x, y, type, 0)
{
}
{}
void CCarrier::getTouchedBy(CVorticonSpriteObject& theObject)
{
......@@ -77,8 +75,8 @@ void CCarrier::draw()
if( scrx < gameres.w && scry < gameres.h && exists )
{
Uint16 showX = scrx+Sprite.getXOffset();
Uint16 showY = scry+Sprite.getYOffset();
auto showX = Uint16(scrx+Sprite.getXOffset());
auto showY = Uint16(scry+Sprite.getYOffset());
if(m_blinktime > 0)
{
Sprite.drawBlinkingSprite( showX, showY );
......@@ -125,7 +123,7 @@ std::vector<CSpriteObject*> CCarrier::fetchCarriedPlayer()
continue;
if( !player->mIsDead || !player->dying )
carriedSO.push_back( (CSpriteObject*) player);
carriedSO.push_back( static_cast<CSpriteObject*>(player) );
}
return carriedSO;
......
......@@ -89,8 +89,8 @@ public:
void processInLevel();
void touchedExit(int mpx);
void walkbehindexitdoor();
void kill(bool force);
void kill();
void kill(const bool force);
void kill();
void dieanim();
void setDir();
void getgoodies();
......@@ -110,14 +110,14 @@ public:
void getShotByRay(object_t &obj_type);
void processStatusScreen();
bool checkMapBoundaryL(const int x1);
bool checkMapBoundaryR(const int x2);
bool checkMapBoundaryU(const int y1);
bool checkMapBoundaryL(const int x1) override;
bool checkMapBoundaryR(const int x2) override;
bool checkMapBoundaryU(const int y1) override;
// Used for both situations
virtual void pumpEvent(const CEvent *evPtr);
virtual void pumpEvent(const CEvent *evPtr) override;
void processCamera();
void processEvents();
void processEvents() override;
void InertiaAndFriction_X();
void Walking();
void WalkingAnimation();
......
......@@ -142,7 +142,7 @@ void CPlayer::kill()
kill(false);
}
void CPlayer::kill(bool force)
void CPlayer::kill(const bool force)
{
if(!force) // force can happens for example, when player leaves the map to the most lower-side
{
......
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