cyphesis/tests/MindPropertyintegration.cpp

111 lines
2.9 KiB
C++
Raw Permalink Normal View History

// 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 16:04:34 +00:00
#include "rulesets/BaseMind.h"
#include "rulesets/Character.h"
#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"
#include <cassert>
2011-12-16 15:36:50 +00:00
using Atlas::Message::MapType;
static PyMethodDef no_methods[] = {
{NULL, NULL} /* Sentinel */
};
int main()
{
init_python_api("978fcfe1-6f5d-44ea-b809-9aac1480bf7f");
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"
" 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);
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());
shutdown_python_api();
return 0;
}
void TestWorld::message(const Operation & op, LocatedEntity & ent)
2012-09-11 22:53:15 +01:00
{
}
LocatedEntity * TestWorld::addNewEntity(const std::string &,
const Atlas::Objects::Entity::RootEntity &)
{
return 0;
}