mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
* tools/cyloadrules.cpp, server/server.cpp, aiclient/ClientConnection.cpp, client/ClientConnection.cpp, common/inheritance.h: Use const iterators and references whenever possible. * client/CommClient.cpp, client/CreatorClient.cpp, client/ObserverClient.cpp, client/Py_CreatorClient.cpp, common/BaseEntity.cpp, common/BaseEntity.h, common/types.h, rulesets/Area.cpp, rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp, rulesets/Food.cpp, rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/Pedestrian.cpp, rulesets/Plant.cpp, rulesets/Py_Mind.cpp, rulesets/Py_Object.cpp, rulesets/Py_Thing.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/Admin.cpp, server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp, server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp, server/Player.cpp, server/ServerRouting.cpp, server/WorldRouter.cpp: Switch to using Fragment as name for Atlas::Message::Object, to avoid name clashes on Object. * common/BaseEntity.h: Make BaseEntity inherit from SigC::Object, so signals and callbacks can be used, and add destroyed signal. * common/accountbase.h, physics/BBox.h, physics/Quaternion.h, physics/Vector3D.h, rulesets/MemMap_methods.h, rulesets/Movement.cpp, rulesets/Plant.h, rulesets/Py_Operation.cpp, rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Script.cpp, common/inheritance.cpp: Cleaned up Atlas::Message::Object use, and excessive use of "using ...". * rulesets/Movement.h, rulesets/Pedestrian.h: Use forward declarations rather than including Move.h * server/Account.cpp, server/Account.h, server/Connection.cpp, server/Connection.h: Use destroyed signal to ensure references to in game entities are removed when those entities are destroyed. Ensure Connection is only destroyed once.
94 lines
3.1 KiB
C++
94 lines
3.1 KiB
C++
// This file may be redistributed and modified only under the terms of
|
|
// the GNU General Public License (See COPYING for details).
|
|
// Copyright (C) 2000,2001 Alistair Riddoch
|
|
|
|
#include "PythonThingScript.h"
|
|
|
|
#include "Py_Operation.h"
|
|
#include "Py_Oplist.h"
|
|
|
|
#include "Thing.h"
|
|
|
|
#include <common/BaseWorld.h>
|
|
#include <common/log.h>
|
|
#include <common/debug.h>
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
PythonThingScript::PythonThingScript(PyObject * o, Thing & t) :
|
|
PythonScript(o, t), thing(t)
|
|
{
|
|
}
|
|
|
|
PythonThingScript::~PythonThingScript()
|
|
{
|
|
}
|
|
|
|
bool PythonThingScript::Operation(const std::string & op_type,
|
|
const RootOperation & op,
|
|
OpVector & ret_list, RootOperation * sub_op)
|
|
{
|
|
if (scriptObject == NULL) {
|
|
debug( std::cout << "No script object asociated" << std::endl
|
|
<< std::flush;);
|
|
return false;
|
|
}
|
|
debug( std::cout << "Got script object for " << std::endl << std::flush;);
|
|
std::string op_name = op_type+"_operation";
|
|
// Construct apropriate python object thingies from op
|
|
if (!PyObject_HasAttrString(scriptObject, (char *)(op_name.c_str()))) {
|
|
debug( std::cout << "No method to be found for "
|
|
<< "." << op_name << std::endl << std::flush;);
|
|
return false;
|
|
}
|
|
ConstOperationObject * py_op = newAtlasConstRootOperation(NULL);
|
|
py_op->operation = &op;
|
|
py_op->own = 0;
|
|
py_op->from = thing.world->getObject(op.GetFrom());
|
|
py_op->to = thing.world->getObject(op.GetTo());
|
|
PyObject * ret;
|
|
ret = PyObject_CallMethod(scriptObject, (char *)(op_name.c_str()),
|
|
"(O)", py_op);
|
|
Py_DECREF(py_op);
|
|
if (ret != NULL) {
|
|
debug( std::cout << "Called python method " << op_name
|
|
<< " for object " << std::endl << std::flush;);
|
|
if (PyOperation_Check(ret)) {
|
|
OperationObject * op = (OperationObject*)ret;
|
|
if (op->operation != NULL) {
|
|
ret_list.push_back(op->operation);
|
|
op->own = 0;
|
|
} else {
|
|
debug( std::cout << "Method returned invalid operation"
|
|
<< std::endl << std::flush;);
|
|
}
|
|
} else if (PyOplist_Check(ret)) {
|
|
OplistObject * op = (OplistObject*)ret;
|
|
if (op->ops != NULL) {
|
|
ret_list = *op->ops;
|
|
} else {
|
|
debug( std::cout << "Method returned invalid OpVector"
|
|
<< std::endl << std::flush;);
|
|
}
|
|
} else {
|
|
debug( std::cout << "Method returned invalid object" << std::endl
|
|
<< std::flush;);
|
|
}
|
|
|
|
Py_DECREF(ret);
|
|
return true;
|
|
} else {
|
|
if (PyErr_Occurred() == NULL) {
|
|
debug( std::cout << "No method to be found for " << std::endl
|
|
<< std::flush;);
|
|
} else {
|
|
log(ERROR, "Reporting python error");
|
|
PyErr_Print();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void PythonThingScript::hook(const std::string &, Entity *)
|
|
{
|
|
}
|