2013-01-11 11:58:29 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2013 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 "TestBase.h"
|
|
|
|
|
|
|
|
|
|
#include "rulesets/Entity.h"
|
|
|
|
|
#include "rulesets/TerrainModProperty.h"
|
2013-01-12 01:19:19 +00:00
|
|
|
#include "rulesets/TerrainProperty.h"
|
2013-01-11 11:58:29 +00:00
|
|
|
|
|
|
|
|
#include "common/OperationRouter.h"
|
2013-02-14 00:04:58 +00:00
|
|
|
#include "common/PropertyFactory_impl.h"
|
2013-11-15 22:55:17 +01:00
|
|
|
#include "common/BaseWorld.h"
|
2013-01-11 11:58:29 +00:00
|
|
|
|
2014-08-26 21:05:18 +02:00
|
|
|
#include "stubs/modules/stubLocation.h"
|
|
|
|
|
|
2013-01-11 11:58:29 +00:00
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Objects::Operation::Delete;
|
|
|
|
|
using Atlas::Objects::Operation::Move;
|
|
|
|
|
|
2013-11-15 22:55:17 +01:00
|
|
|
class TestWorld : public BaseWorld {
|
|
|
|
|
public:
|
|
|
|
|
explicit TestWorld(LocatedEntity& e) : BaseWorld(e) {
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
virtual bool idle() { return false; }
|
2013-11-15 22:55:17 +01:00
|
|
|
virtual LocatedEntity * addEntity(LocatedEntity * ent) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
virtual LocatedEntity * addNewEntity(const std::string &,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity &) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void delEntity(LocatedEntity * obj) {}
|
|
|
|
|
int createSpawnPoint(const Atlas::Message::MapType & data,
|
|
|
|
|
LocatedEntity *) { return 0; }
|
2013-11-24 15:01:38 +01:00
|
|
|
int removeSpawnPoint(LocatedEntity *) {return 0; }
|
2013-11-15 22:55:17 +01:00
|
|
|
int getSpawnList(Atlas::Message::ListType & data) { return 0; }
|
|
|
|
|
LocatedEntity * spawnNewEntity(const std::string & name,
|
|
|
|
|
const std::string & type,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity & desc) {
|
|
|
|
|
return addNewEntity(type, desc);
|
|
|
|
|
}
|
2013-11-16 21:05:45 +01:00
|
|
|
virtual int moveToSpawn(const std::string & name,
|
|
|
|
|
Location& location) {return 0;}
|
2013-11-15 22:55:17 +01:00
|
|
|
virtual Task * newTask(const std::string &, LocatedEntity &) { return 0; }
|
|
|
|
|
virtual Task * activateTask(const std::string &, const std::string &,
|
|
|
|
|
LocatedEntity *, LocatedEntity &) { return 0; }
|
|
|
|
|
virtual ArithmeticScript * newArithmetic(const std::string &,
|
|
|
|
|
LocatedEntity *) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
virtual void message(const Operation & op, LocatedEntity & ent) {
|
|
|
|
|
}
|
|
|
|
|
virtual LocatedEntity * findByName(const std::string & name) { return 0; }
|
|
|
|
|
virtual LocatedEntity * findByType(const std::string & type) { return 0; }
|
|
|
|
|
virtual void addPerceptive(LocatedEntity *) { }
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-11 11:58:29 +00:00
|
|
|
class TerrainModPropertyintegration : public Cyphesis::TestBase
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
Entity * m_world;
|
|
|
|
|
Entity * m_entity;
|
|
|
|
|
PropertyBase * m_property;
|
2013-01-12 01:19:19 +00:00
|
|
|
PropertyBase * m_terrainProperty;
|
2013-01-11 11:58:29 +00:00
|
|
|
public:
|
|
|
|
|
TerrainModPropertyintegration();
|
|
|
|
|
|
|
|
|
|
void setup();
|
|
|
|
|
void teardown();
|
|
|
|
|
|
|
|
|
|
void test_move_handler();
|
|
|
|
|
void test_delete_handler();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TerrainModPropertyintegration::TerrainModPropertyintegration()
|
|
|
|
|
{
|
|
|
|
|
ADD_TEST(TerrainModPropertyintegration::test_move_handler);
|
|
|
|
|
ADD_TEST(TerrainModPropertyintegration::test_delete_handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainModPropertyintegration::setup()
|
|
|
|
|
{
|
|
|
|
|
m_world = new Entity("0", 0);
|
|
|
|
|
|
2013-11-15 22:55:17 +01:00
|
|
|
new TestWorld(*m_world);
|
|
|
|
|
|
2013-01-11 11:58:29 +00:00
|
|
|
m_entity = new Entity("1", 1);
|
2013-01-12 01:53:53 +00:00
|
|
|
m_entity->m_location.m_pos = Point3D(5.f, 5.f, 5.f);
|
2013-01-11 11:58:29 +00:00
|
|
|
m_entity->m_location.m_loc = m_world;
|
2013-01-12 01:19:19 +00:00
|
|
|
m_world->incRef();
|
2013-01-12 01:53:53 +00:00
|
|
|
ASSERT_TRUE(m_entity->m_location.isValid());
|
2013-01-11 11:58:29 +00:00
|
|
|
|
2013-02-14 00:04:58 +00:00
|
|
|
PropertyFactory<TerrainModProperty> terrainmod_property_factory;
|
2013-01-12 01:19:19 +00:00
|
|
|
|
|
|
|
|
m_terrainProperty = new TerrainProperty;
|
2013-02-13 00:45:36 +00:00
|
|
|
m_terrainProperty->install(m_world, "terrain");
|
2013-01-12 01:19:19 +00:00
|
|
|
m_world->setProperty("terrain", m_terrainProperty);
|
2013-01-12 01:53:53 +00:00
|
|
|
m_terrainProperty->apply(m_world);
|
2013-01-11 11:58:29 +00:00
|
|
|
|
|
|
|
|
m_property = terrainmod_property_factory.newProperty();
|
2013-02-13 00:45:36 +00:00
|
|
|
m_property->install(m_entity, "terrainmod");
|
2013-01-12 01:19:19 +00:00
|
|
|
m_entity->setProperty("terrainmod", m_property);
|
2013-01-12 01:53:53 +00:00
|
|
|
m_property->apply(m_entity);
|
2013-01-11 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainModPropertyintegration::teardown()
|
|
|
|
|
{
|
2013-01-12 01:19:19 +00:00
|
|
|
m_entity->decRef();
|
|
|
|
|
m_world->decRef();
|
2013-01-11 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainModPropertyintegration::test_move_handler()
|
|
|
|
|
{
|
|
|
|
|
Move m;
|
2013-01-12 01:19:19 +00:00
|
|
|
// FIXME Move needs some args, and also probably requires the position to
|
|
|
|
|
// to be set up on the entity first
|
2013-01-11 11:58:29 +00:00
|
|
|
|
|
|
|
|
OpVector res;
|
|
|
|
|
m_entity->operation(m, res);
|
|
|
|
|
|
|
|
|
|
// FIXME Check what gives
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainModPropertyintegration::test_delete_handler()
|
|
|
|
|
{
|
|
|
|
|
Delete d;
|
|
|
|
|
|
|
|
|
|
OpVector res;
|
|
|
|
|
m_entity->operation(d, res);
|
|
|
|
|
|
|
|
|
|
// FIXME Check what gives
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
TerrainModPropertyintegration t;
|
|
|
|
|
|
|
|
|
|
return t.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "rulesets/AtlasProperties.h"
|
|
|
|
|
#include "rulesets/Domain.h"
|
|
|
|
|
#include "rulesets/Script.h"
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "common/BaseWorld.h"
|
2013-01-11 11:58:29 +00:00
|
|
|
#include "common/id.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/PropertyManager.h"
|
|
|
|
|
|
|
|
|
|
#include "physics/Vector3D.h"
|
|
|
|
|
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "rulesets/DomainProperty.h"
|
|
|
|
|
#include "stubs/common/stubCustom.h"
|
|
|
|
|
#include "stubs/rulesets/stubDomain.h"
|
|
|
|
|
#include "stubs/rulesets/stubDomainProperty.h"
|
2016-01-18 16:21:00 +01:00
|
|
|
#include "stubs/rulesets/stubTransformsProperty.h"
|
2015-04-09 14:50:45 +02:00
|
|
|
#include "stubs/common/stubVariable.h"
|
|
|
|
|
#include "stubs/common/stubMonitors.h"
|
2013-01-11 11:58:29 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseWorld * BaseWorld::m_instance = 0;
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
BaseWorld::BaseWorld(LocatedEntity & gw) : m_gameWorld(gw)
|
2013-01-11 11:58:29 +00:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseWorld::~BaseWorld()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity * BaseWorld::getEntity(const std::string & id) const
|
2013-01-11 11:58:29 +00:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity * BaseWorld::getEntity(long id) const
|
2013-01-11 11:58:29 +00:00
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IdProperty::IdProperty(const std::string & data) : PropertyBase(per_ephem),
|
|
|
|
|
m_data(data)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int IdProperty::get(Atlas::Message::Element & e) const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IdProperty * IdProperty::copy() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContainsProperty::ContainsProperty(LocatedEntitySet & data) :
|
|
|
|
|
PropertyBase(per_ephem), m_data(data)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ContainsProperty::get(Atlas::Message::Element & e) const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainsProperty::set(const Atlas::Message::Element & e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainsProperty::add(const std::string & s,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity & ent) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContainsProperty * ContainsProperty::copy() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PropertyKit::~PropertyKit()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PropertyManager * PropertyManager::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
long integerId(const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
long intId = strtol(id.c_str(), 0, 10);
|
|
|
|
|
if (intId == 0 && id != "0") {
|
|
|
|
|
intId = -1L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|