cyphesis/server/WorldRouter.cpp

569 lines
19 KiB
C++
Raw Permalink Normal View History

2006-01-19 Al Riddoch <alriddoch@zepler.org> * 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.
2006-01-19 02:17:06 +00:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2000-2006 Alistair Riddoch
2006-01-19 Al Riddoch <alriddoch@zepler.org> * 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.
2006-01-19 02:17:06 +00:00
//
// 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 "WorldRouter.h"
#include "ArithmeticBuilder.h"
#include "EntityBuilder.h"
#include "SpawnEntity.h"
#include "rules/simulation/World.h"
#include "rules/Domain.h"
#include "rules/simulation/Task.h"
2002-05-18 Al Riddoch <alriddoch@zepler.org> * client/ObserverClient.cpp, server/Account.cpp, server/Connection.h, server/Routing.h: Formatting cleanup * client/Py_CreatorClient.cpp, rulesets/Area.cpp, rulesets/Area.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_Mind.cpp, rulesets/Py_Thing.cpp, rulesets/Stackable.cpp, rulesets/Stackable.h: Replace operator[] with get() method for querying attributes. Make this get() method const, and re-write the internals so that it more cleanly handles attributes. * common/BaseWorld.h: Re-write world.getObject() so that it no longer uses std::map::operator[], as the old method was inserting NULLs into the world dictionary when non-existant entities were queried. * rulesets/Character.cpp: Clean up outstanding issues when movement position is supplied, and is very close to being correct, and clarify comments about movement when neither destination nor source are provided. * rulesets/Character.cpp: Modify mind2body interface so that setting the TO of ops is done in the individual handlers, and copying the operation globally is avoided. * rulesets/MemMap_methods.h: Remove dodgy debug code. * rulesets/Pedestrian.cpp: Clarify movement fixme. * rulesets/Py_Operation.cpp: Clarify operation time handler fixme. * rulesets/Stackable.cpp: Clarify fixme's in combine and divide handlers. * server/CommServer.cpp: Remove redundant fixme. * server/Connection.cpp, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/server.cpp: Move inline ServerRouting::getObject into class header. * server/WorldRouter.cpp, server/WorldRouter.h: Clean up includes, and move updateTime into the main body of the file. Clean up code formatting when handling maps and dictionaries. Clarify error output and comments about NULL objects in the world dictionary.
2002-05-18 18:09:14 +00:00
#include "common/id.h"
#include "common/debug.h"
#include "common/const.h"
#include "common/random.h"
#include "common/TypeNode.h"
#include "common/Inheritance.h"
#include "common/Monitors.h"
2011-10-31 11:19:33 +01:00
#include "common/SystemTime.h"
#include "common/Variable.h"
2018-10-30 20:12:45 +01:00
#include "common/operations/Tick.h"
#include "server/Connection.h"
#include "ServerRouting.h"
#include "Account.h"
#include <Atlas/Objects/Operation.h>
#include <Atlas/Objects/Anonymous.h>
#include <algorithm>
2018-10-30 20:12:45 +01:00
#include <common/operations/Change.h>
using Atlas::Message::Element;
using Atlas::Message::MapType;
using Atlas::Objects::Operation::Appearance;
using Atlas::Objects::Entity::RootEntity;
using Atlas::Objects::Entity::Anonymous;
2004-12-03 Al Riddoch <alriddoch@zepler.org> * 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/Py_CreatorClient.cpp, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.h, common/custom.cpp, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/op_switch.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/Location.cpp, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/Missile.h, rulesets/Pedestrian.cpp, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_Mind.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Thing.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.h, rulesets/PythonThingScript.h, rulesets/Python_API.cpp, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/World.cpp, rulesets/World.h, server/Account.cpp, server/Account.h server/Admin.cpp, server/Admin.h, server/CommClient.cpp, server/Connection.cpp, server/Connection.h, server/EntityFactory.cpp, server/EntityFactory.h, server/Lobby.cpp, server/Lobby.h, server/Persistance.cpp, server/Persistance.h, server/Persistor.cpp, server/Player.cpp, server/Player.h, server/ServerRouting.cpp, server/ServerRouting.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, tests/Areatest.cpp, tests/Charactertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Planttest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Thingtest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/inheritancetest.cpp, tests/utilitytest.cpp, tools/cycmd.cpp: Modify the entity interface so that all Operation methods take references to RootOperation, as its cleaner, and requires less nasty casts. Clean up operations in headers generally.
2004-12-03 14:49:13 +00:00
static const bool debug_flag = false;
/// \brief Constructor for the world object.
WorldRouter::WorldRouter(const SystemTime & time, Ref<LocatedEntity> baseEntity) :
BaseWorld(),
2018-08-04 18:00:25 +02:00
m_operationsDispatcher([&](const Operation & op, Ref<LocatedEntity> from){this->operation(op, std::move(from));}, [&]()->double {return getTime();}),
m_entityCount(1),
m_baseEntity(std::move(baseEntity))
{
2011-10-31 11:19:33 +01:00
m_initTime = time.seconds();
m_eobjects[m_baseEntity->getIntId()] = m_baseEntity;
Monitors::instance().watch("entities", new Variable<int>(m_entityCount));
2018-04-26 19:48:53 +02:00
/**
* When types are updated we will send an "change" op to all connected clients.
*/
Inheritance::instance().typesUpdated.connect([&](const std::map<const TypeNode*, TypeNode::PropertiesUpdate> typeNodes) {
//Send Change ops to all clients
2018-04-29 11:59:33 +02:00
if (!typeNodes.empty()) {
Atlas::Objects::Operation::Change change;
std::vector<Atlas::Objects::Root> args;
for (auto& entry: typeNodes) {
auto typeNode = entry.first;
2018-04-29 11:59:33 +02:00
Atlas::Objects::Entity::Anonymous o;
o->setObjtype(typeNode->description(Visibility::PRIVATE)->getObjtype());
2018-04-29 11:59:33 +02:00
o->setId(typeNode->name());
args.emplace_back(o);
}
change->setArgs(args);
messageToClients(change);
//Go through all world entities and check if they need to be updated
for (auto& entry : m_eobjects) {
auto entity = entry.second;
auto I = typeNodes.find(entity->getType());
if (I != typeNodes.end()) {
auto typeNode = I->first;
// for (auto& removedPropName : I->second.removedProps) {
// if (entity->getProperties().find(removedPropName) == entity->getProperties().end()) {
// auto prop = typeNode->defaults().find(removedPropName)->second;
// prop->remove(entity, removedPropName);
// }
// }
for (auto& changedPropName : I->second.changedProps) {
if (entity->getProperties().find(changedPropName) == entity->getProperties().end()) {
auto prop = typeNode->defaults().find(changedPropName)->second;
prop->apply(entity.get());
entity->propertyApplied(changedPropName, *prop);
}
}
for (auto& newPropName : I->second.changedProps) {
if (entity->getProperties().find(newPropName) == entity->getProperties().end()) {
auto prop = typeNode->defaults().find(newPropName)->second;
prop->apply(entity.get());
entity->propertyApplied(newPropName, *prop);
}
}
}
}
2018-04-29 11:59:33 +02:00
}
2018-04-26 19:48:53 +02:00
});
}
/// \brief Destructor for the world object.
///
2018-04-26 19:48:53 +02:00
/// Destruction of the world object implicitly deletes all IG objects in
/// the server, clears the operation queue
WorldRouter::~WorldRouter()
{
{
debug(std::cout << "Flushing world with " << m_eobjects.size()
<< " entities" << std::endl << std::flush;);
}
//Make sure to clear the queues first so that there's nothing referencing entities
//in them.
m_operationsDispatcher.clearQueues();
m_suspendedQueue = std::queue<OpQueEntry<LocatedEntity>>();
m_eobjects.clear();
for (auto entry : m_spawns) {
delete entry.second.first;
}
m_spawns.clear();
}
bool WorldRouter::isQueueDirty() const
{
return m_operationsDispatcher.isQueueDirty();
}
void WorldRouter::markQueueAsClean()
{
m_operationsDispatcher.markQueueAsClean();
}
/// \brief Add a new entity to the world.
///
/// Adds a new entity to the lists maintained by the WorldRouter.
/// Verify that the entity has a valid location, setting to
/// the default spawn area if necessary. Handle inserting the
/// entity into the loc/contains tree maintained by the Entity
/// class. Send a Setup op to the entity.
2018-07-23 11:03:18 +02:00
Ref<LocatedEntity> WorldRouter::addEntity(const Ref<LocatedEntity>& ent)
{
2010-01-03 02:14:52 +00:00
debug(std::cout << "WorldRouter::addEntity(" << ent->getIntId() << ")" << std::endl
<< std::flush;);
assert(ent->getIntId() != 0);
m_eobjects[ent->getIntId()] = ent;
++m_entityCount;
if (!ent->m_location.isValid()) {
log(ERROR, String::compose("Entity %1 of type %2 added to world with invalid location!", ent->getId(), ent->getType()->name()));
debug(std::cout << "set loc " << &getDefaultLocation() << std::endl
<< std::flush;);
2018-08-17 22:04:07 +02:00
ent->m_location.m_parent = &getDefaultLocation();
2018-12-16 23:20:33 +01:00
// ent->m_location.m_pos = Point3D(uniform(-8,8), uniform(-8,8), 0);
ent->m_location.m_pos = Point3D::ZERO();
2018-08-17 22:04:07 +02:00
debug(std::cout << "loc set with loc " << ent->m_location.m_parent->getId()
<< std::endl << std::flush;);
}
ent->m_location.update(getTime());
2018-08-17 22:04:07 +02:00
ent->m_location.m_parent->addChild(*ent);
2018-07-25 19:48:19 +02:00
debug(std::cout << "Entity loc " << ent->m_location << std::endl
<< std::flush;);
if (ent->m_contains != nullptr) {
for (auto& child : *ent->m_contains) {
addEntity(child);
}
}
Anonymous arg;
Appearance app;
arg->setId(ent->getId());
arg->setStamp(ent->getSeq());
app->setArgs1(arg);
message(app, *ent);
2018-07-23 11:03:18 +02:00
inserted.emit(ent.get());
return ent;
}
/// \brief Create a new entity and add to the world.
///
/// Construct a new entity using the entity description provided,
/// and pass it to addEntity().
/// @return a pointer to the new entity.
2018-07-23 11:03:18 +02:00
Ref<LocatedEntity> WorldRouter::addNewEntity(const std::string & typestr,
const RootEntity & attrs)
{
debug(std::cout << "WorldRouter::addNewEntity(\"" << typestr << "\", attrs)"
<< std::endl << std::flush;);
std::string id;
long intId = newId(id);
if (intId < 0) {
log(ERROR, "Unable to get ID for new Entity");
2018-04-26 19:48:53 +02:00
return nullptr;
}
Ref<LocatedEntity> ent = EntityBuilder::instance().newEntity(id, intId, typestr, attrs, *this);
if (!ent) {
log(ERROR, String::compose("Attempt to create an entity of type \"%1\" "
"but type is unknown or forbidden",
typestr));
2018-04-26 19:48:53 +02:00
return nullptr;
}
return addEntity(ent);
}
int WorldRouter::createSpawnPoint(const MapType & data, LocatedEntity * ent)
{
2018-04-26 19:48:53 +02:00
auto I = data.find("name");
if (I == data.end() || !I->second.isString()) {
log(ERROR, "No name on spawn point");
return -1;
}
2018-10-27 13:13:45 +02:00
auto new_spawn = new SpawnEntity(ent);
2012-12-27 23:06:16 +00:00
if (new_spawn->setup(data) != 0) {
2012-12-28 13:38:50 +00:00
delete new_spawn;
2012-12-27 23:06:16 +00:00
log(ERROR, "Error setting up spawn point");
return -1;
}
const std::string & name = I->second.String();
2018-04-26 19:48:53 +02:00
auto J = m_spawns.find(name);
if (J != m_spawns.end()) {
Spawn * old = J->second.first;
J->second.first = new_spawn;
J->second.second = ent->getId();
2012-12-24 10:50:44 +00:00
delete old;
} else {
m_spawns.insert(std::make_pair(name, std::make_pair(new_spawn, ent->getId())));
}
return 0;
}
int WorldRouter::removeSpawnPoint(LocatedEntity * ent)
{
for (auto I = m_spawns.begin(); I != m_spawns.end(); ++I) {
if (I->second.second == ent->getId()) {
2014-01-20 18:38:36 +01:00
delete I->second.first;
m_spawns.erase(I);
return 0;
}
}
return 1;
}
int WorldRouter::getSpawnList(Atlas::Message::ListType & data)
{
for (auto entry : m_spawns) {
MapType spawn;
spawn.insert(std::make_pair("name", entry.first));
entry.second.first->addToMessage(spawn);
2014-01-24 12:29:25 +01:00
data.push_back(spawn);
}
return 0;
}
Ref<LocatedEntity> WorldRouter::spawnNewEntity(const std::string & name,
const std::string & type,
const RootEntity & desc)
{
SpawnDict::const_iterator I = m_spawns.find(name);
if (I == m_spawns.end()) {
2009-12-30 15:09:26 +00:00
log(ERROR, String::compose("Spawn not found %1", name));
2018-04-26 19:48:53 +02:00
return nullptr;
}
Spawn * s = I->second.first;
int ret = s->spawnEntity(type, desc);
if (ret != 0) {
2009-12-30 15:09:26 +00:00
log(ERROR, String::compose("Spawn not permitting %1", type));
2018-04-26 19:48:53 +02:00
return nullptr;
}
auto e = addNewEntity(type, desc);
if (!e) {
2009-12-30 15:09:26 +00:00
log(ERROR, String::compose("Entity creation failed %1", type));
return e;
}
return e;
}
int WorldRouter::moveToSpawn(const std::string & name, Location& location)
{
auto I = m_spawns.find(name);
if (I == m_spawns.end()) {
log(ERROR, String::compose("Spawn not found %1", name));
return -10;
}
return I->second.first->placeInSpawn(location);
}
ArithmeticScript * WorldRouter::newArithmetic(const std::string & name,
LocatedEntity * owner)
{
return ArithmeticBuilder::instance().newArithmetic(name, owner);
}
/// \brief Remove an entity from the world.
///
/// Remove an entity from the various lists in which it is stored.
/// The entity is removed from the LOC/CONTAINS tree, and the
/// reference held by the world is decremented. There may still be
/// a reference held by an operation in the queue from the removed
/// entity.
void WorldRouter::delEntity(LocatedEntity * ent)
{
if (ent == m_baseEntity.get()) {
log(WARNING, "Attempt to delete game world");
return;
}
assert(ent->getIntId() != 0);
ent->destroy();
ent->updated.emit();
m_eobjects.erase(ent->getIntId());
--m_entityCount;
}
void WorldRouter::resumeWorld()
{
//Take all suspended operations and add them to be executed.
while (!m_suspendedQueue.empty()) {
auto& ope = m_suspendedQueue.front();
2018-08-04 18:00:25 +02:00
m_operationsDispatcher.addOperationToQueue(std::move(ope.op), std::move(ope.from));
m_suspendedQueue.pop();
}
}
/// \brief Pass an operation to the World.
///
/// Pass an operation to addOperationToQueue()
/// so it gets added to the queue for dispatch.
/// If the op is a broadcast op, it will be split up into separate ops
/// for each observer.
void WorldRouter::message(const Operation & op, LocatedEntity & fromEntity)
{
2018-08-11 15:23:09 +02:00
if (op->isDefaultTo()) {
if (shouldBroadcastPerception(op)) {
OpVector res;
fromEntity.broadcast(op, res, Visibility::PUBLIC);
2018-08-11 15:23:09 +02:00
for (auto& broadcastedOp : res) {
m_operationsDispatcher.addOperationToQueue(broadcastedOp, Ref<LocatedEntity>(&fromEntity));
}
} else {
//Don't broadcast ops which shouldn't be broadcasted.
2018-08-11 23:25:38 +02:00
log(WARNING, String::compose("Trying to broadcast '%1' op from %2, which we don't allow.",
op->getParent(),
fromEntity.describeEntity()));
}
} else {
2018-08-04 18:00:25 +02:00
m_operationsDispatcher.addOperationToQueue(op, Ref<LocatedEntity>(&fromEntity));
}
debug(std::cout << "WorldRouter::message {"
2017-07-24 13:39:22 +02:00
<< op->getParent() << ":"
<< op->getFrom() << ":" << op->getTo() << "}" << std::endl
<< std::flush;);
}
void WorldRouter::messageToClients(const Operation & op)
{
auto& accounts = ServerRouting::instance().getAccounts();
OpVector res;
for (auto entry : accounts) {
2018-04-26 19:48:53 +02:00
entry.second->operation(op, res);
}
debug(std::cout << "WorldRouter::messageToClients {"
<< op->getParent() << ":"
<< op->getFrom() << ":" << op->getTo() << "}" << std::endl
<< std::flush;);
}
2016-08-16 09:35:16 +02:00
bool WorldRouter::shouldBroadcastPerception(const Operation & op) const
{
int op_class = op->getClassNo();
if (op_class == Atlas::Objects::Operation::SIGHT_NO ||
op_class == Atlas::Objects::Operation::SOUND_NO ||
op_class == Atlas::Objects::Operation::APPEARANCE_NO ||
op_class == Atlas::Objects::Operation::DISAPPEARANCE_NO) {
return true;
}
return false;
}
/// \brief Deliver an operation to its target.
///
/// Pass the operation to the target entity. The resulting operations
/// have their ref numbers set, and are added to the queue for
/// dispatch.
2018-08-04 18:00:25 +02:00
void WorldRouter::deliverTo(const Operation & op, Ref<LocatedEntity> ent)
{
//If the world is suspended and the op is a tick, we should store it
//(to be resent when the world is resumed) and not process it now.
if (m_isSuspended) {
if (op->getClassNo() == Atlas::Objects::Operation::TICK_NO) {
m_suspendedQueue.push(OpQueEntry<LocatedEntity>(op, ent));
return;
}
}
OpVector res;
debug(std::cout << "WorldRouter::deliverTo begin {"
2017-07-24 13:39:22 +02:00
<< op->getParent() << ":"
<< op->getFrom() << ":" << op->getTo() << "}" << std::endl
<< std::flush;);
2018-08-04 18:00:25 +02:00
ent->operation(op, res);
debug(std::cout << "WorldRouter::deliverTo done {"
2017-07-24 13:39:22 +02:00
<< op->getParent() << ":"
<< op->getFrom() << ":" << op->getTo() << "}" << std::endl
<< std::flush;);
2015-04-08 19:13:23 +02:00
for(auto& resOp : res) {
if (op->getFrom() == resOp->getTo()) {
if (!op->isDefaultSerialno() && resOp->isDefaultRefno()) {
resOp->setRefno(op->getSerialno());
}
}
2018-08-04 18:00:25 +02:00
message(resOp, *ent);
}
}
/// \brief Main in-game operation dispatch function.
///
/// Operations are passed here when they are due for dispatch.
/// Determine the target of the operation and deliver it directly.
/// @param op operation to be dispatched to the world.
/// @param from entity the operation to be dispatched was send from. Note
/// that it is possible that this entity has been destroyed.
2018-08-04 18:00:25 +02:00
void WorldRouter::operation(const Operation & op, Ref<LocatedEntity> from)
{
2002-03-11 Al Riddoch <alriddoch@zepler.org> * server/WorldRouter.cpp: Eliminate unnecessary call to opEnumerate() and enhance debugging output. * server/Player.cpp: Correct the use of string.compare() in older versions of libstdc++. * common/types.h: Added enumeration for other operations, not handled by the core, but considered valid. Added new type for storing mapping between operation parents and their enumerated type. * common/op_switch.h: Separate handling of operations known to be invalid from operations which are valid, but not explicitly added to the core. * common/inheritance.h, common/inheritance.cpp, common/custom.cpp: Provide global operation mapping where enumeration of operations can be looked up. Install all types handled by the core, and types known to be used in scripts. * common/BaseEntity.h, common/BaseEntity.cpp: Add object specific operation mapping where operation types each object is subscribed to can be enumerated, and others are rejected. Add mechanism so that objects can add to the mapping, this subscribing to operations. This makes enumerating operations much cheaper, and eliminates the overhead of handling ops an object has no interest in. * rulesets/Thing.h, rulesets/Thing.cpp: Add mechanism so scripts can subscribe to operations. * rulesets/Character.h, rulesets/Character.cpp: Add subscription mechanism for ops going to and from the mind. * rulesets/BaseMind.h, rulesets/BaseMind.cpp: Add subscription mechanism for sight and sound perception operations sub operations, and provide an interface to it for scripts. * server/Connection.cpp, server/Admin.cpp, server/Account.cpp, rulesets/World.cpp, rulesets/World.h, rulesets/Thing.cpp, rulesets/Stackable.cpp, rulesets/Plant.cpp, rulesets/Food.cpp, rulesets/Character.cpp, rulesets/BaseMind.cpp: Add subscriptions to operations for all core base classes. * rulesets/Python_API.cpp: When script is created, go through methods, and subscribe to the operations which are handled by them. * rulesets/Character.cpp: When calculating orientation of a walking character, assume it is standing upright. * physics/Vector3D.h: Add versions of mag() and distance() which omit the square root calculations, so that when their values are only used for comparison, the expensive square root calculations can be ommited. Add new version of collision and range checking functions which provide the optimal interface to the application. Add versions of methods which modify this rather than creating a new operation to eliminate wasted copies. * physics/Quaternion.cpp: Make use of faster interface provided by Vector3D. * physics/BBox.h: Add new version of collision checking function which provides optimal interface to the application. * modules/Location.h, modules/Location.cpp: Add new functions to optimally calculate the distance between any two entities. * modules/Location.h: Re-write collision and range functions to make much more optimal use of Vector3D, BBox and distance functionality. * rulesets/Py_Vector3D.cpp, rulesets/Pedestrian.cpp, rulesets/Movement.cpp, rulesets/Entity.cpp, rulesets/Character.cpp: Eliminate implicit copies from vector arithmetic. * rulesets/Pedestrian.cpp, rulesets/MemMap.cpp, common/const.h: Re-write code which uses magnitude of vectors to use the square of the magnitude instead, as it is much cheaper to calculate.
2002-03-11 18:24:19 +00:00
debug(std::cout << "WorldRouter::operation {"
2017-07-24 13:39:22 +02:00
<< op->getParent() << ":"
<< op->getFrom() << ":" << op->getTo() << "}"
<< std::endl << std::flush;);
2018-08-04 18:00:25 +02:00
assert(op->getFrom() == from->getId());
2018-04-26 19:48:53 +02:00
assert(!op->getParent().empty());
Dispatching.emit(op);
if (!op->isDefaultTo()) {
const std::string & to = op->getTo();
assert(!to.empty());
2018-08-04 18:00:25 +02:00
Ref<LocatedEntity> to_entity;
2018-08-04 18:00:25 +02:00
if (to == from->getId()) {
if (from->isDestroyed()) {
// Entity no longer exists
return;
}
2018-08-04 18:00:25 +02:00
to_entity = std::move(from);
} else {
to_entity = getEntity(to);
2018-04-26 19:48:53 +02:00
if (to_entity == nullptr) {
debug(std::cerr << "WARNING: Op to=\"" << to << "\""
<< " does not exist"
<< std::endl << std::flush;);
return;
}
}
2018-04-26 19:48:53 +02:00
assert(to_entity != nullptr);
2018-08-04 18:00:25 +02:00
deliverTo(op, std::move(to_entity));
} else {
auto I = m_eobjects.begin();
auto Iend = m_eobjects.end();
for (; I != Iend; ++I) {
op->setTo(I->second->getId());
2018-08-04 18:00:25 +02:00
deliverTo(op, I->second);
}
}
}
/// Main world loop function.
/// This function is called whenever the communications code is idle.
/// It updates the in-game time, and dispatches operations that are
/// now due for dispatch. The number of operations dispatched is limited
/// to 10 to ensure that client communications are always handled in a timely
/// manner. If the maximum number of operations are dispatched, the return
/// value indicates that this is the case, and the communications code
/// will call this function again as soon as possible rather than sleeping.
/// This ensures that the maximum possible number of operations are dispatched
/// without becoming unresponsive to client communications traffic.
bool WorldRouter::idle()
{
return m_operationsDispatcher.idle(10);
}
/// Find an entity of the given name. This is provided to allow administrators
/// to perform certain admin tasks. It finds and returns the first instance
/// with the name provided in the game world.
/// @param name string specifying name of the instance required.
/// @return a pointer to an entity with the type required, or zero if an
/// instance with this name was not found.
Ref<LocatedEntity> WorldRouter::findByName(const std::string & name)
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
{
Element name_attr;
auto Iend = m_eobjects.end();
for (auto I = m_eobjects.begin(); I != Iend; ++I) {
2011-09-29 17:36:26 +01:00
if (I->second->getAttr("name", name_attr) == 0) {
if (name_attr == name) {
return I->second;
}
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
}
}
2018-01-30 16:54:49 +01:00
return nullptr;
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
}
/// Find an entity of the given type. This is provided to allow administrators
/// to perform certain admin tasks. It finds and returns the first instance
/// of the type provided in the game world.
/// @param type string specifying the class name of the instance required.
/// @return a pointer to an entity of the type required, or zero if no
/// instance was found.
Ref<LocatedEntity> WorldRouter::findByType(const std::string & type)
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
{
auto Iend = m_eobjects.end();
for(auto I = m_eobjects.begin(); I != Iend; ++I) {
if (I->second->getType()->name() == type) {
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
return I->second;
}
}
2018-01-30 16:54:49 +01:00
return nullptr;
2002-08-30 Al Riddoch <alriddoch@zepler.org> * common/globals.cpp: Only persist this sessions command line options if the user is overriding the installation directory. * cyphesis.vconf, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp: Add client functionality to allow diferent scripts to be run to perform different functions on the server. * client/CharacterClient.cpp: Add debug option. * rulesets/Character.h: Make mind operation functions virtual, so they can be overridden. * common/BaseWorld.h, server/WorldRouter.cpp, server/WorldRouter.h: Add server functions to search for entities by name or type. * rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to specify a look without an id to search for entities with a given name or type. * client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, rulesets/basic/editor.py, rulesets/mason/define_world.py: Add support for looking for entities in the world by name or type from client script, so client scripts can modify existing world. * rulesets/Entity.cpp, rulesets/Movement.cpp, rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp, rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp, server/CommServer.cpp, server/Connection.cpp, server/Player.cpp, server/ServerRouting.cpp, server/server.cpp, tools/cycmd.cpp, tools/cywatchdog.cpp: Code formatting cleanups. * rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now fires correctly.
2002-08-30 13:48:39 +00:00
}
LocatedEntity& WorldRouter::getDefaultLocation() const
{
if (m_defaultLocation) {
return *m_defaultLocation;
}
return *m_baseEntity;
}
OperationsHandler& WorldRouter::getOperationsHandler()
{
return m_operationsDispatcher;
}