mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
* aiclient/ClientAccount.cpp, aiclient/ClientAccount.h, aiclient/ClientConnection.cpp, aiclient/ClientConnection.h, aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp, client/BaseClient.h, client/CharacterClient.cpp, client/CharacterClient.h, client/ClientConnection.cpp, client/ClientConnection.h, client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp, client/define_world.cpp, client/define_world.h, common/Add.h, common/Affect.h, common/AtlasFileLoader.cpp, common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp, common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h, common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h, common/Eat.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/Generic.h, common/Load.h, common/Monitor.h, common/Mow.h, common/Nourish.h, common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp, common/Property.h, common/Property_impl.h, common/Save.h, common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h, common/Use.h, common/Wield.h, common/accountbase.cpp, common/accountbase.h, common/const.cpp, common/const.h, common/custom.cpp, common/debug.h, common/globals.cpp, common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/log.cpp, common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h, common/operations.cpp, common/operations.h, common/random.h, common/refno.h, common/serialno.cpp, common/serialno.h, common/system.cpp, common/system.h, common/terrain_utils.cpp, common/terrain_utils.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/DateTime.cpp, modules/DateTime.h, modules/Location.cpp, modules/Location.h, modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp, physics/BBox.h, physics/Collision.cpp, physics/Collision.h, physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp, physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h, rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp, rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h, rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h, rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h, rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp, rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h, rulesets/Py_Location.cpp, rulesets/Py_Location.h, rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp, rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h, rulesets/Py_Property.cpp, rulesets/Py_Property.h, rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h, rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h, rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h, rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp, rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h, rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h, rulesets/PythonArithmeticScript.cpp, rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.cpp, rulesets/PythonScript.h, rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp, rulesets/PythonWrapper.h, rulesets/Python_API.cpp, rulesets/Python_API.h, rulesets/Python_Script_Utils.h, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h, rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h, rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp, rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h, rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp, rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h, rulesets/attributes.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp, server/ArithmeticFactory.h, server/CommClient.cpp, server/CommClient.h, server/CommIdleSocket.cpp, server/CommIdleSocket.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMDNSPublisher.cpp, server/CommMDNSPublisher.h, server/CommMaster.cpp, server/CommMaster.h, server/CommMetaClient.cpp, server/CommMetaClient.h, server/CommPSQLSocket.cpp, server/CommPSQLSocket.h, server/CommPeer.cpp, server/CommPeer.h, server/CommPeerListener.cpp, server/CommPeerListener.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSlaveClient.cpp, server/CommSlaveClient.h, server/CommSlaveListener.cpp, server/CommSlaveListener.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, server/Connection.cpp, server/Connection.h, server/Connection_methods.h, server/EntityFactory.cpp, server/EntityFactory.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h, server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h, server/Persistance.cpp, server/Persistance.h, server/PersistantThingFactory.cpp, server/PersistantThingFactory.h, server/PersistantThingFactory_impl.h, server/Persistor.cpp, server/Persistor.h, server/Persistor_impl.h, server/Player.cpp, server/Player.h, server/Restoration.cpp, server/Restoration.h, server/Restorer.cpp, server/Restorer.h, server/Restorer_impl.h, server/ScriptFactory.cpp, server/ScriptFactory.h, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/SlaveClientConnection.cpp, server/SlaveClientConnection.h, server/TaskFactory.cpp, server/TaskFactory.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, server/server.cpp, server/server.h, server/slave.cpp, tests/Areatest.cpp, tests/BaseEntitytest.cpp, tests/Charactertest.cpp, tests/Containertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/EntityFactorytest.cpp, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp, tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h, tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp, tests/distancetest.cpp, tests/emergencetest.cpp, tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp, tests/systemtest.cpp, tests/transformtest.cpp, tests/type_utilstest.cpp, tests/utilitytest.cpp, tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp, tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp, tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp, tools/cywatchdog.cpp: Replace the copyright and license statements with new versions that include disclaimer of warranty, and permit distribution under later versions of the GPL.
285 lines
9.1 KiB
C++
285 lines
9.1 KiB
C++
// Cyphesis Online RPG Server and AI Engine
|
|
// Copyright (C) 2000-2004 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
|
|
|
|
#include "inheritance.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
#include <Atlas/Objects/Entity.h>
|
|
|
|
using Atlas::Message::Element;
|
|
using Atlas::Message::ListType;
|
|
|
|
using Atlas::Objects::Root;
|
|
|
|
using Atlas::Objects::Operation::Login;
|
|
using Atlas::Objects::Operation::Logout;
|
|
using Atlas::Objects::Operation::Action;
|
|
using Atlas::Objects::Operation::Affect;
|
|
using Atlas::Objects::Operation::Combine;
|
|
using Atlas::Objects::Operation::Create;
|
|
using Atlas::Objects::Operation::Delete;
|
|
using Atlas::Objects::Operation::Divide;
|
|
using Atlas::Objects::Operation::Imaginary;
|
|
using Atlas::Objects::Operation::Info;
|
|
using Atlas::Objects::Operation::Move;
|
|
using Atlas::Objects::Operation::Set;
|
|
using Atlas::Objects::Operation::Get;
|
|
using Atlas::Objects::Operation::Sight;
|
|
using Atlas::Objects::Operation::Sound;
|
|
using Atlas::Objects::Operation::Touch;
|
|
using Atlas::Objects::Operation::Talk;
|
|
using Atlas::Objects::Operation::Use;
|
|
using Atlas::Objects::Operation::Wield;
|
|
using Atlas::Objects::Operation::Look;
|
|
using Atlas::Objects::Operation::Appearance;
|
|
using Atlas::Objects::Operation::Disappearance;
|
|
using Atlas::Objects::Operation::Error;
|
|
using Atlas::Objects::Operation::Use;
|
|
using Atlas::Objects::Operation::Wield;
|
|
|
|
Inheritance * Inheritance::m_instance = NULL;
|
|
|
|
Root atlasOpDefinition(const std::string & name, const std::string & parent)
|
|
{
|
|
Atlas::Objects::Entity::Anonymous r;
|
|
|
|
r->setParents(std::list<std::string>(1, parent));
|
|
r->setObjtype("op_definition");
|
|
r->setId(name);
|
|
|
|
return r;
|
|
}
|
|
|
|
Root atlasClass(const std::string & name, const std::string & parent)
|
|
{
|
|
Atlas::Objects::Entity::Anonymous r;
|
|
|
|
r->setParents(std::list<std::string>(1, parent));
|
|
r->setObjtype("class");
|
|
r->setId(name);
|
|
|
|
return r;
|
|
}
|
|
|
|
Inheritance::Inheritance() : noClass(0)
|
|
{
|
|
Atlas::Objects::Entity::Anonymous root;
|
|
|
|
root->setParents(std::list<std::string>(0));
|
|
root->setObjtype("meta");
|
|
root->setId("root");
|
|
|
|
atlasObjects["root"] = root;
|
|
}
|
|
|
|
void Inheritance::flush()
|
|
{
|
|
atlasObjects.clear();
|
|
}
|
|
|
|
Inheritance & Inheritance::instance()
|
|
{
|
|
if (m_instance == NULL) {
|
|
m_instance = new Inheritance();
|
|
installStandardObjects();
|
|
installCustomOperations();
|
|
installCustomEntities();
|
|
}
|
|
return *m_instance;
|
|
}
|
|
|
|
void Inheritance::clear()
|
|
{
|
|
if (m_instance != NULL) {
|
|
m_instance->flush();
|
|
delete m_instance;
|
|
}
|
|
}
|
|
|
|
OpNo Inheritance::opEnumerate(const std::string & parent) const
|
|
{
|
|
OpNoDict::const_iterator I = opLookup.find(parent);
|
|
if (I != opLookup.end()) {
|
|
return I->second;
|
|
} else {
|
|
return OP_INVALID;
|
|
}
|
|
}
|
|
|
|
OpNo Inheritance::opEnumerate(const Operation & op) const
|
|
{
|
|
return op->getClassNo();
|
|
}
|
|
|
|
const Atlas::Objects::Root & Inheritance::getClass(const std::string & parent)
|
|
{
|
|
RootDict::const_iterator I = atlasObjects.find(parent);
|
|
if (I == atlasObjects.end()) {
|
|
return noClass;
|
|
}
|
|
return I->second;
|
|
}
|
|
|
|
bool Inheritance::hasClass(const std::string & parent)
|
|
{
|
|
RootDict::const_iterator I = atlasObjects.find(parent);
|
|
if (I == atlasObjects.end()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int Inheritance::addChild(const Atlas::Objects::Root & obj)
|
|
{
|
|
const std::string & child = obj->getId();
|
|
const std::string & parent = obj->getParents().front();
|
|
if (atlasObjects.find(child) != atlasObjects.end()) {
|
|
std::string msg = std::string("Installing type ") + child
|
|
+ "(" + parent + ") which was already installed";
|
|
log(ERROR, msg.c_str());
|
|
return -1;
|
|
}
|
|
RootDict::const_iterator I = atlasObjects.find(parent);
|
|
if (I == atlasObjects.end()) {
|
|
std::string msg = std::string("Installing type ") + child
|
|
+ " which has unknown parent \"" + parent + "\"";
|
|
log(ERROR, msg.c_str());
|
|
return -1;
|
|
}
|
|
Element children(ListType(1, child));
|
|
if (I->second->copyAttr("children", children) == 0) {
|
|
assert(children.isList());
|
|
children.asList().push_back(child);
|
|
}
|
|
I->second->setAttr("children", children);
|
|
atlasObjects[child] = obj;
|
|
return 0;
|
|
}
|
|
|
|
bool Inheritance::isTypeOf(const std::string & instance,
|
|
const std::string & type) const
|
|
{
|
|
if (instance == type) {
|
|
return true;
|
|
}
|
|
RootDict::const_iterator I = atlasObjects.find(instance);
|
|
RootDict::const_iterator Iend = atlasObjects.end();
|
|
for (; I != Iend;) {
|
|
const std::list<std::string> & parents = I->second->getParents();
|
|
if (parents.empty()) {
|
|
break;
|
|
}
|
|
const std::string & parent = I->second->getParents().front();
|
|
if (parent == type) {
|
|
return true;
|
|
}
|
|
I = atlasObjects.find(parent);
|
|
}
|
|
return false;
|
|
// Walk up the tree.
|
|
}
|
|
|
|
using Atlas::Objects::Operation::RootOperation;
|
|
using Atlas::Objects::Operation::Perception;
|
|
using Atlas::Objects::Operation::Communicate;
|
|
using Atlas::Objects::Operation::Perceive;
|
|
using Atlas::Objects::Operation::Smell;
|
|
using Atlas::Objects::Operation::Feel;
|
|
using Atlas::Objects::Operation::Listen;
|
|
using Atlas::Objects::Operation::Sniff;
|
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
using Atlas::Objects::Entity::AdminEntity;
|
|
using Atlas::Objects::Entity::Game;
|
|
using Atlas::Objects::Entity::GameEntity;
|
|
|
|
void installStandardObjects()
|
|
{
|
|
Inheritance & i = Inheritance::instance();
|
|
|
|
i.addChild(atlasOpDefinition("root_operation", "root"));
|
|
i.addChild(atlasOpDefinition("action", "root_operation"));
|
|
i.opInstall("action", OP_ACTION);
|
|
i.addChild(atlasOpDefinition("create", "action"));
|
|
i.opInstall("create", OP_CREATE);
|
|
i.addChild(atlasOpDefinition("delete", "action"));
|
|
i.opInstall("delete", OP_DELETE);
|
|
i.addChild(atlasOpDefinition("info", "root_operation"));
|
|
i.opInstall("info", OP_INFO);
|
|
i.addChild(atlasOpDefinition("set", "action"));
|
|
i.opInstall("set", OP_SET);
|
|
i.addChild(atlasOpDefinition("get", "action"));
|
|
i.opInstall("get", OP_GET);
|
|
i.addChild(atlasOpDefinition("perception", "info"));
|
|
i.addChild(atlasOpDefinition("error", "info"));
|
|
i.opInstall("error", OP_ERROR);
|
|
i.addChild(atlasOpDefinition("combine", "create"));
|
|
i.opInstall("combine", OP_COMBINE);
|
|
i.addChild(atlasOpDefinition("divide", "create"));
|
|
i.opInstall("divide", OP_DIVIDE);
|
|
i.addChild(atlasOpDefinition("communicate", "create"));
|
|
i.addChild(atlasOpDefinition("move", "set"));
|
|
i.opInstall("move", OP_MOVE);
|
|
i.addChild(atlasOpDefinition("affect", "set"));
|
|
i.opInstall("affect", OP_MOVE);
|
|
i.addChild(atlasOpDefinition("perceive", "get"));
|
|
i.addChild(atlasOpDefinition("login", "get"));
|
|
i.opInstall("login", OP_LOGIN);
|
|
i.addChild(atlasOpDefinition("logout", "login"));
|
|
i.opInstall("logout", OP_LOGOUT);
|
|
i.addChild(atlasOpDefinition("sight", "perception"));
|
|
i.opInstall("sight", OP_SIGHT);
|
|
i.addChild(atlasOpDefinition("sound", "perception"));
|
|
i.opInstall("sound", OP_SOUND);
|
|
i.addChild(atlasOpDefinition("smell", "perception"));
|
|
i.addChild(atlasOpDefinition("feel", "perception"));
|
|
i.addChild(atlasOpDefinition("imaginary", "action"));
|
|
i.opInstall("imaginary", OP_IMAGINARY);
|
|
i.addChild(atlasOpDefinition("talk", "communicate"));
|
|
i.opInstall("talk", OP_TALK);
|
|
i.addChild(atlasOpDefinition("look", "perceive"));
|
|
i.opInstall("look", OP_LOOK);
|
|
i.addChild(atlasOpDefinition("listen", "perceive"));
|
|
i.addChild(atlasOpDefinition("sniff", "perceive"));
|
|
i.addChild(atlasOpDefinition("touch", "perceive"));
|
|
i.opInstall("touch", OP_TOUCH);
|
|
i.addChild(atlasOpDefinition("appearance", "sight"));
|
|
i.opInstall("appearance", OP_APPEARANCE);
|
|
i.addChild(atlasOpDefinition("disappearance", "sight"));
|
|
i.opInstall("disappearance", OP_DISAPPEARANCE);
|
|
i.addChild(atlasOpDefinition("use", "action"));
|
|
i.opInstall("use", OP_USE);
|
|
i.addChild(atlasOpDefinition("wield", "set"));
|
|
i.opInstall("wield", OP_WIELD);
|
|
|
|
|
|
|
|
i.addChild(atlasClass("root_entity", "root"));
|
|
i.addChild(atlasClass("admin_entity", "root_entity"));
|
|
i.addChild(atlasClass("account", "admin_entity"));
|
|
i.addChild(atlasClass("player", "account"));
|
|
i.addChild(atlasClass("admin", "account"));
|
|
i.addChild(atlasClass("game", "admin_entity"));
|
|
i.addChild(atlasClass("game_entity", "root_entity"));
|
|
|
|
// And from here on we need to define the hierarchy as found in the C++
|
|
// base classes. Script classes defined in rulsets need to be added
|
|
// at runtime.
|
|
}
|