2001-04-10 19:05:14 +00:00
|
|
|
// This file may be redistributed and modified only under the terms of
|
|
|
|
|
// the GNU General Public License (See COPYING for details).
|
2001-04-16 16:26:44 +00:00
|
|
|
// Copyright (C) 2000,2001 Alistair Riddoch
|
2001-04-10 19:05:14 +00:00
|
|
|
|
|
|
|
|
#include "PythonThingScript.h"
|
|
|
|
|
|
* client/ClientConnection.cpp, client/ClientConnection.h,
tools/cycmd.cpp: Switched to using skstream to completely handle
client socket connections.
* client/ClientConnection.cpp, client/ClientConnection.h,
common/log.cpp, rulesets/EntityFactory.h, rulesets/MemMap.h,
server/server.cpp, tools/cycmd.cpp: Removed unused includes.
* client/Py_CreatorClient.cpp, client/client.cpp,
client/define_world.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Location.h, rulesets/Py_Map.cpp,
rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h,
rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h,
rulesets/Py_Optime.cpp, rulesets/Py_Optime.h,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h,
rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, server/server.cpp:
Reorganised python header files so that each header includes
all the code relevant for a particular type. Tidied up
the type implementations. Added prototypes to init_python_api()
to the Python_API.h header, and removed other dependencies from
it.
Al Riddoch <alriddoch@zepler.org>
2001-10-19 11:35:07 +00:00
|
|
|
#include "Py_Operation.h"
|
|
|
|
|
#include "Py_Oplist.h"
|
2001-04-10 19:05:14 +00:00
|
|
|
|
|
|
|
|
#include "Thing.h"
|
|
|
|
|
|
2003-03-07 00:22:12 +00:00
|
|
|
#include "common/BaseWorld.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/debug.h"
|
2001-04-10 19:05:14 +00:00
|
|
|
|
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
2002-11-25 Al Riddoch <alriddoch@zepler.org>
* common/Database.h, common/Database.cpp, server/Persistance.cpp:
Finish entity table creation code, and test it.
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityFactory.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Python_API.h,
rulesets/Thing.cpp, rulesets/Thing.h, server/EntityFactory.cpp,
server/EntityFactory.h, server/WorldRouter.cpp: Sort out
some incorrect use of Thing instead of Entity. Move some code
from Thing into Entity.
2002-11-25 22:48:13 +00:00
|
|
|
PythonThingScript::PythonThingScript(PyObject * o, Entity & t) :
|
2001-04-10 19:05:14 +00:00
|
|
|
PythonScript(o, t), thing(t)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PythonThingScript::~PythonThingScript()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-02 14:27:06 +00:00
|
|
|
bool PythonThingScript::Operation(const std::string & op_type,
|
|
|
|
|
const RootOperation & op,
|
2002-03-08 14:58:40 +00:00
|
|
|
OpVector & ret_list, RootOperation * sub_op)
|
2001-04-10 19:05:14 +00:00
|
|
|
{
|
2001-04-11 14:34:15 +00:00
|
|
|
if (scriptObject == NULL) {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "No script object asociated" << std::endl
|
|
|
|
|
<< std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "Got script object for " << std::endl << std::flush;);
|
2001-08-02 14:27:06 +00:00
|
|
|
std::string op_name = op_type+"_operation";
|
2001-04-10 19:05:14 +00:00
|
|
|
// Construct apropriate python object thingies from op
|
2001-04-11 14:34:15 +00:00
|
|
|
if (!PyObject_HasAttrString(scriptObject, (char *)(op_name.c_str()))) {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "No method to be found for "
|
|
|
|
|
<< "." << op_name << std::endl << std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2002-05-17 17:18:40 +00:00
|
|
|
ConstOperationObject * py_op = newAtlasConstRootOperation(NULL);
|
|
|
|
|
py_op->operation = &op;
|
2001-04-10 19:05:14 +00:00
|
|
|
py_op->own = 0;
|
2003-05-03 19:52:41 +00:00
|
|
|
py_op->from = thing.m_world->getObject(op.GetFrom());
|
|
|
|
|
py_op->to = thing.m_world->getObject(op.GetTo());
|
2001-04-10 19:05:14 +00:00
|
|
|
PyObject * ret;
|
2001-04-11 14:34:15 +00:00
|
|
|
ret = PyObject_CallMethod(scriptObject, (char *)(op_name.c_str()),
|
2001-04-10 19:05:14 +00:00
|
|
|
"(O)", py_op);
|
|
|
|
|
Py_DECREF(py_op);
|
|
|
|
|
if (ret != NULL) {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "Called python method " << op_name
|
|
|
|
|
<< " for object " << std::endl << std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
if (PyOperation_Check(ret)) {
|
* client/ClientConnection.cpp, client/ClientConnection.h,
tools/cycmd.cpp: Switched to using skstream to completely handle
client socket connections.
* client/ClientConnection.cpp, client/ClientConnection.h,
common/log.cpp, rulesets/EntityFactory.h, rulesets/MemMap.h,
server/server.cpp, tools/cycmd.cpp: Removed unused includes.
* client/Py_CreatorClient.cpp, client/client.cpp,
client/define_world.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Location.h, rulesets/Py_Map.cpp,
rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h,
rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h,
rulesets/Py_Optime.cpp, rulesets/Py_Optime.h,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h,
rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, server/server.cpp:
Reorganised python header files so that each header includes
all the code relevant for a particular type. Tidied up
the type implementations. Added prototypes to init_python_api()
to the Python_API.h header, and removed other dependencies from
it.
Al Riddoch <alriddoch@zepler.org>
2001-10-19 11:35:07 +00:00
|
|
|
OperationObject * op = (OperationObject*)ret;
|
2001-04-10 19:05:14 +00:00
|
|
|
if (op->operation != NULL) {
|
|
|
|
|
ret_list.push_back(op->operation);
|
|
|
|
|
op->own = 0;
|
|
|
|
|
} else {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "Method returned invalid operation"
|
|
|
|
|
<< std::endl << std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
}
|
|
|
|
|
} else if (PyOplist_Check(ret)) {
|
|
|
|
|
OplistObject * op = (OplistObject*)ret;
|
|
|
|
|
if (op->ops != NULL) {
|
|
|
|
|
ret_list = *op->ops;
|
|
|
|
|
} else {
|
2002-03-08 14:58:40 +00:00
|
|
|
debug( std::cout << "Method returned invalid OpVector"
|
2001-08-14 17:52:50 +00:00
|
|
|
<< std::endl << std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "Method returned invalid object" << std::endl
|
|
|
|
|
<< std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_DECREF(ret);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if (PyErr_Occurred() == NULL) {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "No method to be found for " << std::endl
|
|
|
|
|
<< std::flush;);
|
2001-04-10 19:05:14 +00:00
|
|
|
} else {
|
2002-07-14 21:04:50 +00:00
|
|
|
log(ERROR, "Reporting python error");
|
2001-04-10 19:05:14 +00:00
|
|
|
PyErr_Print();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-02 14:27:06 +00:00
|
|
|
void PythonThingScript::hook(const std::string &, Entity *)
|
2001-04-10 19:05:14 +00:00
|
|
|
{
|
|
|
|
|
}
|