2010-07-31 01:20:53 +01:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2010 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
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-11-23 16:11:21 +00:00
|
|
|
#include "rulesets/ExternalMind.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
#include "server/Connection.h"
|
|
|
|
|
|
|
|
|
|
#include "rulesets/Entity.h"
|
|
|
|
|
|
|
|
|
|
#include "common/BaseWorld.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
class TestExternalMind : public ExternalMind
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TestExternalMind(Entity & e) : ExternalMind(e) { }
|
|
|
|
|
|
|
|
|
|
void test_deleteEntity(const std::string & id) {
|
2014-01-23 21:17:13 +01:00
|
|
|
deleteEntity(id, false);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_purgeEntity(const LocatedEntity & ent) {
|
|
|
|
|
purgeEntity(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_setLossTime(double t) { m_lossTime = t; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int stub_baseworld_receieved_op = -1;
|
2012-08-02 15:29:49 +01:00
|
|
|
int stub_link_send_op = -1;
|
|
|
|
|
int stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
class TestWorld : public BaseWorld {
|
|
|
|
|
public:
|
2013-01-17 10:17:07 +00:00
|
|
|
explicit TestWorld() : BaseWorld(*(LocatedEntity*)0) {
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
virtual bool idle() { return false; }
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual LocatedEntity * addEntity(LocatedEntity * ent) {
|
2010-07-31 01:20:53 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual LocatedEntity * addNewEntity(const std::string &,
|
2010-07-31 01:20:53 +01:00
|
|
|
const Atlas::Objects::Entity::RootEntity &) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-11-15 22:55:17 +01:00
|
|
|
void delEntity(LocatedEntity * obj) {}
|
2010-07-31 01:20:53 +01:00
|
|
|
int createSpawnPoint(const Atlas::Message::MapType & data,
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity *) { return 0; }
|
2013-11-24 15:01:38 +01:00
|
|
|
int removeSpawnPoint(LocatedEntity *) {return 0; }
|
2010-07-31 01:20:53 +01:00
|
|
|
int getSpawnList(Atlas::Message::ListType & data) { return 0; }
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity * spawnNewEntity(const std::string & name,
|
|
|
|
|
const std::string & type,
|
|
|
|
|
const Atlas::Objects::Entity::RootEntity & desc) {
|
2010-07-31 01:20:53 +01:00
|
|
|
return addNewEntity(type, desc);
|
|
|
|
|
}
|
2013-11-16 21:05:45 +01:00
|
|
|
virtual int moveToSpawn(const std::string & name,
|
|
|
|
|
Location& location){return 0;}
|
2011-12-02 23:42:24 +00:00
|
|
|
virtual Task * newTask(const std::string &, LocatedEntity &) { return 0; }
|
2010-07-31 01:20:53 +01:00
|
|
|
virtual Task * activateTask(const std::string &, const std::string &,
|
2011-12-06 10:07:25 +00:00
|
|
|
LocatedEntity *, LocatedEntity &) { return 0; }
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual ArithmeticScript * newArithmetic(const std::string &,
|
|
|
|
|
LocatedEntity *) {
|
2010-07-31 01:20:53 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual void message(const Operation & op, LocatedEntity & ent) {
|
2010-07-31 01:20:53 +01:00
|
|
|
stub_baseworld_receieved_op = op->getClassNo();
|
2018-04-25 20:09:14 +02:00
|
|
|
}
|
|
|
|
|
virtual void messageToClients(const Atlas::Objects::Operation::RootOperation &) {
|
|
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
2013-01-17 10:17:07 +00:00
|
|
|
virtual LocatedEntity * findByName(const std::string & name) { return 0; }
|
|
|
|
|
virtual LocatedEntity * findByType(const std::string & type) { return 0; }
|
|
|
|
|
virtual void addPerceptive(LocatedEntity *) { }
|
2010-07-31 01:20:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
TestWorld world;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
ExternalMind em(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
em.test_deleteEntity("3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge with empty contains
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
e.m_contains = new LocatedEntitySet;
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
em.test_purgeEntity(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge with populated contains
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
e.m_contains = new LocatedEntitySet;
|
|
|
|
|
e.m_contains->insert(new Entity("3", 3));
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
em.test_purgeEntity(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to nothing
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
ExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(0);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
ExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something, then disconnect
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
ExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
|
|
|
|
em.linkUp(0);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something, then check connection ID
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
ExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
const std::string & id = em.connectionId();
|
|
|
|
|
assert(id == "4");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a random operation
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
em.test_setLossTime(BaseWorld::instance().getTime());
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::RootOperation(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Delete operation
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
em.test_setLossTime(BaseWorld::instance().getTime());
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Delete(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Delete operation to an ephemeral entity
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
2018-04-25 12:21:44 +02:00
|
|
|
e.addFlags(entity_ephem);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
em.test_setLossTime(BaseWorld::instance().getTime());
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Delete(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a non Delete operation to an ephemeral entity
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
2018-04-25 12:21:44 +02:00
|
|
|
e.addFlags(entity_ephem);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
em.test_setLossTime(BaseWorld::instance().getTime());
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::RootOperation(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == Atlas::Objects::Operation::DELETE_NO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a random operation to a connected mind
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::RootOperation(), res);
|
2012-08-02 15:29:49 +01:00
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::ROOT_OPERATION_NO);
|
|
|
|
|
assert(stub_link_send_count == 1);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Sight operation to a connected mind
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Sight(), res);
|
2012-08-02 15:29:49 +01:00
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO);
|
|
|
|
|
assert(stub_link_send_count == 1);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Sight(Set) of hungry operation to a connected mind
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
// A sight(set) of a starving entity
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
arg->setAttr("status", 0.05);
|
|
|
|
|
arg->setId(e.getId());
|
|
|
|
|
Atlas::Objects::Operation::Set set;
|
|
|
|
|
set->setArgs1(arg);
|
|
|
|
|
Atlas::Objects::Operation::Sight op;
|
|
|
|
|
op->setArgs1(set);
|
|
|
|
|
|
|
|
|
|
// It should trigger an extra Sight(Imaginary)
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(op, res);
|
2012-08-02 15:29:49 +01:00
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO);
|
|
|
|
|
assert(stub_link_send_count > 1);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Sight(Set) of starving operation to a connected mind
|
|
|
|
|
{
|
|
|
|
|
Entity e("2", 2);
|
|
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"addr", "4", 4));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
// A sight(set) of a starving entity
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
arg->setAttr("status", 0.005);
|
|
|
|
|
arg->setId(e.getId());
|
|
|
|
|
Atlas::Objects::Operation::Set set;
|
|
|
|
|
set->setArgs1(arg);
|
|
|
|
|
Atlas::Objects::Operation::Sight op;
|
|
|
|
|
op->setArgs1(set);
|
|
|
|
|
|
|
|
|
|
// It should trigger an extra Sight(Imaginary)
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(op, res);
|
2012-08-02 15:29:49 +01:00
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO);
|
|
|
|
|
assert(stub_link_send_count > 1);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "rulesets/Script.h"
|
|
|
|
|
|
2012-11-13 23:33:23 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "stubs/server/stubConnection.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Entity_destroy
|
2010-07-31 01:20:53 +01:00
|
|
|
void Entity::destroy()
|
|
|
|
|
{
|
|
|
|
|
destroyed.emit();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Entity_sendWorld
|
2013-01-17 10:17:07 +00:00
|
|
|
void Entity::sendWorld(const Operation & op)
|
|
|
|
|
{
|
|
|
|
|
BaseWorld::instance().message(op, *this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#include "stubs/rulesets/stubEntity.h"
|
2017-07-01 19:36:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "stubs/rulesets/stubLocatedEntity.h"
|
|
|
|
|
#include "stubs/rulesets/stubScript.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "stubs/modules/stubLocation.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Link_send
|
2012-08-01 21:13:14 +01:00
|
|
|
void Link::send(const Operation & op) const
|
|
|
|
|
{
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = op->getClassNo();
|
|
|
|
|
++stub_link_send_count;
|
2012-08-01 21:13:14 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
|
|
|
|
|
#include "stubs/common/stubLink.h"
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "stubs/common/stubRouter.h"
|
|
|
|
|
#include "stubs/common/stubBaseWorld.h"
|
2014-02-03 12:19:42 +01:00
|
|
|
|
2012-11-13 23:33:23 +00:00
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|