2009-11-14 03:18:59 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-11-14 03:18:59 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2009-11-14 03:18:59 +00:00
|
|
|
#include "rulesets/Entity.h"
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "rulesets/Py_Thing.h"
|
|
|
|
|
#include "rulesets/Python_API.h"
|
2011-12-15 23:12:45 +00:00
|
|
|
#include "rulesets/PythonScriptFactory.h"
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "rulesets/Script.h"
|
2009-11-14 03:18:59 +00:00
|
|
|
|
|
|
|
|
#include "common/Tick.h"
|
2013-11-15 22:55:17 +01:00
|
|
|
#include "common/BaseWorld.h"
|
2009-11-14 03:18:59 +00:00
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-11-15 22:55:17 +01:00
|
|
|
class TestWorld : public BaseWorld {
|
|
|
|
|
public:
|
|
|
|
|
explicit TestWorld(LocatedEntity& e) : BaseWorld(e) {
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
virtual bool idle() { return false; }
|
2013-11-15 22:55:17 +01:00
|
|
|
virtual LocatedEntity * addEntity(LocatedEntity * ent) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
virtual LocatedEntity * addNewEntity(const std::string &,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity &) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void delEntity(LocatedEntity * obj) {}
|
|
|
|
|
int createSpawnPoint(const Atlas::Message::MapType & data,
|
|
|
|
|
LocatedEntity *) { return 0; }
|
2013-11-24 15:01:38 +01:00
|
|
|
int removeSpawnPoint(LocatedEntity *) {return 0; }
|
2013-11-15 22:55:17 +01:00
|
|
|
int getSpawnList(Atlas::Message::ListType & data) { return 0; }
|
|
|
|
|
LocatedEntity * spawnNewEntity(const std::string & name,
|
|
|
|
|
const std::string & type,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity & desc) {
|
|
|
|
|
return addNewEntity(type, desc);
|
|
|
|
|
}
|
2013-11-16 21:05:45 +01:00
|
|
|
virtual int moveToSpawn(const std::string & name,
|
|
|
|
|
Location& location){return 0;}
|
2013-11-15 22:55:17 +01:00
|
|
|
virtual Task * newTask(const std::string &, LocatedEntity &) { return 0; }
|
|
|
|
|
virtual Task * activateTask(const std::string &, const std::string &,
|
|
|
|
|
LocatedEntity *, LocatedEntity &) { return 0; }
|
|
|
|
|
virtual ArithmeticScript * newArithmetic(const std::string &,
|
|
|
|
|
LocatedEntity *) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
virtual void message(const Operation & op, LocatedEntity & ent) {
|
|
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
virtual void messageToClients(const Atlas::Objects::Operation::RootOperation &) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 22:55:17 +01:00
|
|
|
virtual LocatedEntity * findByName(const std::string & name) { return 0; }
|
|
|
|
|
virtual LocatedEntity * findByType(const std::string & type) { return 0; }
|
|
|
|
|
virtual void addPerceptive(LocatedEntity *) { }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-11-14 03:18:59 +00:00
|
|
|
static PyMethodDef no_methods[] = {
|
2018-01-30 16:54:49 +01:00
|
|
|
{nullptr, nullptr} /* Sentinel */
|
2009-11-14 03:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("9fb5e26d-5631-479c-bdfc-cdb3c14b5428");
|
2009-11-14 03:18:59 +00:00
|
|
|
|
|
|
|
|
Py_InitModule("testmod", no_methods);
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("import server");
|
|
|
|
|
run_python_string("import testmod");
|
|
|
|
|
run_python_string("from atlas import Operation");
|
|
|
|
|
run_python_string("class TestEntity(server.Thing):\n"
|
|
|
|
|
" def look_operation(self, op): pass\n"
|
|
|
|
|
" def delete_operation(self, op):\n"
|
|
|
|
|
" raise AssertionError, 'deliberate'\n"
|
|
|
|
|
" def tick_operation(self, op):\n"
|
|
|
|
|
" raise AssertionError, 'deliberate'\n"
|
|
|
|
|
" def talk_operation(self, op):\n"
|
|
|
|
|
" return 'invalid result'\n"
|
|
|
|
|
" def set_operation(self, op):\n"
|
|
|
|
|
" return Operation('sight')\n"
|
|
|
|
|
" def move_operation(self, op):\n"
|
|
|
|
|
" return Operation('sight') + Operation('move')\n"
|
|
|
|
|
" def test_hook(self, ent): pass\n");
|
|
|
|
|
run_python_string("testmod.TestEntity=TestEntity");
|
2009-11-14 03:18:59 +00:00
|
|
|
|
2018-05-02 11:57:10 +02:00
|
|
|
// PyObject * package_name = PyUnicode_FromString("testmod");
|
2009-11-14 03:18:59 +00:00
|
|
|
// PyObject * testmod = PyImport_Import(package_name);
|
|
|
|
|
// Py_DECREF(package_name);
|
|
|
|
|
// assert(testmod);
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
PythonScriptFactory<LocatedEntity> psf("testmod", "TestEntity");
|
2011-11-08 20:33:56 +00:00
|
|
|
int ret = psf.setup();
|
|
|
|
|
assert(ret == 0);
|
2009-11-14 03:18:59 +00:00
|
|
|
Entity * e = new Entity("1", 1);
|
2013-11-15 22:55:17 +01:00
|
|
|
new TestWorld(*e);
|
2011-11-08 20:33:56 +00:00
|
|
|
ret = psf.addScript(e);
|
2009-11-14 03:18:59 +00:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
|
|
OpVector res;
|
|
|
|
|
Atlas::Objects::Operation::Look op1;
|
|
|
|
|
e->operation(op1, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Create op2;
|
|
|
|
|
e->operation(op2, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Delete op3;
|
|
|
|
|
e->operation(op3, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Talk op4;
|
|
|
|
|
e->operation(op4, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Set op5;
|
|
|
|
|
e->operation(op5, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Move op6;
|
|
|
|
|
e->operation(op6, res);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Tick op7;
|
|
|
|
|
e->operation(op7, res);
|
|
|
|
|
|
|
|
|
|
Script * script = e->script();
|
|
|
|
|
assert(script != 0);
|
|
|
|
|
|
|
|
|
|
script->hook("nohookfunction", e);
|
|
|
|
|
script->hook("test_hook", e);
|
|
|
|
|
|
|
|
|
|
delete e;
|
|
|
|
|
|
|
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|