Browse Source

Updates to the Python API

Throw away some stupid stuff and make things slightly easier to use...
Adam Johnson 13 years ago
parent
commit
5cf540b424
  1. 9
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 18
      Sources/Plasma/FeatureLib/pfPython/pyCritterBrain.cpp
  3. 3
      Sources/Plasma/FeatureLib/pfPython/pyCritterBrain.h
  4. 21
      Sources/Plasma/FeatureLib/pfPython/pyCritterBrainGlue.cpp
  5. 8
      Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
  6. 9
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp
  7. 15
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.h

9
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -2868,14 +2868,7 @@ PyObject* cyMisc::GetAIAvatarsByModelName(const char* name)
Py_DECREF(tuple);
}
}
if (PyList_Size(avList) > 0)
return avList;
else
{
Py_DECREF(avList);
PYTHON_RETURN_NONE;
}
return avList;
}
void cyMisc::ForceVaultNodeUpdate(unsigned nodeId)

18
Sources/Plasma/FeatureLib/pfPython/pyCritterBrain.cpp

@ -41,8 +41,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "pyCritterBrain.h"
#include "pyGeometry3.h"
#include "pySceneObject.h"
#include "plAvatar/plAvBrainCritter.h"
#include "pnSceneObject/plSceneObject.h"
pyCritterBrain::pyCritterBrain(): fBrain(nil) {}
@ -66,18 +68,12 @@ void pyCritterBrain::RemoveReceiver(pyKey& oldReceiver)
fBrain->RemoveReceiver(oldReceiver.getKey());
}
void pyCritterBrain::LocallyControlled(bool local)
PyObject* pyCritterBrain::GetSceneObject()
{
if (!fBrain)
return;
fBrain->LocallyControlled(local);
}
bool pyCritterBrain::LocallyControlled() const
{
if (!fBrain)
return false;
return fBrain->LocallyControlled();
if (fBrain)
if (plSceneObject* obj = fBrain->GetTarget())
return pySceneObject::New(obj->GetKey());
PYTHON_RETURN_NONE;
}
void pyCritterBrain::AddBehavior(const std::string& animationName, const std::string& behaviorName, bool loop /* = true */,

3
Sources/Plasma/FeatureLib/pfPython/pyCritterBrain.h

@ -83,8 +83,7 @@ public:
void AddReceiver(pyKey& newReceiver);
void RemoveReceiver(pyKey& oldReceiver);
void LocallyControlled(bool local);
bool LocallyControlled() const;
PyObject* GetSceneObject();
void AddBehavior(const std::string& animationName, const std::string& behaviorName, bool loop = true, bool randomStartPos = true,
float fadeInLen = 2.f, float fadeOutLen = 2.f);

21
Sources/Plasma/FeatureLib/pfPython/pyCritterBrainGlue.cpp

@ -139,21 +139,9 @@ PYTHON_METHOD_DEFINITION(ptCritterBrain, removeReceiver, args)
PYTHON_RETURN_NONE;
}
PYTHON_METHOD_DEFINITION(ptCritterBrain, setLocallyControlled, args)
PYTHON_METHOD_DEFINITION(ptCritterBrain, getSceneObject, GetSceneObject)
{
char local;
if (!PyArg_ParseTuple(args, "b", &local))
{
PyErr_SetString(PyExc_TypeError, "setLocallyControlled expects a boolean");
PYTHON_RETURN_ERROR;
}
self->fThis->LocallyControlled(local != 0);
PYTHON_RETURN_NONE;
}
PYTHON_METHOD_DEFINITION_NOARGS(ptCritterBrain, getLocallyControlled)
{
PYTHON_RETURN_BOOL(self->fThis->LocallyControlled());
return self->fThis->GetSceneObject();
}
PYTHON_METHOD_DEFINITION_WKEY(ptCritterBrain, addBehavior, args, keywords)
@ -472,10 +460,7 @@ PYTHON_METHOD_DEFINITION(ptCritterBrain, vectorToPlayer, args)
PYTHON_START_METHODS_TABLE(ptCritterBrain)
PYTHON_METHOD(ptCritterBrain, addReceiver, "Params: key\nTells the brain that the specified key wants AI messages"),
PYTHON_METHOD(ptCritterBrain, removeReceiver, "Params: key\nTells the brain that the specified key no longer wants AI messages"),
PYTHON_METHOD(ptCritterBrain, setLocallyControlled, "Params: local\nTells the brain that we are the ones making all the AI decisions, and to prop location "
"and other information to the server."),
PYTHON_METHOD_NOARGS(ptCritterBrain, getLocallyControlled, "Are we the one making AI decisions? NOTE: Not set automatically, some python script needs to "
"tell the brain this using setLocallyControlled()."),
PYTHON_METHOD(ptCritterBrain, getSceneObject, "Returns the ptSceneObject this brain controls."),
PYTHON_METHOD_WKEY(ptCritterBrain, addBehavior, "Params: animName, behaviorName, loop = 1, randomStartPos = 1, fadeInLen = 2.0, fadeOutLen = 2.0\n"
"Adds a new animation to the brain as a behavior with the specified name and parameters. If multiple animations are assigned to the same behavior, "
"they will be randomly picked from when started."),

