2009-11-16 03:14:53 +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-16 03:14:53 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2010-07-13 18:39:03 +01:00
|
|
|
#include "TestWorld.h"
|
|
|
|
|
|
2009-11-16 03:14:53 +00:00
|
|
|
#include "rulesets/Python_API.h"
|
|
|
|
|
#include "rulesets/Py_Thing.h"
|
|
|
|
|
#include "rulesets/Entity.h"
|
|
|
|
|
#include "rulesets/LineProperty.h"
|
|
|
|
|
#include "rulesets/StatisticsProperty.h"
|
|
|
|
|
#include "rulesets/TerrainProperty.h"
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
static PyObject * add_properties(PyObject * self, PyEntity * o)
|
|
|
|
|
{
|
2011-12-13 19:39:09 +00:00
|
|
|
if (!PyEntity_Check(o)) {
|
2009-11-16 03:14:53 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "Unknown Object type");
|
2018-01-30 16:54:49 +01:00
|
|
|
return nullptr;
|
2009-11-16 03:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Entity * ent = o->m_entity.e;
|
|
|
|
|
|
|
|
|
|
PropertyBase * p = ent->setProperty("statistics", new StatisticsProperty);
|
2013-02-13 00:45:36 +00:00
|
|
|
p->install(ent, "statistics");
|
2009-11-16 03:14:53 +00:00
|
|
|
p->apply(ent);
|
2016-07-19 20:44:03 +02:00
|
|
|
ent->propertyApplied("statistics", *p);
|
2009-11-16 03:14:53 +00:00
|
|
|
p = ent->setProperty("terrain", new TerrainProperty);
|
2013-02-13 00:45:36 +00:00
|
|
|
p->install(ent, "terrain");
|
2009-11-16 03:14:53 +00:00
|
|
|
p->apply(ent);
|
2016-07-19 20:44:03 +02:00
|
|
|
ent->propertyApplied("terrain", *p);
|
2009-11-16 03:14:53 +00:00
|
|
|
p = ent->setProperty("line", new LineProperty);
|
2013-02-13 00:45:36 +00:00
|
|
|
p->install(ent, "line");
|
2009-11-16 03:14:53 +00:00
|
|
|
p->apply(ent);
|
2016-07-19 20:44:03 +02:00
|
|
|
ent->propertyApplied("line", *p);
|
2009-11-16 03:14:53 +00:00
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMethodDef testprop_methods[] = {
|
|
|
|
|
{"add_properties", (PyCFunction)add_properties, METH_O},
|
2018-01-30 16:54:49 +01:00
|
|
|
{nullptr, nullptr} /* Sentinel */
|
2009-11-16 03:14:53 +00:00
|
|
|
};
|
|
|
|
|
|
2018-05-04 19:17:55 +02:00
|
|
|
static PyObject* init_testprop() {
|
|
|
|
|
static struct PyModuleDef def = {
|
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
|
"testprop",
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
testprop_methods,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PyModule_Create(&def);
|
2009-11-16 03:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2018-05-04 19:17:55 +02:00
|
|
|
PyImport_AppendInittab("testprop", &init_testprop);
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("b513b7b1-b0d8-4495-b3f0-54c2ef3f27f6");
|
2009-11-16 03:14:53 +00:00
|
|
|
|
|
|
|
|
|
2010-07-13 18:39:03 +01:00
|
|
|
Entity wrld("0", 0);
|
|
|
|
|
TestWorld tw(wrld);
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("from server import *");
|
|
|
|
|
run_python_string("import testprop");
|
|
|
|
|
run_python_string("t=Thing('1')");
|
2018-05-12 00:42:43 +02:00
|
|
|
expect_python_error("t.props.line", PyExc_AttributeError);
|
|
|
|
|
expect_python_error("t.props.statistics", PyExc_AttributeError);
|
|
|
|
|
expect_python_error("t.props.terrain", PyExc_AttributeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("testprop.add_properties(t)");
|
2018-05-12 00:42:43 +02:00
|
|
|
run_python_string("t.props.line");
|
|
|
|
|
run_python_string("t.props.statistics");
|
|
|
|
|
run_python_string("t.props.terrain");
|
2009-11-16 03:14:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-09-06 13:48:40 +01:00
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void TestWorld::message(const Operation & op, LocatedEntity & ent)
|
2012-09-11 22:53:15 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity * TestWorld::addNewEntity(const std::string &,
|
2012-09-06 13:48:40 +01:00
|
|
|
const Atlas::Objects::Entity::RootEntity &)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|