mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
623 lines
11 KiB
C++
623 lines
11 KiB
C++
// Cyphesis Online RPG Server and AI Engine
|
|
// Copyright (C) 2003 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$
|
|
|
|
#include "IGEntityExerciser.h"
|
|
#include "allOperations.h"
|
|
|
|
#include "rulesets/Stackable.h"
|
|
|
|
#include "rulesets/AtlasProperties.h"
|
|
#include "rulesets/BBoxProperty.h"
|
|
#include "rulesets/Domain.h"
|
|
#include "rulesets/Script.h"
|
|
#include "rulesets/StatusProperty.h"
|
|
|
|
#include "common/id.h"
|
|
#include "common/log.h"
|
|
#include "common/Property_impl.h"
|
|
#include "common/TypeNode.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
|
|
|
using Atlas::Message::Element;
|
|
using Atlas::Message::ListType;
|
|
using Atlas::Message::MapType;
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
int main()
|
|
{
|
|
Stackable e("1", 1);
|
|
TypeNode type;
|
|
type.name() = "stackable";
|
|
e.setType(&type);
|
|
|
|
IGEntityExerciser ee(e);
|
|
|
|
// Throw an op of every type at the entity
|
|
ee.runOperations();
|
|
|
|
// Subscribe the entity to every class of op
|
|
std::set<std::string> opNames;
|
|
ee.addAllOperations(opNames);
|
|
|
|
// Throw an op of every type at the entity again now it is subscribed
|
|
ee.runOperations();
|
|
|
|
return 0;
|
|
}
|
|
|
|
// stubs
|
|
|
|
Script noScript;
|
|
|
|
namespace Atlas { namespace Objects { namespace Operation {
|
|
int ACTUATE_NO = -1;
|
|
int ATTACK_NO = -1;
|
|
int EAT_NO = -1;
|
|
int NOURISH_NO = -1;
|
|
int SETUP_NO = -1;
|
|
int TICK_NO = -1;
|
|
int UPDATE_NO = -1;
|
|
} } }
|
|
|
|
Thing::Thing(const std::string & id, long intId) :
|
|
Thing_parent(id, intId)
|
|
{
|
|
}
|
|
|
|
Thing::~Thing()
|
|
{
|
|
}
|
|
|
|
void Thing::DeleteOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Thing::MoveOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Thing::SetOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Thing::LookOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Thing::CreateOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Thing::UpdateOperation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
Entity::Entity(const std::string & id, long intId) :
|
|
LocatedEntity(id, intId), m_motion(0), m_flags(0)
|
|
{
|
|
}
|
|
|
|
Entity::~Entity()
|
|
{
|
|
}
|
|
|
|
void Entity::destroy()
|
|
{
|
|
destroyed.emit();
|
|
}
|
|
|
|
void Entity::ActuateOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::AppearanceOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::AttackOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::CombineOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::CreateOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::DeleteOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::DisappearanceOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::DivideOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::EatOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::ImaginaryOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::LookOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::MoveOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::NourishOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::SetOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::SightOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::SoundOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::TalkOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::TickOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::TouchOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::UpdateOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::UseOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::WieldOperation(const Operation &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void Entity::externalOperation(const Operation & op)
|
|
{
|
|
}
|
|
|
|
void Entity::operation(const Operation & op, OpVector & res)
|
|
{
|
|
}
|
|
|
|
void Entity::addToMessage(Atlas::Message::MapType & omap) const
|
|
{
|
|
}
|
|
|
|
void Entity::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
void Entity::setAttr(const std::string & name,
|
|
const Atlas::Message::Element & attr)
|
|
{
|
|
}
|
|
|
|
const PropertyBase * Entity::getProperty(const std::string & name) const
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
PropertyBase * Entity::modProperty(const std::string & name)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void Entity::onContainered()
|
|
{
|
|
}
|
|
|
|
void Entity::onUpdated()
|
|
{
|
|
}
|
|
|
|
LocatedEntity::LocatedEntity(const std::string & id, long intId) :
|
|
Router(id, intId),
|
|
m_refCount(0), m_seq(0),
|
|
m_script(&noScript), m_type(0), m_contains(0)
|
|
{
|
|
}
|
|
|
|
LocatedEntity::~LocatedEntity()
|
|
{
|
|
}
|
|
|
|
bool LocatedEntity::hasAttr(const std::string & name) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool LocatedEntity::getAttr(const std::string & name, Atlas::Message::Element & attr) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool LocatedEntity::getAttrType(const std::string & name,
|
|
Atlas::Message::Element & attr,
|
|
int type) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void LocatedEntity::setAttr(const std::string & name, const Atlas::Message::Element & attr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const PropertyBase * LocatedEntity::getProperty(const std::string & name) const
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void LocatedEntity::onContainered()
|
|
{
|
|
}
|
|
|
|
void LocatedEntity::onUpdated()
|
|
{
|
|
}
|
|
|
|
void LocatedEntity::makeContainer()
|
|
{
|
|
if (m_contains == 0) {
|
|
m_contains = new LocatedEntitySet;
|
|
}
|
|
}
|
|
|
|
void LocatedEntity::merge(const MapType & ent)
|
|
{
|
|
}
|
|
|
|
Domain * Domain::m_instance = new Domain();
|
|
|
|
Domain::Domain() : m_refCount(0)
|
|
{
|
|
}
|
|
|
|
Domain::~Domain()
|
|
{
|
|
}
|
|
|
|
float Domain::constrainHeight(LocatedEntity * parent,
|
|
const Point3D & pos,
|
|
const std::string & mode)
|
|
{
|
|
return 0.f;
|
|
}
|
|
|
|
void Domain::tick(double t)
|
|
{
|
|
|
|
}
|
|
|
|
void addToEntity(const Point3D & p, std::vector<double> & vd)
|
|
{
|
|
vd.resize(3);
|
|
vd[0] = p[0];
|
|
vd[1] = p[1];
|
|
vd[2] = p[2];
|
|
}
|
|
|
|
Router::Router(const std::string & id, long intId) : m_id(id),
|
|
m_intId(intId)
|
|
{
|
|
}
|
|
|
|
Router::~Router()
|
|
{
|
|
}
|
|
|
|
void Router::addToMessage(Atlas::Message::MapType & omap) const
|
|
{
|
|
}
|
|
|
|
void Router::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
void Router::error(const Operation & op,
|
|
const std::string & errstring,
|
|
OpVector & res,
|
|
const std::string & to) const
|
|
{
|
|
}
|
|
|
|
BaseWorld * BaseWorld::m_instance = 0;
|
|
|
|
BaseWorld::BaseWorld(Entity & gw) : m_gameWorld(gw)
|
|
{
|
|
m_instance = this;
|
|
}
|
|
|
|
BaseWorld::~BaseWorld()
|
|
{
|
|
m_instance = 0;
|
|
}
|
|
|
|
Entity * BaseWorld::getEntity(const std::string & id) const
|
|
{
|
|
long intId = integerId(id);
|
|
|
|
EntityDict::const_iterator I = m_eobjects.find(intId);
|
|
if (I != m_eobjects.end()) {
|
|
assert(I->second != 0);
|
|
return I->second;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
Entity * BaseWorld::getEntity(long id) const
|
|
{
|
|
EntityDict::const_iterator I = m_eobjects.find(id);
|
|
if (I != m_eobjects.end()) {
|
|
assert(I->second != 0);
|
|
return I->second;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
Script::Script()
|
|
{
|
|
}
|
|
|
|
/// \brief Script destructor
|
|
Script::~Script()
|
|
{
|
|
}
|
|
|
|
bool Script::operation(const std::string & opname,
|
|
const Atlas::Objects::Operation::RootOperation & op,
|
|
OpVector & res)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void Script::hook(const std::string & function, LocatedEntity * entity)
|
|
{
|
|
}
|
|
|
|
void Location::addToMessage(MapType & omap) const
|
|
{
|
|
}
|
|
|
|
Location::Location()
|
|
{
|
|
}
|
|
|
|
Location::Location(LocatedEntity * rf, const Point3D & pos)
|
|
{
|
|
}
|
|
|
|
void Location::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
TypeNode::TypeNode() : m_parent(0)
|
|
{
|
|
}
|
|
|
|
TypeNode::~TypeNode()
|
|
{
|
|
}
|
|
|
|
IdProperty::IdProperty(const std::string & data) : PropertyBase(per_ephem),
|
|
m_data(data)
|
|
{
|
|
}
|
|
|
|
bool IdProperty::get(Atlas::Message::Element & e) const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void IdProperty::set(const Atlas::Message::Element & e)
|
|
{
|
|
}
|
|
|
|
void IdProperty::add(const std::string & key,
|
|
Atlas::Message::MapType & ent) const
|
|
{
|
|
}
|
|
|
|
void IdProperty::add(const std::string & key,
|
|
const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
PropertyBase::PropertyBase(unsigned int flags) : m_flags(flags)
|
|
{
|
|
}
|
|
|
|
PropertyBase::~PropertyBase()
|
|
{
|
|
}
|
|
|
|
void PropertyBase::install(Entity *)
|
|
{
|
|
}
|
|
|
|
void PropertyBase::apply(Entity *)
|
|
{
|
|
}
|
|
|
|
void PropertyBase::add(const std::string & s,
|
|
Atlas::Message::MapType & ent) const
|
|
{
|
|
get(ent[s]);
|
|
}
|
|
|
|
void PropertyBase::add(const std::string & s,
|
|
const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
template<>
|
|
void Property<int>::set(const Atlas::Message::Element & e)
|
|
{
|
|
if (e.isInt()) {
|
|
this->m_data = e.asInt();
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void Property<double>::set(const Atlas::Message::Element & e)
|
|
{
|
|
if (e.isNum()) {
|
|
this->m_data = e.asNum();
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void Property<std::string>::set(const Atlas::Message::Element & e)
|
|
{
|
|
if (e.isString()) {
|
|
this->m_data = e.String();
|
|
}
|
|
}
|
|
|
|
template class Property<int>;
|
|
template class Property<double>;
|
|
template class Property<std::string>;
|
|
|
|
SoftProperty::SoftProperty()
|
|
{
|
|
}
|
|
|
|
SoftProperty::SoftProperty(const Atlas::Message::Element & data) :
|
|
PropertyBase(0), m_data(data)
|
|
{
|
|
}
|
|
|
|
bool SoftProperty::get(Atlas::Message::Element & val) const
|
|
{
|
|
val = m_data;
|
|
return true;
|
|
}
|
|
|
|
void SoftProperty::set(const Atlas::Message::Element & val)
|
|
{
|
|
}
|
|
|
|
ContainsProperty::ContainsProperty(LocatedEntitySet & data) :
|
|
PropertyBase(per_ephem), m_data(data)
|
|
{
|
|
}
|
|
|
|
bool ContainsProperty::get(Atlas::Message::Element & e) const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void ContainsProperty::set(const Atlas::Message::Element & e)
|
|
{
|
|
}
|
|
|
|
void ContainsProperty::add(const std::string & s,
|
|
const Atlas::Objects::Entity::RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
StatusProperty::StatusProperty()
|
|
{
|
|
}
|
|
|
|
void StatusProperty::apply(Entity * owner)
|
|
{
|
|
}
|
|
|
|
BBoxProperty::BBoxProperty()
|
|
{
|
|
}
|
|
|
|
void BBoxProperty::apply(Entity * ent)
|
|
{
|
|
}
|
|
|
|
bool BBoxProperty::get(Element & val) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void BBoxProperty::set(const Element & val)
|
|
{
|
|
}
|
|
|
|
void BBoxProperty::add(const std::string & key,
|
|
MapType & map) const
|
|
{
|
|
}
|
|
|
|
void BBoxProperty::add(const std::string & key,
|
|
const RootEntity & ent) const
|
|
{
|
|
}
|
|
|
|
PropertyManager * PropertyManager::m_instance = 0;
|
|
|
|
PropertyManager::PropertyManager()
|
|
{
|
|
assert(m_instance == 0);
|
|
m_instance = this;
|
|
}
|
|
|
|
PropertyManager::~PropertyManager()
|
|
{
|
|
m_instance = 0;
|
|
}
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
{
|
|
}
|
|
|
|
long integerId(const std::string & id)
|
|
{
|
|
long intId = strtol(id.c_str(), 0, 10);
|
|
if (intId == 0 && id != "0") {
|
|
intId = -1L;
|
|
}
|
|
|
|
return intId;
|
|
}
|