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"
|
|
|
|
|
|
|
|
|
|
#include "Python_API.h"
|
|
|
|
|
|
|
|
|
|
#include "Thing.h"
|
|
|
|
|
|
* client/client.cpp,
client/ObserverClient.cpp, client/ObserverClient.h,
client/ClientConnection.cpp, client/ClientConnection.h,
client/define_world.cpp, client define_world.h:
Started re-coding of python client code in C++.
* common/accountbase.h:
Database class used for simply accessing accounts.
* common/OOGThing.cpp, common/OOGThing.h, server/Account.h,
server/Routing.h:
Moved OOGThing class into common as it is not server specific.
* common/BaseWorld.cpp, common/BaseWorld.h,
server/WorldRouter.cpp, server/WorldRouter.h,
rulesets/Entity.h, rulesets/Py_World.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.h,
rulesets/Thing.cpp, rulesets/Thing.h:
Added base class for WorldRouter so that code that previously
used WorldRouter now used the interface defined by this
new class. This means that the code in rulesets no longer
has dependencies on code in server, so can be used in the client.
* server/ExternalMind.cpp, server/ExternalMind.h,
rulesets/Character.h, rulesets/Creator.cpp,
server/Account.cpp:
Moved ExternalMind class into server as it is server specific,
so that there is no dependancy on server in rulesets.
* server/Persistance.cpp. server/Persistance.h,
server/Admin.cpp, server/ServerRouting.cpp, server/server.cpp:
Moved high level server specific persistance class into
server, so there is no dependency on server in common.
* common/database.cpp, common/database.h, server/Admin.cpp,
tools/cydbload.cpp, tools/cyisoload.cpp, tools/cypasswd.cpp:
Increases efficiency of some interfaces by passing Object::MapType
instead of MapType, when the value must be a map.
* modules/WorldTime.cpp, modules/WorldTime.h,
rulesets/Py_WorldTime.cpp, rulesets/Python_API.cpp:
Brought the version of WorldTime in modules up to date, as this is
the version now used.
* rulesets/Character.cpp, server/WorldRouter.cpp, rulesets/Thing.cpp,
server/Admin.cpp:
Made world objects dictionary private.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Change newThing parameters so entity factory does not need to
know about WorldRouter.
* server/Lobby.cpp: Added support for people and rooms attributes
of OOG room class.
Al Riddoch <alriddoch@zepler.org>
2001-08-13 17:22:27 +00:00
|
|
|
#include <common/BaseWorld.h>
|
2001-04-10 19:05:14 +00:00
|
|
|
#include <common/debug.h>
|
|
|
|
|
|
|
|
|
|
using Atlas::Objects::Operation::RootOperation;
|
|
|
|
|
|
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
|
|
|
|
PythonThingScript::PythonThingScript(PyObject * o, Thing & t) :
|
|
|
|
|
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,
|
|
|
|
|
oplist & 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;
|
|
|
|
|
}
|
|
|
|
|
RootOperationObject * py_op = newAtlasRootOperation(NULL);
|
|
|
|
|
py_op->operation = new RootOperation(op);
|
|
|
|
|
py_op->own = 0;
|
* Renamed Operataion method names throughout so they no longer
all have the name Operation but are now called MoveOperation,
according to the type of operation they handle.
* modules/DateTime.cpp, modules/DataTime.h: Filled in functionality,
allowing initialisation and updating from a time values in seconds.
* modules/Location.h: Modified collision detection code so no
checking is done between two moving objects.
* rulesets/BaseMind.h, rulesets/BaseMind.cpp, rulesets/Entity.h,
rulesets/Entity.cpp: Removed virtual getMap() method and replaced
with a fixed method in BaseMind only. Added time member veriable
to BaseMind so each mind keeps track of time by itself.
* rulesets/Python_API.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h:
Added specific python interface for mind objects, because if
increasing differences in the way this must be handled.
* rulesets/Character.h, rulesets/Character.cpp: Added isAlive flag
which is cleared if the character is dead. If this flag is cleared,
operations are no longer sent to the mind.
* rulesets/Movement.h, rulesets/Movement.cpp, rulesets/Pedestrian.h,
rulesets/Pedestrian.cpp: Cleaned up the code, made members more
distinctive, and make interface more general.
* rulesets/Py_Thing.cpp: Removed features used to support mind.
* rulesets/Py_WorldTime.cpp: Added support for comparison of
time with strings, to establish whether it matches descriptions
of time.
* rulesets/Python_API.cpp: Modified creating of scripts so mind
scripts use a slightly different interface from entity scripts,
to support the fact that a mind handles its own timekeeping,
has a memory map, and has no access to the world.
* server/WorldTime.cpp, server/WorldTime.h: Brought WorldTime into
the build. Used to track details of the time. Added support for
checking time descriptions such as "midday", "summer" against
DateTime.
Al Riddoch <alriddoch@zepler.org>
2001-05-28 14:58:24 +00:00
|
|
|
py_op->from = thing.world->getObject(op.GetFrom());
|
|
|
|
|
py_op->to = thing.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);
|
|
|
|
|
delete py_op->operation;
|
|
|
|
|
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)) {
|
|
|
|
|
RootOperationObject * op = (RootOperationObject*)ret;
|
|
|
|
|
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 {
|
2001-08-14 17:52:50 +00:00
|
|
|
debug( std::cout << "Method returned invalid oplist"
|
|
|
|
|
<< 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 {
|
2001-08-14 17:52:50 +00:00
|
|
|
std::cerr << "Reporting python error for " << std::endl
|
|
|
|
|
<< std::flush;
|
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
|
|
|
{
|
|
|
|
|
}
|