2007-12-02 19:20:55 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2000-2007 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 RULESETS_LOCATED_ENTITY_H
|
|
|
|
|
#define RULESETS_LOCATED_ENTITY_H
|
|
|
|
|
|
|
|
|
|
#include "modules/Location.h"
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "common/Property.h"
|
2009-03-22 15:44:54 +00:00
|
|
|
#include "common/Router.h"
|
2013-06-02 00:06:52 +02:00
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/compose.hpp"
|
2007-12-02 19:20:55 +00:00
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
#include <sigc++/signal.h>
|
|
|
|
|
|
2008-01-13 Al Riddoch <alriddoch@googlemail.com>
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/BaseWorld.h, common/OperationRouter.h, common/TypeNode.h,
common/inheritance.cpp, common/inheritance.h, common/types.h,
rulesets/ActivePropertyFactory.h, rulesets/AtlasProperties.h,
rulesets/EntityPropertyFactory.h, rulesets/LocatedEntity.h,
rulesets/MemMap.h, rulesets/Motion.h, rulesets/Movement.h,
rulesets/Pedestrian.h, rulesets/PythonThingScript.cpp,
rulesets/Statistics.h, rulesets/Task.h, server/Account.h,
server/Connection.h, server/Player.h, server/ServerRouting.h,
server/WorldRouter.h, tests/OperationExerciser.h, tools/cycmd.cpp:
A major clean up and re-work in internal headers.
2008-01-13 01:32:54 +00:00
|
|
|
#include <set>
|
|
|
|
|
|
2011-02-02 23:29:21 -08:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
class Domain;
|
2008-01-13 Al Riddoch <alriddoch@googlemail.com>
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/BaseWorld.h, common/OperationRouter.h, common/TypeNode.h,
common/inheritance.cpp, common/inheritance.h, common/types.h,
rulesets/ActivePropertyFactory.h, rulesets/AtlasProperties.h,
rulesets/EntityPropertyFactory.h, rulesets/LocatedEntity.h,
rulesets/MemMap.h, rulesets/Motion.h, rulesets/Movement.h,
rulesets/Pedestrian.h, rulesets/PythonThingScript.cpp,
rulesets/Statistics.h, rulesets/Task.h, server/Account.h,
server/Connection.h, server/Player.h, server/ServerRouting.h,
server/WorldRouter.h, tests/OperationExerciser.h, tools/cycmd.cpp:
A major clean up and re-work in internal headers.
2008-01-13 01:32:54 +00:00
|
|
|
class LocatedEntity;
|
|
|
|
|
class PropertyBase;
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
class Script;
|
|
|
|
|
class TypeNode;
|
2007-12-07 Al Riddoch <alriddoch@zepler.org>
* common/BaseWorld.h, common/PropertyFactory.h, rulesets/Character.h,
rulesets/LocatedEntity.h, rulesets/MemMap.h, rulesets/Py_Location.h,
rulesets/Py_Thing.h, rulesets/Python_Script_Utils.h,
rulesets/Statistics.h, server/Connection.h, server/EntityFactory.h,
server/Persistance.h, server/PersistantThingFactory.h,
server/Persistor.h, server/Restoration.h, server/TaskFactory.h:
Sort forward declarations alphabetically, because alphabetical
is good.
2007-12-07 01:19:16 +00:00
|
|
|
|
2008-09-29 02:49:45 +00:00
|
|
|
template <typename T>
|
|
|
|
|
class Property;
|
|
|
|
|
|
2008-01-13 Al Riddoch <alriddoch@googlemail.com>
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/BaseWorld.h, common/OperationRouter.h, common/TypeNode.h,
common/inheritance.cpp, common/inheritance.h, common/types.h,
rulesets/ActivePropertyFactory.h, rulesets/AtlasProperties.h,
rulesets/EntityPropertyFactory.h, rulesets/LocatedEntity.h,
rulesets/MemMap.h, rulesets/Motion.h, rulesets/Movement.h,
rulesets/Pedestrian.h, rulesets/PythonThingScript.cpp,
rulesets/Statistics.h, rulesets/Task.h, server/Account.h,
server/Connection.h, server/Player.h, server/ServerRouting.h,
server/WorldRouter.h, tests/OperationExerciser.h, tools/cycmd.cpp:
A major clean up and re-work in internal headers.
2008-01-13 01:32:54 +00:00
|
|
|
typedef std::set<LocatedEntity *> LocatedEntitySet;
|
|
|
|
|
typedef std::map<std::string, PropertyBase *> PropertyDict;
|
|
|
|
|
|
2013-01-14 09:59:54 +00:00
|
|
|
/// \brief Flag indicating entity has been written to permanent store
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_clean = 1 << 0;
|
|
|
|
|
/// \brief Flag indicating entity POS has been written to permanent store
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_pos_clean = 1 << 1;
|
|
|
|
|
/// \brief Flag indicating entity ORIENT has been written to permanent store
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_orient_clean = 1 << 2;
|
|
|
|
|
|
|
|
|
|
static const unsigned int entity_clean_mask = entity_clean |
|
|
|
|
|
entity_pos_clean |
|
|
|
|
|
entity_orient_clean;
|
|
|
|
|
|
|
|
|
|
/// \brief Flag indicating entity is perceptive
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_perceptive = 1 << 3;
|
|
|
|
|
/// \brief Flag indicating entity has been destroyed
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_destroyed = 1 << 4;
|
|
|
|
|
/// \brief Flag indicating entity has been queued for storage update
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_queued = 1 << 5;
|
|
|
|
|
/// \brief Flag indicaiting entity is ephemeral
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_ephem = 1 << 6;
|
|
|
|
|
/// \brief Flag indicating entity is visible
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
/// Currently only used on MemEntity
|
|
|
|
|
static const unsigned int entity_visible = 1 << 7;
|
2013-01-22 23:29:23 +00:00
|
|
|
/// \brief Flag indicating entity is asleep
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
/// Currently only used on BaseMind
|
|
|
|
|
static const unsigned int entity_asleep = 1 << 8;
|
2014-09-13 10:34:30 +02:00
|
|
|
/// \brief Flag indicating entity contains a Domain, used for movement and sights
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_domain = 1 << 9;
|
2013-01-14 09:59:54 +00:00
|
|
|
|
2015-05-26 22:27:39 +02:00
|
|
|
/// \brief Flag indicating entity has thoughts that needs to be persisted.
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_dirty_thoughts = 1 << 10;
|
|
|
|
|
|
2016-01-19 15:38:03 +01:00
|
|
|
/// \brief Flag indicating entity has a location which has been changed since last sent to clients,
|
|
|
|
|
/// and new location data should be sent on the next Update.
|
|
|
|
|
/// \ingroup EntityFlags
|
|
|
|
|
static const unsigned int entity_dirty_location = 1 << 11;
|
|
|
|
|
|
2007-12-03 23:55:11 +00:00
|
|
|
/// \brief This is the base class from which in-game and in-memory objects
|
|
|
|
|
/// inherit.
|
|
|
|
|
///
|
|
|
|
|
/// This class should not normally be instantiated directly.
|
|
|
|
|
/// This class provides hard-coded attributes that are common to all
|
|
|
|
|
/// in-game objects, and objects in the memory on an NPC.
|
|
|
|
|
/// It provides a physical location for the entity, and a contains list
|
|
|
|
|
/// which lists other entities which specify their location with reference to
|
|
|
|
|
/// this one. It also provides the script interface for handling operations
|
|
|
|
|
/// in scripts rather than in the C++ code.
|
2008-12-10 Al Riddoch <alriddoch@googlemail.com>
* common/Identified.cpp, common/Identified.h, rulesets/Character.h,
rulesets/LocatedEntity.h, server/Account.h, server/Admin.cpp,
server/CommClient.cpp, server/CommClient.h, server/Connection.cpp,
server/Connection.h, server/ExternalMind.h,
server/ExternalProperty.cpp, server/ExternalProperty.h,
server/Lobby.h, server/Master.h, server/Peer.h,
server/ServerRouting.h, server/SlaveClientConnection.h:
Rename IdentifiedRouter to Router as it's the base class
for pretty much all routers.
2008-12-10 01:16:37 +00:00
|
|
|
class LocatedEntity : public Router {
|
2007-12-02 19:20:55 +00:00
|
|
|
private:
|
2015-07-13 22:14:51 +02:00
|
|
|
static std::set<std::string> s_immutable;
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
static const std::set<std::string> & immutables();
|
|
|
|
|
|
2007-12-02 19:20:55 +00:00
|
|
|
/// Count of references held by other objects to this entity
|
|
|
|
|
int m_refCount;
|
|
|
|
|
protected:
|
2007-12-24 00:32:11 +00:00
|
|
|
/// Map of properties
|
|
|
|
|
PropertyDict m_properties;
|
2007-12-02 19:20:55 +00:00
|
|
|
|
|
|
|
|
/// Sequence number
|
|
|
|
|
int m_seq;
|
|
|
|
|
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
/// Script associated with this entity
|
|
|
|
|
Script * m_script;
|
|
|
|
|
/// Class of which this is an instance
|
|
|
|
|
const TypeNode * m_type;
|
2013-01-14 09:59:54 +00:00
|
|
|
/// Flags indicating changes to attributes
|
|
|
|
|
unsigned int m_flags;
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
|
2007-12-02 19:20:55 +00:00
|
|
|
public:
|
|
|
|
|
/// Full details of location
|
|
|
|
|
Location m_location;
|
|
|
|
|
/// List of entities which use this as ref
|
2007-12-31 Al Riddoch <alriddoch@googlemail.com>
* rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/LocatedEntity.cpp, rulesets/LocatedEntity.h,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Thing.cpp, rulesets/World.cpp,
server/WorldRouter.cpp: Change LocatedEntity::m_contains into
a pointer so that the majority of entities that can not contain
anything don't waste the storage.
2007-12-31 17:39:25 +00:00
|
|
|
LocatedEntitySet * m_contains;
|
2007-12-02 19:20:55 +00:00
|
|
|
|
|
|
|
|
explicit LocatedEntity(const std::string & id, long intId);
|
|
|
|
|
virtual ~LocatedEntity();
|
|
|
|
|
|
|
|
|
|
/// \brief Increment the reference count on this entity
|
|
|
|
|
void incRef() {
|
|
|
|
|
++m_refCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \brief Decrement the reference count on this entity
|
|
|
|
|
void decRef() {
|
2011-10-03 13:33:50 +01:00
|
|
|
if (--m_refCount < 0) {
|
|
|
|
|
assert(m_refCount == -1);
|
2007-12-02 19:20:55 +00:00
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \brief Check the reference count on this entity
|
|
|
|
|
int checkRef() const {
|
|
|
|
|
return m_refCount;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-14 09:59:54 +00:00
|
|
|
/// \brief Check if this entity is flagged as perceptive
|
2013-01-22 19:49:34 +00:00
|
|
|
bool isPerceptive() const { return m_flags & entity_perceptive; }
|
2013-01-14 09:59:54 +00:00
|
|
|
|
|
|
|
|
/// \brief Check if this entity is flagged as destroyed
|
|
|
|
|
bool isDestroyed() const { return m_flags & entity_destroyed; }
|
|
|
|
|
|
|
|
|
|
bool isVisible() const { return m_flags & entity_visible; }
|
|
|
|
|
|
|
|
|
|
/// \brief Accessor for flags
|
|
|
|
|
const int getFlags() const { return m_flags; }
|
|
|
|
|
|
|
|
|
|
void setFlags(unsigned int flags) { m_flags |= flags; }
|
|
|
|
|
|
|
|
|
|
void resetFlags(unsigned int flags) { m_flags &= ~flags; }
|
|
|
|
|
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
/// \brief Accessor for pointer to script object
|
|
|
|
|
Script * script() const {
|
|
|
|
|
return m_script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \brief Accessor for sequence number
|
|
|
|
|
const int getSeq() const { return m_seq; }
|
|
|
|
|
/// \brief Accessor for entity type property
|
|
|
|
|
const TypeNode * getType() const { return m_type; }
|
2008-08-23 17:53:43 +00:00
|
|
|
/// \brief Accessor for properies
|
|
|
|
|
const PropertyDict & getProperties() const { return m_properties; }
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
|
|
|
|
|
/// \brief Set the value of the entity type property
|
2015-04-08 18:36:20 +02:00
|
|
|
virtual void setType(const TypeNode * t);
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
|
2007-12-02 19:20:55 +00:00
|
|
|
virtual bool hasAttr(const std::string & name) const;
|
2011-09-29 17:36:26 +01:00
|
|
|
virtual int getAttr(const std::string & name,
|
|
|
|
|
Atlas::Message::Element &) const;
|
|
|
|
|
virtual int getAttrType(const std::string & name,
|
|
|
|
|
Atlas::Message::Element &,
|
|
|
|
|
int type) const;
|
2011-02-27 23:56:11 +00:00
|
|
|
virtual PropertyBase* setAttr(const std::string & name,
|
|
|
|
|
const Atlas::Message::Element &);
|
2008-10-01 18:20:57 +00:00
|
|
|
virtual const PropertyBase * getProperty(const std::string & name) const;
|
2016-01-17 16:23:11 +01:00
|
|
|
// FIXME These should be de-virtualised and, and implementations moved
|
2013-01-17 10:17:07 +00:00
|
|
|
// from Entity to here.
|
|
|
|
|
virtual PropertyBase * modProperty(const std::string & name);
|
|
|
|
|
virtual PropertyBase * setProperty(const std::string & name, PropertyBase * prop);
|
|
|
|
|
|
|
|
|
|
virtual void installDelegate(int, const std::string &);
|
2014-08-25 22:42:00 +02:00
|
|
|
virtual void removeDelegate(int, const std::string &);
|
2007-12-02 19:20:55 +00:00
|
|
|
|
2013-06-15 22:53:14 +02:00
|
|
|
virtual void onContainered(const LocatedEntity* oldLocation);
|
2008-08-16 23:21:06 +00:00
|
|
|
virtual void onUpdated();
|
2008-01-07 00:06:18 +00:00
|
|
|
|
2013-01-24 22:52:05 +00:00
|
|
|
virtual void destroy() = 0;
|
2013-01-17 10:17:07 +00:00
|
|
|
|
|
|
|
|
virtual Domain * getMovementDomain();
|
2016-06-22 16:50:36 +02:00
|
|
|
virtual const Domain * getMovementDomain() const;
|
2013-01-17 10:17:07 +00:00
|
|
|
|
|
|
|
|
virtual void sendWorld(const Operation & op);
|
|
|
|
|
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
void setScript(Script * scrpt);
|
2008-01-05 Al Riddoch <alriddoch@googlemail.com>
* rulesets/LocatedEntity.cpp, rulesets/LocatedEntity.h:
Don't allocated storage for m_contains by default, only
on demand. Add a convenience method which checks, and
allocates the storage if required. Set up the ID property
on this base class rather then Entity.
* rulesets/Py_Thing.cpp: Remove special handling of ID attribute
as it is now handled by the property.
* rulesets/Character.cpp, rulesets/Entity.cpp, rulesets/MemMap.cpp,
rulesets/Motion.cpp, rulesets/Py_Mind.cpp, rulesets/Py_Thing.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp:
Make sure all parts of the code where contains is used have
the right checks, as it could be null.
2008-01-05 14:05:05 +00:00
|
|
|
void makeContainer();
|
2007-12-02 Al Riddoch <alriddoch@zepler.org>
* client/CreatorClient.cpp, client/CreatorClient.h,
client/Py_CreatorClient.cpp, common/BaseWorld.h, common/types.h,
modules/Location.cpp, modules/Location.h,
rulesets/AtlasProperties.cpp, rulesets/AtlasProperties.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/EntityProperties.cpp, rulesets/LocatedEntity.cpp,
rulesets/LocatedEntity.h, rulesets/MemEntity.cpp,
rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/Motion.cpp,
rulesets/Motion.h, rulesets/Py_Location.h, rulesets/Py_Mind.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Thing.h,
rulesets/PythonMindScript.h, rulesets/PythonScript.h,
rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h,
rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h,
rulesets/Thing.cpp, rulesets/World.cpp, server/WorldRouter.cpp,
server/WorldRouter.h: Refactor all the entity code so there is now
a new base class for entities in the world simulation, and in the
mind which only contains things which are trully common to both.
This moves a lot of functionality which should not have been
present in mind entities away, and makes that code safer and more
efficient.
* tests/TestWorld.h: Update the test world API to match the base
class.
2007-12-02 23:49:05 +00:00
|
|
|
void changeContainer(LocatedEntity *);
|
|
|
|
|
void merge(const Atlas::Message::MapType &);
|
2008-01-08 15:21:42 +00:00
|
|
|
|
2015-05-26 22:27:39 +02:00
|
|
|
/**
|
|
|
|
|
* Gets all registered thoughts.
|
|
|
|
|
* @return All registered thoughts.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::vector<Atlas::Objects::Root> getThoughts() const;
|
|
|
|
|
|
2014-09-18 22:41:23 +02:00
|
|
|
/// \brief Adds a child to this entity.
|
|
|
|
|
virtual void addChild(LocatedEntity& childEntity);
|
|
|
|
|
/// \brief Removes a child from this entity.
|
|
|
|
|
virtual void removeChild(LocatedEntity& childEntity);
|
|
|
|
|
|
2016-06-26 14:18:37 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Determines if this entity is visible to another entity.
|
|
|
|
|
*
|
|
|
|
|
* @param watcher The other entity observing this entity, for which we want to determine visibility.
|
|
|
|
|
* @return True if this entity is visible to another entity.
|
|
|
|
|
*/
|
|
|
|
|
bool isVisibleForOtherEntity(const LocatedEntity* watcher) const;
|
|
|
|
|
|
2008-01-12 18:08:03 +00:00
|
|
|
/// \brief Get a property that is required to of a given type.
|
2008-01-08 15:21:42 +00:00
|
|
|
template <class PropertyT>
|
2008-10-01 18:20:57 +00:00
|
|
|
const PropertyT * getPropertyClass(const std::string & name) const
|
2008-01-08 15:21:42 +00:00
|
|
|
{
|
2008-10-01 18:20:57 +00:00
|
|
|
const PropertyBase * p = getProperty(name);
|
2008-01-08 15:21:42 +00:00
|
|
|
if (p != 0) {
|
2008-10-01 18:20:57 +00:00
|
|
|
return dynamic_cast<const PropertyT *>(p);
|
2008-01-08 15:21:42 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-17 16:23:11 +01:00
|
|
|
/// \brief Get a property that is required to of a given type.
|
|
|
|
|
///
|
|
|
|
|
/// The specified class must present the "property_name" trait.
|
|
|
|
|
template <class PropertyT>
|
2016-01-18 15:37:05 +01:00
|
|
|
const PropertyT * getPropertyClassFixed() const
|
2016-01-17 16:23:11 +01:00
|
|
|
{
|
|
|
|
|
return this->getPropertyClass<PropertyT>(PropertyT::property_name);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-29 02:49:45 +00:00
|
|
|
/// \brief Get a property that is a generic property of a given type
|
|
|
|
|
template <typename T>
|
2008-10-01 18:20:57 +00:00
|
|
|
const Property<T> * getPropertyType(const std::string & name) const
|
2008-09-29 02:49:45 +00:00
|
|
|
{
|
2008-10-01 18:20:57 +00:00
|
|
|
const PropertyBase * p = getProperty(name);
|
2008-09-29 02:49:45 +00:00
|
|
|
if (p != 0) {
|
2008-10-01 18:20:57 +00:00
|
|
|
return dynamic_cast<const Property<T> *>(p);
|
2008-09-29 02:49:45 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-01-17 10:17:07 +00:00
|
|
|
|
|
|
|
|
/// \brief Get a property that is required to of a given type.
|
|
|
|
|
template <class PropertyT>
|
|
|
|
|
PropertyT * modPropertyClass(const std::string & name)
|
|
|
|
|
{
|
|
|
|
|
PropertyBase * p = modProperty(name);
|
|
|
|
|
if (p != 0) {
|
|
|
|
|
return dynamic_cast<PropertyT *>(p);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-17 16:23:11 +01:00
|
|
|
/// \brief Get a property that is required to of a given type.
|
|
|
|
|
///
|
|
|
|
|
/// The specified class must present the "property_name" trait.
|
|
|
|
|
template <class PropertyT>
|
2016-01-18 15:37:05 +01:00
|
|
|
PropertyT * modPropertyClassFixed()
|
2016-01-17 16:23:11 +01:00
|
|
|
{
|
|
|
|
|
return this->modPropertyClass<PropertyT>(PropertyT::property_name);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
/// \brief Get a modifiable property that is a generic property of a type
|
|
|
|
|
///
|
|
|
|
|
/// If the property is not set on the Entity instance, but has a class
|
|
|
|
|
/// default, the default is copied to the instance, and a pointer is
|
|
|
|
|
/// returned if it is a property of the right type.
|
|
|
|
|
template <typename T>
|
|
|
|
|
Property<T> * modPropertyType(const std::string & name)
|
|
|
|
|
{
|
|
|
|
|
PropertyBase * p = modProperty(name);
|
|
|
|
|
if (p != 0) {
|
|
|
|
|
return dynamic_cast<Property<T> *>(p);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \brief Require that a property of a given type is set.
|
|
|
|
|
///
|
|
|
|
|
/// If the property is not set on the Entity instance, but has a class
|
|
|
|
|
/// default, the default is copied to the instance, and a pointer is
|
|
|
|
|
/// returned if it is a property of the right type. If it does not
|
|
|
|
|
/// exist, or is not of the right type, a new property is created of
|
|
|
|
|
/// the right type, and installed on the Entity instance.
|
|
|
|
|
template <class PropertyT>
|
|
|
|
|
PropertyT * requirePropertyClass(const std::string & name,
|
|
|
|
|
const Atlas::Message::Element & def_val
|
|
|
|
|
= Atlas::Message::Element())
|
|
|
|
|
{
|
|
|
|
|
PropertyBase * p = modProperty(name);
|
|
|
|
|
PropertyT * sp = 0;
|
|
|
|
|
if (p != 0) {
|
|
|
|
|
sp = dynamic_cast<PropertyT *>(p);
|
2013-06-02 00:06:52 +02:00
|
|
|
//Assert that the stored property is of the correct type. If not,
|
|
|
|
|
//it needs to be installed into CorePropertyManager.
|
|
|
|
|
//We want to do this here, because allowing for properties to be
|
|
|
|
|
//installed of the wrong type brings instability to the system.
|
|
|
|
|
assert(sp);
|
2013-01-17 10:17:07 +00:00
|
|
|
}
|
|
|
|
|
if (sp == 0) {
|
|
|
|
|
// If it is not of the right type, delete it and a new
|
|
|
|
|
// one of the right type will be inserted.
|
|
|
|
|
m_properties[name] = sp = new PropertyT;
|
2013-02-13 00:45:36 +00:00
|
|
|
sp->install(this, name);
|
2013-01-17 10:17:07 +00:00
|
|
|
if (p != 0) {
|
2013-06-02 00:06:52 +02:00
|
|
|
log(WARNING, String::compose("Property %1 on entity with id %2 "
|
|
|
|
|
"reinstalled with new class."
|
|
|
|
|
"This might cause instability. Make sure that all "
|
|
|
|
|
"properties are properly installed in "
|
|
|
|
|
"CorePropertyManager.", name, getId()));
|
2013-01-17 10:17:07 +00:00
|
|
|
Atlas::Message::Element val;
|
|
|
|
|
if (p->get(val)) {
|
|
|
|
|
sp->set(val);
|
|
|
|
|
}
|
|
|
|
|
delete p;
|
|
|
|
|
} else if (!def_val.isNone()) {
|
|
|
|
|
sp->set(def_val);
|
|
|
|
|
}
|
|
|
|
|
sp->apply(this);
|
|
|
|
|
}
|
|
|
|
|
return sp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-17 16:23:11 +01:00
|
|
|
/// \brief Require that a property of a given type is set, relying on the "property_name" trait.
|
|
|
|
|
///
|
|
|
|
|
/// If the property is not set on the Entity instance, but has a class
|
|
|
|
|
/// default, the default is copied to the instance, and a pointer is
|
|
|
|
|
/// returned if it is a property of the right type. If it does not
|
|
|
|
|
/// exist, or is not of the right type, a new property is created of
|
|
|
|
|
/// the right type, and installed on the Entity instance.
|
|
|
|
|
///
|
|
|
|
|
/// The specified class must present the "property_name" trait.
|
|
|
|
|
template <class PropertyT>
|
2016-01-18 15:37:05 +01:00
|
|
|
PropertyT * requirePropertyClassFixed(const Atlas::Message::Element & def_val
|
2016-01-17 16:23:11 +01:00
|
|
|
= Atlas::Message::Element())
|
|
|
|
|
{
|
|
|
|
|
return this->requirePropertyClass<PropertyT>(PropertyT::property_name, def_val);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 11:20:32 +02:00
|
|
|
/**
|
|
|
|
|
* Generates a string describing this entity, used for debugging.
|
|
|
|
|
*
|
|
|
|
|
* @return A string describing the entity in more detail.
|
|
|
|
|
*/
|
|
|
|
|
std::string describeEntity() const;
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
/// Signal indicating that this entity has been changed
|
|
|
|
|
sigc::signal<void> updated;
|
|
|
|
|
|
2013-06-15 22:53:14 +02:00
|
|
|
/// Signal indicating that this entity has changed its LOC.
|
|
|
|
|
/// First parameter is the old location.
|
|
|
|
|
sigc::signal<void, const LocatedEntity*> containered;
|
2013-01-17 10:17:07 +00:00
|
|
|
|
|
|
|
|
/// \brief Signal emitted when this entity is removed from the server
|
|
|
|
|
///
|
|
|
|
|
/// Note that this is usually well before the object is actually deleted
|
|
|
|
|
/// and marks the conceptual destruction of the concept this entity
|
|
|
|
|
/// represents, not the destruction of this object.
|
|
|
|
|
sigc::signal<void> destroyed;
|
2013-01-19 00:51:05 +00:00
|
|
|
|
|
|
|
|
friend class LocatedEntitytest;
|
2007-12-02 19:20:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // RULESETS_LOCATED_ENTITY_H
|