2011-09-21 10:25:55 +01:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2011 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-12-15 11:28:36 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2011-09-21 10:25:55 +01:00
|
|
|
#include "server/EntityRuleHandler.h"
|
|
|
|
|
|
|
|
|
|
#include "server/EntityBuilder.h"
|
2018-04-25 20:09:14 +02:00
|
|
|
#include "server/CorePropertyManager.h"
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
#include "common/TypeNode.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Objects::Root;
|
|
|
|
|
using Atlas::Objects::Entity::Anonymous;
|
|
|
|
|
|
|
|
|
|
static TypeNode * stub_addChild_result = 0;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
EntityBuilder eb;
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2011-09-21 10:25:55 +01:00
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 11:18:55 +01:00
|
|
|
// check() not a class
|
2011-09-21 10:25:55 +01:00
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
Anonymous description;
|
2017-07-24 13:39:22 +02:00
|
|
|
description->setParent("foo");
|
2011-09-21 10:25:55 +01:00
|
|
|
int ret = rh->check(description);
|
|
|
|
|
|
|
|
|
|
assert(ret == -1);
|
|
|
|
|
|
|
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 11:18:55 +01:00
|
|
|
// check() stub says it's not a task
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2011-09-21 11:18:55 +01:00
|
|
|
|
|
|
|
|
Anonymous description;
|
|
|
|
|
description->setObjtype("class");
|
2017-07-24 13:39:22 +02:00
|
|
|
description->setParent("foo");
|
2011-09-21 11:18:55 +01:00
|
|
|
int ret = rh->check(description);
|
|
|
|
|
|
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 10:25:55 +01:00
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2018-05-10 00:21:30 +02:00
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes;
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
Anonymous description;
|
2011-09-21 11:18:55 +01:00
|
|
|
description->setId("class_name");
|
2011-09-21 10:25:55 +01:00
|
|
|
std::string dependent, reason;
|
|
|
|
|
|
2011-09-21 11:18:55 +01:00
|
|
|
int ret = rh->install("class_name", "parent_name",
|
2018-05-10 00:21:30 +02:00
|
|
|
description, dependent, reason, changes);
|
2011-09-21 11:18:55 +01:00
|
|
|
|
|
|
|
|
assert(ret == 1);
|
|
|
|
|
assert(dependent == "parent_name");
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Install a rule with addChild rigged to give a correct result
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2018-05-10 00:21:30 +02:00
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes;
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
Anonymous description;
|
2011-09-21 11:18:55 +01:00
|
|
|
description->setId("class_name");
|
2011-09-21 10:25:55 +01:00
|
|
|
std::string dependent, reason;
|
|
|
|
|
|
|
|
|
|
stub_addChild_result = (TypeNode *) malloc(sizeof(TypeNode));
|
2011-09-21 11:18:55 +01:00
|
|
|
int ret = rh->install("class_name", "parent_name",
|
2018-05-10 00:21:30 +02:00
|
|
|
description, dependent, reason, changes);
|
2011-09-21 10:25:55 +01:00
|
|
|
|
2011-09-21 11:18:55 +01:00
|
|
|
assert(ret == 1);
|
|
|
|
|
assert(dependent == "parent_name");
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
free(stub_addChild_result);
|
|
|
|
|
stub_addChild_result = 0;
|
|
|
|
|
|
|
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
RuleHandler * rh = new EntityRuleHandler(&eb);
|
2018-05-10 00:21:30 +02:00
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate> changes;
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
Anonymous description;
|
2018-05-10 00:21:30 +02:00
|
|
|
int ret = rh->update("", description, changes);
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
// FIXME Currently does nothing
|
|
|
|
|
assert(ret == -1);
|
|
|
|
|
|
|
|
|
|
delete rh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "server/EntityFactory.h"
|
2011-09-21 11:18:55 +01:00
|
|
|
#include "server/Player.h"
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/python/PythonScriptFactory.h"
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
#include "common/Inheritance.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
|
2018-08-03 19:19:55 +02:00
|
|
|
#include "stubs/server/stubEntityBuilder.h"
|
2011-09-21 11:18:55 +01:00
|
|
|
|
2011-12-15 01:00:28 +00:00
|
|
|
template <class T>
|
|
|
|
|
PythonScriptFactory<T>::PythonScriptFactory(const std::string & package,
|
2011-09-21 11:18:55 +01:00
|
|
|
const std::string & type) :
|
2011-12-15 11:28:36 +00:00
|
|
|
PythonClass(package,
|
2018-07-24 21:18:50 +02:00
|
|
|
type)
|
2011-09-21 11:18:55 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 01:00:28 +00:00
|
|
|
template <class T>
|
|
|
|
|
int PythonScriptFactory<T>::setup()
|
2011-11-08 20:32:35 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 01:00:28 +00:00
|
|
|
template <class T>
|
|
|
|
|
const std::string & PythonScriptFactory<T>::package() const
|
2011-11-08 20:32:35 +00:00
|
|
|
{
|
|
|
|
|
return m_package;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 01:00:28 +00:00
|
|
|
template <class T>
|
|
|
|
|
int PythonScriptFactory<T>::addScript(T * entity) const
|
2011-09-21 11:18:55 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
template class PythonScriptFactory<LocatedEntity>;
|
2011-12-15 01:00:28 +00:00
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
int PythonScriptFactory<T>::refreshClass()
|
2011-09-21 11:18:55 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "stubs/rules/python/stubPythonClass.h"
|
2011-11-08 20:32:35 +00:00
|
|
|
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#ifndef STUB_Inheritance_addChild
|
|
|
|
|
#define STUB_Inheritance_addChild
|
|
|
|
|
TypeNode* Inheritance::addChild(const Atlas::Objects::Root & obj)
|
2011-09-21 10:25:55 +01:00
|
|
|
{
|
|
|
|
|
return stub_addChild_result;
|
|
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
#endif //STUB_Inheritance_addChild
|
2011-09-21 10:25:55 +01:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
|
|
|
|
|
#ifndef STUB_Inheritance_hasClass
|
|
|
|
|
#define STUB_Inheritance_hasClass
|
2011-09-21 10:25:55 +01:00
|
|
|
bool Inheritance::hasClass(const std::string & parent)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
#endif //STUB_Inheritance_hasClass
|
|
|
|
|
|
|
|
|
|
#include "stubs/common/stubInheritance.h"
|
2011-09-21 10:25:55 +01:00
|
|
|
|
|
|
|
|
Root atlasOpDefinition(const std::string & name, const std::string & parent)
|
|
|
|
|
{
|
|
|
|
|
return Root();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-09-21 11:18:55 +01:00
|
|
|
|
2018-01-19 21:35:48 +01:00
|
|
|
#include "stubs/common/stubEntityKit.h"
|
|
|
|
|
#include "stubs/server/stubEntityFactory.h"
|
|
|
|
|
|
|
|
|
|
class Thing;
|
|
|
|
|
class Character;
|
|
|
|
|
class Creator;
|
|
|
|
|
class Plant;
|
|
|
|
|
class Stackable;
|
|
|
|
|
class Entity;
|
|
|
|
|
class World;
|
|
|
|
|
|
|
|
|
|
template class EntityFactory<Entity>;
|
|
|
|
|
template class EntityFactory<Thing>;
|
|
|
|
|
template class EntityFactory<Character>;
|
|
|
|
|
template class EntityFactory<Creator>;
|
|
|
|
|
template class EntityFactory<Plant>;
|
|
|
|
|
template class EntityFactory<Stackable>;
|
|
|
|
|
template class EntityFactory<World>;
|
2011-09-21 11:18:55 +01:00
|
|
|
|