8
Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp

@ -1952,10 +1952,10 @@ hsBool plArmatureMod::IsLocalAvatar()
hsBool plArmatureMod::IsLocalAI()
{
plAvBrainCritter* ai = plAvBrainCritter::ConvertNoRef(FindBrainByClass(plAvBrainCritter::Index()));
if (ai)
return ai->LocallyControlled();
return false; // not an AI, obviously not local
// Formerly a lot of silly cached rigamaroll... Now, we'll just rely
// on the fact that one player is the game master. HACK TURD if net groups
// are ever brought back.
return plNetClientApp::GetInstance()->IsLocallyOwned(this);
}
void plArmatureMod::SynchIfLocal(double timeNow, int force)

9
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp

@ -126,7 +126,7 @@ protected:
///////////////////////////////////////////////////////////////////////////////
plAvBrainCritter::plAvBrainCritter(): fCallbackAction(nil), fCurMode(kIdle), fNextMode(kIdle), fFadingNextBehavior(true),
fLocallyControlled(false), fAvoidingAvatars(false), fFinalGoalPos(0, 0, 0), fImmediateGoalPos(0, 0, 0), fDotGoal(0),
fAvoidingAvatars(false), fFinalGoalPos(0, 0, 0), fImmediateGoalPos(0, 0, 0), fDotGoal(0),
fAngRight(0)
{
SightCone(M_PI/2); // 90deg
@ -229,6 +229,13 @@ void plAvBrainCritter::Resume()
plArmatureBrain::Resume();
}
plSceneObject* plAvBrainCritter::GetTarget() const
{
if (fArmature)
return fArmature->GetTarget(0);
return nil;
}
void plAvBrainCritter::AddBehavior(const std::string& animationName, const std::string& behaviorName, bool loop /* = true */, bool randomStartPos /* = true */,
float fadeInLen /* = 2.f */, float fadeOutLen /* = 2.f */)
{

15
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.h

@ -83,14 +83,21 @@ public:
virtual void Suspend();
virtual void Resume();
/**
* Gets the SceneObject root for this avatar
*
* This is most useful in scripts that need to act upon the SceneObject directly.
* There are other ways of obtaining the SceneObject, but network synchronization often
* makes those ways more difficult than they need to be, so we have included this method
* to make the scripter's life easier.
*/
plSceneObject* GetTarget() const;
void AddBehavior(const std::string& animationName, const std::string& behaviorName, bool loop = true, bool randomStartPos = true,
float fadeInLen = 2.f, float fadeOutLen = 2.f);
void StartBehavior(const std::string& behaviorName, bool fade = true);
bool RunningBehavior(const std::string& behaviorName) const;
void LocallyControlled(bool local) {fLocallyControlled = local;}
bool LocallyControlled() const {return fLocallyControlled;}
std::string BehaviorName(int behavior) const;
plString AnimationName(int behavior) const;
int CurBehavior() const {return fCurMode;}
@ -157,8 +164,6 @@ protected:
int fNextMode; // the next behavior to run (-1 if we aren't switching on next eval)
bool fFadingNextBehavior; // is the next behavior supposed to blend?
bool fLocallyControlled; // is our local AI script the one making all the choices?
bool fAvoidingAvatars; // are we avoiding avatars to the best of our ability when pathfinding?
hsPoint3 fFinalGoalPos; // the location we are pathfinding to
hsPoint3 fImmediateGoalPos; // the location of the point we are immediately going towards (not necessarily our final goal)

Loading…
Cancel
Save