2009-08-19 02:47:15 +01: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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVER_RULESET_H
|
|
|
|
|
#define SERVER_RULESET_H
|
|
|
|
|
|
2018-05-10 00:21:30 +02:00
|
|
|
#include "common/TypeNode.h"
|
|
|
|
|
#include "common/Singleton.h"
|
|
|
|
|
|
2009-08-19 02:47:15 +01:00
|
|
|
#include <Atlas/Objects/Root.h>
|
|
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
2018-05-10 00:21:30 +02:00
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
|
2018-04-29 11:58:35 +02:00
|
|
|
#include <memory>
|
2018-05-10 00:21:30 +02:00
|
|
|
#include <boost/asio/io_service.hpp>
|
2018-04-29 11:58:35 +02:00
|
|
|
|
2009-08-19 02:47:15 +01:00
|
|
|
class EntityBuilder;
|
|
|
|
|
class EntityKit;
|
2011-09-18 00:53:32 +01:00
|
|
|
class RuleHandler;
|
2018-04-29 11:58:35 +02:00
|
|
|
class EntityRuleHandler;
|
|
|
|
|
class TaskRuleHandler;
|
|
|
|
|
class OpRuleHandler;
|
|
|
|
|
class PropertyRuleHandler;
|
|
|
|
|
class ArchetypeRuleHandler;
|
2009-08-19 02:47:15 +01:00
|
|
|
class TaskKit;
|
|
|
|
|
|
|
|
|
|
/// \brief Class to handle rules that cannot yet be installed, and the reason
|
|
|
|
|
class RuleWaiting {
|
|
|
|
|
public:
|
|
|
|
|
/// Name of the rule.
|
|
|
|
|
std::string name;
|
|
|
|
|
/// Complete description of the rule.
|
|
|
|
|
Atlas::Objects::Root desc;
|
|
|
|
|
/// Message giving a description of why this rule has not been installed.
|
|
|
|
|
std::string reason;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::multimap<std::string, RuleWaiting> RuleWaitList;
|
|
|
|
|
|
|
|
|
|
/// \brief Builder to handle the creation of all entities for the world.
|
|
|
|
|
///
|
|
|
|
|
/// Uses PersistantThingFactory to store information about entity types, and
|
|
|
|
|
/// create them. Handles connecting entities to their persistor as required.
|
2018-05-10 00:21:30 +02:00
|
|
|
class Ruleset : public Singleton<Ruleset>{
|
2009-08-19 02:47:15 +01:00
|
|
|
protected:
|
2018-04-29 11:58:35 +02:00
|
|
|
std::unique_ptr<TaskRuleHandler>m_taskHandler;
|
|
|
|
|
std::unique_ptr<EntityRuleHandler> m_entityHandler;
|
|
|
|
|
std::unique_ptr<OpRuleHandler> m_opHandler;
|
|
|
|
|
std::unique_ptr<PropertyRuleHandler> m_propertyHandler;
|
|
|
|
|
std::unique_ptr<ArchetypeRuleHandler> m_archetypeHandler;
|
2009-08-19 02:47:15 +01:00
|
|
|
|
|
|
|
|
RuleWaitList m_waitingRules;
|
|
|
|
|
|
2018-05-10 00:21:30 +02:00
|
|
|
std::set<boost::filesystem::path> m_changedRules;
|
|
|
|
|
|
|
|
|
|
boost::asio::io_service& m_io_service;
|
|
|
|
|
|
2009-11-04 19:01:26 +00:00
|
|
|
void installItem(const std::string & class_name,
|
2018-05-10 00:21:30 +02:00
|
|
|
const Atlas::Objects::Root & class_desc,
|
|
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate>& changes);
|
2009-11-04 19:01:26 +00:00
|
|
|
int installRuleInner(const std::string & class_name,
|
|
|
|
|
const Atlas::Objects::Root & class_desc,
|
|
|
|
|
std::string & dependent,
|
2018-05-10 00:21:30 +02:00
|
|
|
std::string & reason,
|
|
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate>& changes);
|
|
|
|
|
int modifyRuleInner(const std::string &class_name,
|
|
|
|
|
const Atlas::Objects::Root &class_desc,
|
|
|
|
|
std::map<const TypeNode *, TypeNode::PropertiesUpdate> &changes);
|
|
|
|
|
|
2012-01-19 19:34:20 +00:00
|
|
|
void getRulesFromFiles(const std::string &,
|
|
|
|
|
std::map<std::string, Atlas::Objects::Root> &);
|
2009-08-19 02:47:15 +01:00
|
|
|
void waitForRule(const std::string & class_name,
|
|
|
|
|
const Atlas::Objects::Root & class_desc,
|
|
|
|
|
const std::string & dependent,
|
|
|
|
|
const std::string & reason);
|
2018-05-10 00:21:30 +02:00
|
|
|
|
|
|
|
|
void processChangedRules();
|
2009-08-19 02:47:15 +01:00
|
|
|
public:
|
2018-05-10 00:21:30 +02:00
|
|
|
explicit Ruleset(EntityBuilder * eb, boost::asio::io_service& io_service);
|
|
|
|
|
~Ruleset();
|
|
|
|
|
|
|
|
|
|
void loadRules(const std::string &);
|
2009-08-19 02:47:15 +01:00
|
|
|
|
|
|
|
|
int installRule(const std::string & class_name,
|
2012-01-19 19:34:20 +00:00
|
|
|
const std::string & section,
|
2009-08-19 02:47:15 +01:00
|
|
|
const Atlas::Objects::Root & class_desc);
|
|
|
|
|
int modifyRule(const std::string & class_name,
|
|
|
|
|
const Atlas::Objects::Root & class_desc);
|
2012-12-20 19:11:23 +00:00
|
|
|
|
|
|
|
|
friend class Rulesetintegration;
|
2018-05-10 00:21:30 +02:00
|
|
|
|
2009-08-19 02:47:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SERVER_RULESET_H
|