2011-12-16 09:20:30 +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
|
|
|
|
|
|
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "python_testers.h"
|
2011-12-16 16:04:34 +00:00
|
|
|
#include "TestWorld.h"
|
2011-12-16 09:20:30 +00:00
|
|
|
|
2011-12-16 16:04:34 +00:00
|
|
|
#include "rulesets/BaseMind.h"
|
|
|
|
|
#include "rulesets/Character.h"
|
2011-12-16 09:20:30 +00:00
|
|
|
#include "rulesets/Python_API.h"
|
|
|
|
|
#include "rulesets/MindFactory.h"
|
|
|
|
|
#include "rulesets/MindProperty.h"
|
|
|
|
|
|
2011-12-16 16:04:34 +00:00
|
|
|
#include "common/TypeNode.h"
|
|
|
|
|
|
2011-12-16 09:20:30 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2011-12-16 15:36:50 +00:00
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
|
2011-12-16 09:20:30 +00:00
|
|
|
static PyMethodDef no_methods[] = {
|
|
|
|
|
{NULL, NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("978fcfe1-6f5d-44ea-b809-9aac1480bf7f");
|
2011-12-16 09:20:30 +00:00
|
|
|
|
|
|
|
|
Py_InitModule("testmod", no_methods);
|
|
|
|
|
|
|
|
|
|
run_python_string("import server");
|
|
|
|
|
run_python_string("import testmod");
|
|
|
|
|
run_python_string("from atlas import Operation");
|
2011-12-16 15:36:50 +00:00
|
|
|
run_python_string("class settlerMind(server.Mind):\n"
|
2011-12-16 16:04:34 +00:00
|
|
|
" def __init__(self, cppthing):\n"
|
|
|
|
|
" self.mind = cppthing\n"
|
2011-12-16 09:20:30 +00:00
|
|
|
" def look_operation(self, op): pass\n"
|
|
|
|
|
" def delete_operation(self, op):\n"
|
|
|
|
|
" return Operation('sight') + Operation('move')\n"
|
|
|
|
|
" def test_hook(self, ent): pass\n"
|
|
|
|
|
);
|
|
|
|
|
run_python_string("testmod.settlerMind=settlerMind");
|
|
|
|
|
|
|
|
|
|
MindProperty * mp = new MindProperty;
|
|
|
|
|
|
2011-12-16 15:36:50 +00:00
|
|
|
MapType mind_descr;
|
|
|
|
|
|
|
|
|
|
mind_descr["language"] = "python";
|
|
|
|
|
mind_descr["name"] = "testmod.settlerMind";
|
|
|
|
|
|
|
|
|
|
mp->set(mind_descr);
|
|
|
|
|
|
|
|
|
|
MindKit * mk = mp->factory();
|
|
|
|
|
assert(mk != 0);
|
|
|
|
|
|
|
|
|
|
assert(mk->m_scriptFactory != 0);
|
|
|
|
|
|
2011-12-16 16:04:34 +00:00
|
|
|
// Set up a minimal test world
|
|
|
|
|
|
|
|
|
|
Entity * world = new Entity("0", 0);
|
|
|
|
|
|
2012-02-11 13:47:06 +00:00
|
|
|
new TestWorld(*world);
|
2011-12-16 16:04:34 +00:00
|
|
|
|
|
|
|
|
Character * test_character = new Character("1", 1);
|
|
|
|
|
|
|
|
|
|
test_character->setType(new TypeNode("settler"));
|
|
|
|
|
|
|
|
|
|
assert(test_character->m_mind == 0);
|
|
|
|
|
|
|
|
|
|
mp->apply(test_character);
|
|
|
|
|
|
|
|
|
|
assert(test_character->m_mind != 0);
|
|
|
|
|
assert(test_character->m_mind->getType() == test_character->getType());
|
|
|
|
|
|
2011-12-16 09:20:30 +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;
|
|
|
|
|
}
|