cyphesis/tests/ThingTest.cpp
2016-06-26 21:50:10 +02:00

534 lines
10 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
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include "IGEntityExerciser.h"
#include "allOperations.h"
#include "rulesets/Thing.h"
#include "rulesets/Domain.h"
#include "common/const.h"
#include "common/id.h"
#include "common/log.h"
#include "common/Property_impl.h"
#include "common/TypeNode.h"
#include "stubs/common/stubCustom.h"
#include "stubs/common/stubRouter.h"
#include "stubs/common/stubTypeNode.h"
#include "stubs/common/stubPropertyManager.h"
#include "stubs/modules/stubLocation.h"
#include "stubs/common/stubProperty.h"
#include "stubs/rulesets/stubSoftProperty.h"
#include "stubs/rulesets/stubMotion.h"
#include "stubs/rulesets/stubDomain.h"
#include "stubs/rulesets/stubTransformsProperty.h"
#include "stubs/rulesets/stubPropelProperty.h"
#include "TestDomain.h"
#include <cstdlib>
#include <cassert>
using Atlas::Message::Element;
using Atlas::Message::ListType;
using Atlas::Message::MapType;
using Atlas::Objects::Entity::RootEntity;
int main()
{
Thing e("1", 1);
TypeNode type("thing");
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
void TestWorld::message(const Operation & op, LocatedEntity & ent)
{
}
LocatedEntity * TestWorld::addNewEntity(const std::string &,
const Atlas::Objects::Entity::RootEntity &)
{
return 0;
}
Entity::Entity(const std::string & id, long intId) :
LocatedEntity(id, intId), m_motion(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::GetOperation(const Operation &, OpVector &)
{
}
void Entity::InfoOperation(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::RelayOperation(const Operation &, OpVector &)
{
}
void Entity::externalOperation(const Operation & op, Link &)
{
}
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
{
}
PropertyBase * Entity::setAttr(const std::string & name,
const Atlas::Message::Element & attr)
{
return 0;
}
const PropertyBase * Entity::getProperty(const std::string & name) const
{
return 0;
}
PropertyBase * Entity::setProperty(const std::string & name,
PropertyBase * prop)
{
return m_properties[name] = prop;
}
void Entity::installDelegate(int class_no, const std::string & delegate)
{
}
void Entity::removeDelegate(int class_no, const std::string & delegate)
{
}
Domain * Entity::getMovementDomain()
{
return new TestDomain(*this);
}
const Domain * Entity::getMovementDomain() const
{
return nullptr;
}
bool LocatedEntity::isVisibleForOtherEntity(const LocatedEntity* watcher) const
{
return true;
}
void Entity::sendWorld(const Operation & op)
{
}
PropertyBase * Entity::modProperty(const std::string & name)
{
return 0;
}
void Entity::onContainered(const LocatedEntity*)
{
}
void Entity::onUpdated()
{
}
void Entity::callOperation(const Operation & op, OpVector & res)
{
}
void Entity::setType(const TypeNode * t) {
m_type = t;
}
LocatedEntity::LocatedEntity(const std::string & id, long intId) :
Router(id, intId),
m_refCount(0), m_seq(0),
m_script(0), m_type(0), m_flags(0), m_contains(0)
{
}
LocatedEntity::~LocatedEntity()
{
}
bool LocatedEntity::hasAttr(const std::string & name) const
{
return false;
}
int LocatedEntity::getAttr(const std::string & name,
Atlas::Message::Element & attr) const
{
return -1;
}
int LocatedEntity::getAttrType(const std::string & name,
Atlas::Message::Element & attr,
int type) const
{
return -1;
}
PropertyBase * LocatedEntity::setAttr(const std::string & name,
const Atlas::Message::Element & attr)
{
return 0;
}
const PropertyBase * LocatedEntity::getProperty(const std::string & name) const
{
return 0;
}
PropertyBase * LocatedEntity::modProperty(const std::string & name)
{
return 0;
}
PropertyBase * LocatedEntity::setProperty(const std::string & name,
PropertyBase * prop)
{
return 0;
}
void LocatedEntity::installDelegate(int, const std::string &)
{
}
void LocatedEntity::removeDelegate(int class_no, const std::string & delegate)
{
}
void LocatedEntity::destroy()
{
}
Domain * LocatedEntity::getMovementDomain()
{
return 0;
}
const Domain * LocatedEntity::getMovementDomain() const
{
return 0;
}
void LocatedEntity::sendWorld(const Operation & op)
{
}
void LocatedEntity::onContainered(const LocatedEntity*)
{
}
void LocatedEntity::onUpdated()
{
}
void LocatedEntity::makeContainer()
{
if (m_contains == 0) {
m_contains = new LocatedEntitySet;
}
}
void LocatedEntity::changeContainer(LocatedEntity * new_loc)
{
assert(m_location.m_loc != 0);
assert(m_location.m_loc->m_contains != 0);
m_location.m_loc->m_contains->erase(this);
if (m_location.m_loc->m_contains->empty()) {
m_location.m_loc->onUpdated();
}
new_loc->makeContainer();
bool was_empty = new_loc->m_contains->empty();
new_loc->m_contains->insert(this);
if (was_empty) {
new_loc->onUpdated();
}
assert(m_location.m_loc->checkRef() > 0);
LocatedEntity* oldLoc = m_location.m_loc;
m_location.m_loc = new_loc;
m_location.m_loc->incRef();
assert(m_location.m_loc->checkRef() > 0);
onContainered(oldLoc);
oldLoc->decRef();
}
void LocatedEntity::merge(const MapType & ent)
{
}
void LocatedEntity::addChild(LocatedEntity& childEntity)
{
}
void LocatedEntity::removeChild(LocatedEntity& childEntity)
{
}
void LocatedEntity::setType(const TypeNode* t)
{
}
std::vector<Atlas::Objects::Root> LocatedEntity::getThoughts() const
{
return std::vector<Atlas::Objects::Root>();
}
std::string LocatedEntity::describeEntity() const
{
return "";
}
void addToEntity(const Point3D & p, std::vector<double> & vd)
{
vd.resize(3);
vd[0] = p[0];
vd[1] = p[1];
vd[2] = p[2];
}
BaseWorld * BaseWorld::m_instance = 0;
BaseWorld::BaseWorld(LocatedEntity & gw) : m_gameWorld(gw)
{
m_instance = this;
}
BaseWorld::~BaseWorld()
{
m_instance = 0;
}
LocatedEntity * 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;
}
}
LocatedEntity * 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;
}
}
double BaseWorld::getTime() const
{
return 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;
}
template <typename FloatT>
int fromStdVector(Point3D & p, const std::vector<FloatT> & vf)
{
if (vf.size() != 3) {
return -1;
}
p[0] = vf[0];
p[1] = vf[1];
p[2] = vf[2];
p.setValid();
return 0;
}
template <typename FloatT>
int fromStdVector(Vector3D & v, const std::vector<FloatT> & vf)
{
if (vf.size() != 3) {
return -1;
}
v[0] = vf[0];
v[1] = vf[1];
v[2] = vf[2];
v.setValid();
return 0;
}
template int fromStdVector<double>(Point3D & p, const std::vector<double> & vf);
template int fromStdVector<double>(Vector3D & v, const std::vector<double> & vf);
float squareDistance(const Point3D & u, const Point3D & v)
{
return 1.f;
}