cyphesis/modules/Location.cpp

347 lines
10 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-2008 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 "rulesets/LocatedEntity.h"
#include "common/log.h"
#include "common/const.h"
#include "common/debug.h"
#include <wfmath/atlasconv.h>
#include <Atlas/Objects/Anonymous.h>
#include <iostream>
using Atlas::Message::Element;
using Atlas::Message::MapType;
using Atlas::Objects::Entity::Anonymous;
static const bool debug_flag = false;
Location::Location() :
m_simple(true), m_solid(true),
m_boxSize(consts::minBoxSize),
m_squareBoxSize(consts::minSqrBoxSize),
m_loc(0)
{
}
Location::Location(LocatedEntity * rf) :
m_simple(true), m_solid(true),
m_boxSize(consts::minBoxSize),
m_squareBoxSize(consts::minSqrBoxSize),
m_loc(rf)
{
}
Location::Location(LocatedEntity * rf, const Point3D & pos) :
m_simple(true), m_solid(true),
m_boxSize(consts::minBoxSize),
m_squareBoxSize(consts::minSqrBoxSize),
m_loc(rf), m_pos(pos)
{
}
Location::Location(LocatedEntity * rf,
const Point3D& pos,
const Vector3D& velocity) :
m_simple(true), m_solid(true),
m_boxSize(consts::minBoxSize),
m_squareBoxSize(consts::minSqrBoxSize),
m_loc(rf), m_pos(pos), m_velocity(velocity)
{
}
void Location::addToMessage(MapType & omap) const
{
if (m_loc!=NULL) {
2004-08-07 Al Riddoch <alriddoch@zepler.org> * common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.h, common/Database.cpp, common/Database.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/accountbase.cpp, common/accountbase.h, common/custom.cpp, common/inheritance.cpp, common/inheritance.h, common/operations.h, common/type_utils.h, common/utility.cpp, common/utility.h, modules/Location.cpp, modules/Location.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h, rulesets/Creator.cpp, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Entity_getLocation.h, rulesets/Food.cpp, rulesets/Line.cpp, rulesets/Line.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/Pedestrian.cpp, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_Mind.cpp, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Thing.cpp, rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Thing.cpp, rulesets/World.cpp, rulesets/World.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/CommClient.cpp, server/CommClient.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMetaClient.h, server/CommPSQLSocket.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, 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/PersistantThingFactory.h, server/Persistor.cpp, server/Player.cpp, server/Player.h, server/Restorer.h, server/Restorer_impl.h, server/ServerRouting.cpp, server/ServerRouting.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h: Convert code to using Atlas Message typedefs as found in Atlas-C++ 0.6 to aid conversion later.
2004-08-16 14:26:47 +00:00
omap["loc"] = m_loc->getId();
}
if (pos().isValid()) {
omap["pos"] = pos().toAtlas();
}
if (velocity().isValid()) {
omap["velocity"] = velocity().toAtlas();
}
if (orientation().isValid()) {
omap["orientation"] = orientation().toAtlas();
}
if (bBox().isValid()) {
omap["bbox"] = bBox().toAtlas();
}
}
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
void Location::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
{
if (m_loc!=NULL) {
ent->setLoc(m_loc->getId());
}
if (pos().isValid()) {
::addToEntity(pos(), ent->modifyPos());
}
if (velocity().isValid()) {
::addToEntity(velocity(), ent->modifyVelocity());
}
if (orientation().isValid()) {
ent->setAttr("orientation", orientation().toAtlas());
}
if (bBox().isValid()) {
ent->setAttr("bbox", bBox().toAtlas());
}
}
int Location::readFromMessage(const MapType & msg)
{
try {
MapType::const_iterator I = msg.find("pos");
MapType::const_iterator Iend = msg.end();
if (I != Iend) {
const Element & pos = I->second;
if (pos.isList() && pos.List().size() == 3) {
m_pos.fromAtlas(pos);
} else {
log(ERROR, "Malformed POS data");
}
}
I = msg.find("orientation");
if (I != Iend) {
const Element & orientation = I->second;
if (orientation.isList() && orientation.List().size() == 4) {
m_orientation.fromAtlas(orientation);
} else {
log(ERROR, "Malformed ORIENTATION data");
}
}
}
catch (Atlas::Message::WrongTypeException&) {
log(ERROR, "Location::readFromMessage: Bad location data");
return -1;
}
return 0;
}
int Location::readFromEntity(const Atlas::Objects::Entity::RootEntity & ent)
{
debug( std::cout << "Location::readFromEntity" << std::endl << std::flush;);
try {
if (ent->hasAttrFlag(Atlas::Objects::Entity::POS_FLAG)) {
fromStdVector(m_pos, ent->getPos());
}
if (ent->hasAttrFlag(Atlas::Objects::Entity::VELOCITY_FLAG)) {
fromStdVector(m_velocity, ent->getVelocity());
}
Element orientation;
if (ent->copyAttr("orientation", orientation) == 0) {
if (orientation.isList() && orientation.List().size() == 4) {
m_orientation.fromAtlas(orientation);
} else {
log(ERROR, "Malformed ORIENTATION data");
}
}
}
catch (Atlas::Message::WrongTypeException&) {
log(ERROR, "Location::readFromEntity: Bad location data");
return -1;
}
return 0;
}
void Location::modifyBBox()
{
if (!m_bBox.isValid()) {
return;
}
m_squareBoxSize = square(m_bBox.highCorner().x() - m_bBox.lowCorner().x()) +
square(m_bBox.highCorner().y() - m_bBox.lowCorner().y()) +
square(m_bBox.highCorner().z() - m_bBox.lowCorner().z());
2011-04-27 19:46:13 +01:00
m_boxSize = std::sqrt(m_squareBoxSize);
m_squareRadius = std::max(square(m_bBox.lowCorner().x()) +
square(m_bBox.lowCorner().y()) +
square(m_bBox.lowCorner().z()),
square(m_bBox.highCorner().x()) +
square(m_bBox.highCorner().y()) +
square(m_bBox.highCorner().z()));
2011-04-27 19:46:13 +01:00
m_radius = std::sqrt(m_squareRadius);
}
void Location::setVisibility(float v)
{
m_boxSize = v;
m_squareBoxSize = v * v;
// TODO m_radius and m_squareRadius? Unused everywhere for now.
}
const Atlas::Objects::Root Location::asEntity() const
{
Anonymous ret;
addToEntity(ret);
return ret;
}
static const Location* distanceFromAncestor(const Location & self,
const Location & other, Point3D & c)
{
if (&self == &other) {
return &self;
}
if (other.m_loc == nullptr) {
return nullptr;
}
if (!other.m_pos.isValid()) {
return nullptr;
}
if (other.orientation().isValid()) {
c = c.toParentCoords(other.m_pos, other.orientation());
} else {
2012-03-05 09:30:49 +00:00
static const Quaternion identity((Quaternion::Identity()));
c = c.toParentCoords(other.m_pos, identity);
}
return distanceFromAncestor(self, other.m_loc->m_location, c);
}
static const Location* distanceToAncestor(const Location & self,
const Location & other, Point3D & c)
{
if (!self.m_pos.isValid()) {
return nullptr;
}
c.setToOrigin();
const Location* ancestor = distanceFromAncestor(self, other, c);
if (ancestor) {
return ancestor;
} else if ((self.m_loc != 0)) {
ancestor = distanceToAncestor(self.m_loc->m_location, other, c);
if (ancestor) {
if (self.orientation().isValid()) {
c = c.toLocalCoords(self.m_pos, self.orientation());
} else {
static const Quaternion identity(1, 0, 0, 0);
c = c.toLocalCoords(self.m_pos, identity);
}
return ancestor;
}
}
log(ERROR, "Broken entity hierarchy doing distance calculation");
if (self.m_loc != 0) {
std::cerr << "Self(" << self.m_loc->getId() << "," << self.m_loc << ")"
<< std::endl << std::flush;
2016-05-15 23:39:55 +02:00
} else {
std::cerr << "Self has no location"
<< std::endl << std::flush;
}
if (other.m_loc != 0) {
std::cerr << "Other(" << other.m_loc->getId() << "," << other.m_loc << ")"
<< std::endl << std::flush;
2016-05-15 23:39:55 +02:00
} else {
std::cerr << "Other has no location"
<< std::endl << std::flush;
}
return nullptr;
}
/// \brief Determine the vector distance from self to other.
///
/// @param self Location of an entity
/// @param other Location of an entity the distance of which is to be
/// determined
/// @return The vector distance from self to other.
/// The distance calculated is a vector relative to the parent of the
/// entity who's location is given by self. This is useful for determing
/// both the scalar distance to another entity, and a direction vector
/// that can be used to determine the direction for motion if it
/// is necessary to head toward the other entity.
const Vector3D distanceTo(const Location & self, const Location & other)
{
static Point3D origin(0,0,0);
Point3D pos;
distanceToAncestor(self, other, pos);
Vector3D dist = pos - origin;
if (self.orientation().isValid()) {
dist.rotate(self.orientation());
}
return dist;
}
/// \brief Determine the position of other relative to self.
///
/// @param self Location of an entity
/// @param other Location of an entity this position of which is to be
/// determined
/// @return The position of other.
/// The position calculated is relative to the entity who's location is given
/// by self. The calculation is very similar to distanceTo() but an extra
/// step is ommited.
const Point3D relativePos(const Location & self, const Location & other)
{
Point3D pos;
distanceToAncestor(self, other, pos);
return pos;
}
float squareDistance(const Location & self, const Location & other)
{
Point3D dist;
distanceToAncestor(self, other, dist);
return sqrMag(dist);
}
float squareDistanceWithAncestor(const Location & self, const Location & other, const Location** ancestor)
{
Point3D dist;
*ancestor = distanceToAncestor(self, other, dist);
if (ancestor) {
return sqrMag(dist);
}
return 0.f;
}
float squareHorizontalDistance(const Location & self, const Location & other)
{
Point3D dist;
distanceToAncestor(self, other, dist);
dist.z() = 0.f;
return sqrMag(dist);
}
std::ostream & operator<<(std::ostream& s, Location& v)
{
s << "{";
if (v.m_loc != 0) {
s << v.m_loc->getId();
} else {
s << "null";
}
if (v.pos().isValid()) {
s << "," << v.pos();
if (v.velocity().isValid()) {
s << "," << v.velocity();
}
}
return s << "}";
}