cyphesis/rulesets/Py_Thing.cpp

796 lines
26 KiB
C++
Raw 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 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
// $Id$
#include "Py_Thing.h"
#include "Py_Map.h"
#include "Py_Message.h"
#include "Py_Vector3D.h"
#include "Py_Point3D.h"
#include "Py_Location.h"
#include "Py_World.h"
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
#include "Py_Property.h"
#include "Py_Operation.h"
#include "Py_Oplist.h"
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
#include "Py_Task.h"
#include "Py_WorldTime.h"
#include "PythonWrapper.h"
#include "BaseMind.h"
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
#include "Character.h"
#include "common/id.h"
#include "common/log.h"
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
#include "common/Property.h"
#include "common/TypeNode.h"
#include "common/Inheritance.h"
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
using Atlas::Message::Element;
using Atlas::Message::MapType;
static PyObject * Entity_as_entity(PyEntity * self)
{
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
#ifndef NDEBUG
if (self->m_entity.l == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.as_entity");
return NULL;
}
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
#endif // NDEBUG
PyMessage * ret = newPyMessage();
if (ret != NULL) {
ret->m_obj = new Element(MapType());
self->m_entity.l->addToMessage(ret->m_obj->asMap());
}
return (PyObject *)ret;
}
static PyMethodDef LocatedEntity_methods[] = {
{"as_entity", (PyCFunction)Entity_as_entity, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
static PyObject * Entity_send_world(PyEntity * self, PyOperation * op)
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
{
#ifndef NDEBUG
if (self->m_entity.e == NULL) {
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.send_world");
return NULL;
}
#endif // NDEBUG
if (PyOperation_Check(op)) {
self->m_entity.e->sendWorld(op->operation);
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
} else {
PyErr_SetString(PyExc_TypeError, "Entity.send_world must be an op");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef Entity_methods[] = {
{"send_world", (PyCFunction)Entity_send_world, METH_O},
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
{NULL, NULL} /* sentinel */
};
static PyObject * Character_start_task(PyEntity * self, PyObject * args)
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
{
#ifndef NDEBUG
if (self->m_entity.l == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.start_task");
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
return NULL;
}
#endif // NDEBUG
PyObject * task;
PyObject * op;
PyObject * res;
if (!PyArg_ParseTuple(args, "OOO", &task, &op, &res)) {
return NULL;
}
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
if (!PyTask_Check(task)) {
PyErr_SetString(PyExc_TypeError, "Entity.start_task must be a task");
return NULL;
}
if (!PyOperation_Check(op)) {
PyErr_SetString(PyExc_TypeError, "Entity.start_task must be an op");
return NULL;
}
if (!PyOplist_Check(res)) {
PyErr_SetString(PyExc_TypeError, "Entity.start_task must be an oplist");
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
return NULL;
}
self->m_entity.c->startTask(((PyTask*)task)->m_task,
((PyOperation*)op)->operation,
*((PyOplist*)res)->ops);
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
Py_INCREF(Py_None);
return Py_None;
}
static PyObject * Character_mind2body(PyEntity * self, PyOperation * op)
{
#ifndef NDEBUG
if (self->m_entity.l == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.mind2body");
return NULL;
}
#endif // NDEBUG
if (!PyOperation_Check(op)) {
PyErr_SetString(PyExc_TypeError, "Entity.mind2body must be an operation");
return NULL;
}
OpVector res;
self->m_entity.c->mind2body(op->operation, res);
if (res.empty()) {
Py_INCREF(Py_None);
return Py_None;
} else if (res.size() == 1) {
PyOperation * ret = newPyOperation();
if (ret != NULL) {
ret->operation = res[0];
}
return (PyObject*)ret;
} else {
PyOplist * ret = newPyOplist();
if (ret != NULL) {
ret->ops = new OpVector(res);
}
return (PyObject*)ret;
}
}
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
static PyMethodDef Character_methods[] = {
{"start_task", (PyCFunction)Character_start_task, METH_VARARGS},
{"mind2body", (PyCFunction)Character_mind2body, METH_O},
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
{NULL, NULL} /* sentinel */
};
2011-10-12 15:29:52 +01:00
static PyEntity * Entity_new(PyTypeObject * type,
PyObject * args,
PyObject * kwds)
{
PyEntity * self = (PyEntity *)type->tp_alloc(type, 0);
if (self != NULL) {
self->m_weakreflist = NULL;
}
return self;
}
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
static void Entity_dealloc(PyEntity *self)
{
2011-10-12 15:29:52 +01:00
if (self->m_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *) self);
}
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * Entity_getattro(PyEntity *self, PyObject *oname)
{
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
#ifndef NDEBUG
if (self->m_entity.e == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.getattr");
return NULL;
}
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
#endif // NDEBUG
char * name = PyString_AsString(oname);
// If operation search gets to here, it goes no further
if (strcmp(name, "type") == 0) {
if (self->m_entity.e->getType() == NULL) {
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
PyObject * list = PyList_New(0);
if (list == NULL) {
return NULL;
}
PyObject * ent = PyString_FromString(self->m_entity.e->getType()->name().c_str());
PyList_Append(list, ent);
Py_DECREF(ent);
return list;
}
if (strcmp(name, "location") == 0) {
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
PyLocation * loc = newPyLocation();
if (loc != NULL) {
loc->location = &self->m_entity.e->m_location;
loc->owner = self->m_entity.e;
}
return (PyObject *)loc;
}
if (strcmp(name, "contains") == 0) {
if (self->m_entity.e->m_contains == 0) {
Py_INCREF(Py_None);
return Py_None;
}
PyObject * list = PyList_New(0);
if (list == NULL) {
return NULL;
}
LocatedEntitySet::const_iterator I = self->m_entity.e->m_contains->begin();
LocatedEntitySet::const_iterator Iend = self->m_entity.e->m_contains->end();
for (; I != Iend; ++I) {
LocatedEntity * child = *I;
PyObject * wrapper = wrapEntity(child);
if (wrapper == NULL) {
Py_DECREF(list);
return NULL;
}
PyList_Append(list, wrapper);
Py_DECREF(wrapper);
}
return list;
}
Entity * entity = self->m_entity.e;
PropertyBase * prop = entity->modProperty(name);
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
if (prop != 0) {
PyObject * ret = Property_asPyObject(prop, entity);
if (ret != 0) {
return ret;
}
Element attr;
// If this property is not set with a value, return none.
if (prop->get(attr) == 0) {
return MessageElement_asPyObject(attr);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
return PyObject_GenericGetAttr((PyObject *)self, oname);
}
static int Entity_setattro(PyEntity *self, PyObject *oname, PyObject *v)
{
#ifndef NDEBUG
if (self->m_entity.e == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL entity in Entity.setattr");
return -1;
}
#endif // NDEBUG
char * name = PyString_AsString(oname);
if (strcmp(name, "map") == 0) {
PyErr_SetString(PyExc_AttributeError, "map attribute forbidden");
return -1;
}
Entity * entity = self->m_entity.e;
//std::string attr(name);
//if (v == NULL) {
//entity->attributes.erase(attr);
//return 0;
//}
if (strcmp(name, "type") == 0) {
if (entity->getType() != 0) {
PyErr_SetString(PyExc_RuntimeError, "Cannot mutate entity type");
return -1;
}
if (!PyString_CheckExact(v)) {
PyErr_SetString(PyExc_TypeError, "No string type");
return -1;
}
const TypeNode * type = Inheritance::instance().getType(PyString_AsString(v));
if (type == 0) {
2012-01-04 16:52:40 +00:00
PyErr_SetString(PyExc_ValueError, "Entity type unknown");
return -1;
}
entity->setType(type);
return 0;
}
Element obj;
if (PyObject_asMessageElement(v, obj) == 0) {
PropertyBase * p = entity->setAttr(name, obj);
if (p != 0) {
p->setFlags(flag_unsent);
}
return 0;
}
2011-12-27 10:28:14 +01:00
return PyObject_GenericSetAttr((PyObject *)self, oname, v);
}
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
static int Entity_compare(PyEntity *self, PyEntity *other)
{
if (self->m_entity.e == NULL || other->m_entity.e == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL Entity in Entity.compare");
return -1;
}
return (self->m_entity.e == other->m_entity.e) ? 0 : 1;
}
static int LocatedEntity_init(PyEntity * self, PyObject * args, PyObject * kwds)
{
char * id = NULL;
if (!PyArg_ParseTuple(args, "s", &id)) {
return -1;
}
long intId = integerId(id);
if (intId == -1L) {
PyErr_SetString(PyExc_TypeError, "Entity() requires string/int ID");
return -1;
}
self->m_entity.l = new Entity(id, intId);
return 0;
}
static int Entity_init(PyEntity * self, PyObject * args, PyObject * kwds)
{
PyObject * arg;
if (!PyArg_ParseTuple(args, "O", &arg)) {
return -1;
}
if (PyString_Check(arg)) {
char * id = PyString_AsString(arg);
long intId = integerId(id);
if (intId == -1L) {
PyErr_SetString(PyExc_TypeError, "Entity() requires string/int ID");
return -1;
}
self->m_entity.e = new Entity(id, intId);
return 0;
}
if (PyEntity_Check(arg)) {
PyEntity * character = (PyEntity *)arg;
#ifndef NDEBUG
if (character->m_entity.c == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL character Task.__init__");
return -1;
}
#endif // NDEBUG
self->m_entity.c = character->m_entity.c;
return 0;
}
PyErr_SetString(PyExc_TypeError, "Entity() requires string ID or Entity");
return -1;
}
static int Character_init(PyEntity * self, PyObject * args, PyObject * kwds)
{
PyObject * arg;
if (!PyArg_ParseTuple(args, "O", &arg)) {
return -1;
}
if (PyString_Check(arg)) {
char * id = PyString_AsString(arg);
long intId = integerId(id);
if (intId == -1L) {
PyErr_SetString(PyExc_TypeError, "Entity() requires string/int ID");
return -1;
}
self->m_entity.c = new Character(id, intId);
return 0;
}
if (PyCharacter_Check(arg)) {
PyEntity * character = (PyEntity *)arg;
#ifndef NDEBUG
if (character->m_entity.c == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL character Task.__init__");
return -1;
}
#endif // NDEBUG
self->m_entity.c = character->m_entity.c;
return 0;
}
PyErr_SetString(PyExc_TypeError, "Character() requires string ID or Character");
return -1;
}
static PyObject * Mind_getattro(PyEntity *self, PyObject *oname)
{
#ifndef NDEBUG
if (self->m_entity.m == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL mind in Mind.getattr");
return NULL;
}
#endif // NDEBUG
char * name = PyString_AsString(oname);
if (strcmp(name, "id") == 0) {
return (PyObject *)PyString_FromString(self->m_entity.m->getId().c_str());
}
if (strcmp(name, "type") == 0) {
if (self->m_entity.m->getType() == NULL) {
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
PyObject * list = PyList_New(0);
if (list == NULL) {
return NULL;
}
PyObject * ent = PyString_FromString(self->m_entity.m->getType()->name().c_str());
PyList_Append(list, ent);
Py_DECREF(ent);
return list;
}
if (strcmp(name, "map") == 0) {
PyMap * map = newPyMap();
if (map != NULL) {
map->m_map = self->m_entity.m->getMap();
}
return (PyObject *)map;
}
if (strcmp(name, "location") == 0) {
PyLocation * loc = newPyLocation();
if (loc != NULL) {
loc->location = &self->m_entity.m->m_location;
loc->owner = self->m_entity.m;
}
return (PyObject *)loc;
}
if (strcmp(name, "time") == 0) {
PyWorldTime * worldtime = newPyWorldTime();
if (worldtime != NULL) {
worldtime->time = self->m_entity.m->getTime();
}
return (PyObject *)worldtime;
}
if (strcmp(name, "contains") == 0) {
if (self->m_entity.m->m_contains == 0) {
Py_INCREF(Py_None);
return Py_None;
}
PyObject * list = PyList_New(0);
if (list == NULL) {
return NULL;
}
LocatedEntitySet::const_iterator I = self->m_entity.m->m_contains->begin();
LocatedEntitySet::const_iterator Iend = self->m_entity.m->m_contains->end();
for (; I != Iend; ++I) {
LocatedEntity * child = *I;
PyObject * wrapper = wrapEntity(child);
if (wrapper == NULL) {
Py_DECREF(list);
return NULL;
}
PyList_Append(list, wrapper);
Py_DECREF(wrapper);
}
return list;
}
LocatedEntity * mind = self->m_entity.m;
Element attr;
if (mind->getAttr(name, attr) == 0) {
return MessageElement_asPyObject(attr);
}
return PyObject_GenericGetAttr((PyObject *)self, oname);
}
static int Mind_setattro(PyEntity *self, PyObject *oname, PyObject *v)
{
char * name = PyString_AsString(oname);
if (strcmp(name, "mind") == 0) {
if (!PyMind_Check(v)) {
PyErr_SetString(PyExc_TypeError, "Mind.mind requires Mind");
return -1;
}
self->m_entity.m = ((PyEntity*)v)->m_entity.m;
return 0;
}
#ifndef NDEBUG
if (self->m_entity.m == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL mind in Mind.setattr");
return -1;
}
#endif // NDEBUG
if (strcmp(name, "map") == 0) {
2012-01-04 16:52:40 +00:00
PyErr_SetString(PyExc_AttributeError, "Setting map on mind is forbidden");
return -1;
}
LocatedEntity * entity = self->m_entity.m;
// Should we support removal of attributes?
//std::string attr(name);
//if (v == NULL) {
//entity->attributes.erase(attr);
//return 0;
//}
Element obj;
if (PyObject_asMessageElement(v, obj, true) == 0) {
assert(!obj.isMap() && !obj.isList());
// In the Python wrapper for Entity in Py_Thing.cpp notices are issued
// for some types.
entity->setAttr(name, obj);
return 0;
}
2011-12-27 10:28:14 +01:00
return PyObject_GenericSetAttr((PyObject *)self, oname, v);
}
static int Mind_compare(PyEntity *self, PyEntity *other)
{
if (self->m_entity.m == NULL || other->m_entity.m == NULL) {
PyErr_SetString(PyExc_AssertionError, "NULL mind in Mind.compare");
return -1;
}
return (self->m_entity.m == other->m_entity.m) ? 0 : 1;
}
static int Mind_init(PyEntity * self, PyObject * args, PyObject * kwds)
{
char * id = NULL;
if (!PyArg_ParseTuple(args, "s", &id)) {
return -1;
}
long intId = integerId(id);
if (intId == -1L) {
PyErr_SetString(PyExc_TypeError, "Mind() requires string/int ID");
return -1;
}
self->m_entity.m = new BaseMind(id, intId);
return 0;
}
PyTypeObject PyLocatedEntity_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"server.LocatedEntity", /*tp_name*/
sizeof(PyEntity), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)Entity_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
(cmpfunc)Entity_compare, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, // tp_call
0, // tp_str
(getattrofunc)Entity_getattro, // tp_getattro
(setattrofunc)Entity_setattro, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags
"LocatedEntity objects", // tp_doc
0, // tp_travers
0, // tp_clear
0, // tp_richcompare
2011-10-12 15:29:52 +01:00
offsetof(PyEntity, m_weakreflist), // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
LocatedEntity_methods, // tp_methods
0, // tp_members
0, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
(initproc)LocatedEntity_init, // tp_init
0, // tp_alloc
2011-10-12 15:29:52 +01:00
(newfunc)Entity_new, // tp_new
};
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
PyTypeObject PyEntity_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"server.Entity", /*tp_name*/
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
sizeof(PyEntity), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
0, /*tp_dealloc*/
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
(cmpfunc)Entity_compare, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags
"Entity objects", // tp_doc
0, // tp_travers
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
Entity_methods, // tp_methods
0, // tp_members
0, // tp_getset
&PyLocatedEntity_Type, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
(initproc)Entity_init, // tp_init
0, // tp_alloc
2011-10-12 15:29:52 +01:00
(newfunc)Entity_new, // tp_new
};
PyTypeObject PyCharacter_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"server.Character", /*tp_name*/
sizeof(PyEntity), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
(cmpfunc)Entity_compare, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags
"Character objects", // tp_doc
0, // tp_travers
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
Character_methods, // tp_methods
0, // tp_members
0, // tp_getset
&PyEntity_Type, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
(initproc)Character_init, // tp_init
0, // tp_alloc
2011-10-12 15:29:52 +01:00
(newfunc)Entity_new, // tp_new
};
PyTypeObject PyMind_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"server.Mind", // tp_name
sizeof(PyEntity), // tp_basicsize
0, // tp_itemsize
// methods
0, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
(cmpfunc)Mind_compare, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
(getattrofunc)Mind_getattro, // tp_getattro
(setattrofunc)Mind_setattro, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags
"Mind objects", // tp_doc
0, // tp_travers
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
2011-12-27 15:02:28 +01:00
0, // tp_methods
0, // tp_members
0, // tp_getset
&PyLocatedEntity_Type, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
(initproc)Mind_init, // tp_init
0, // tp_alloc
(newfunc)Entity_new, // tp_new
};
template<>
PyObject * wrapPython<LocatedEntity>(LocatedEntity * le)
{
PyEntity * pe;
Entity * entity = dynamic_cast<Entity *>(le);
if (entity != 0) {
Character * ch_entity = dynamic_cast<Character *>(entity);
if (ch_entity != 0) {
pe = newPyCharacter();
if (pe == NULL) {
return NULL;
}
pe->m_entity.c = ch_entity;
} else {
pe = newPyEntity();
if (pe == NULL) {
return NULL;
}
pe->m_entity.e = entity;
}
} else {
pe = newPyLocatedEntity();
if (pe == NULL) {
return NULL;
}
pe->m_entity.l = le;
}
return (PyObject*)pe;
}
template<>
PyObject * wrapPython<Entity>(Entity * e)
{
return wrapPython<LocatedEntity>(e);
}
template<>
PyObject * wrapPython<BaseMind>(BaseMind * t)
{
PyEntity * pm = newPyMind();
if (pm == NULL) {
return NULL;
}
pm->m_entity.m = t;
return (PyObject*)pm;
}
PyObject * wrapEntity(LocatedEntity * le)
{
PyObject * wrapper = 0;
if (le->script() == 0) {
wrapper = wrapPython(le);
le->setScript(new PythonWrapper(wrapper));
} else {
PythonWrapper * pw = dynamic_cast<PythonWrapper *>(le->script());
if (pw == 0) {
log(WARNING, "Entity has script of unknown type");
} else {
wrapper = pw->wrapper();
assert(wrapper != NULL);
Py_INCREF(wrapper);
}
}
return wrapper;
}
// FIXME if this is cleaner to use the methods field of the type for methods,
// one PyTypeObject for each, and just share the members. That way we lose
// the need for a members entry on the object.
PyEntity * newPyLocatedEntity()
{
return (PyEntity *)PyLocatedEntity_Type.tp_new(&PyLocatedEntity_Type, 0, 0);
}
2003-09-08 Al Riddoch <alriddoch@zepler.org> * client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.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_Quaternion.cpp, rulesets/Py_Quaternion.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/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp: Clean up python API code, with decent names for types, decent error reporting, and making the more paranoid checks only present in debug build. * common/BaseEntity.cpp, common/BaseEntity.h, server/Account.cpp: Remove pointless method setRefnoOp, and put it in the body as an inline method. * common/BaseEntity.h, common/BaseWorld.cpp, common/Setup.h, common/Tick.h, common/operations.h, common/custom.cpp, common/types.h, common/utility.cpp, common/utility.h, modules/Location.h, physics/Vector3D.h, rulesets/BaseMind.cpp, rulesets/Script.h, server/EntityFactory.h: Clean up the dependency trees using more forward declarations. * common/inheritance.cpp, common/inheritance.h: Move most of the implementation into the .cpp file as its not suited to inlining. * rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h: Move contents of MemMap_methods.h into the .cpp file, as it is not suited to inlining, and remove the file from the build.
2003-09-07 23:38:32 +00:00
PyEntity * newPyEntity()
{
return (PyEntity *)PyEntity_Type.tp_new(&PyEntity_Type, 0, 0);
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
}
PyEntity * newPyCharacter()
2005-12-30 Al Riddoch <alriddoch@zepler.org> * rulesets/Character.cpp, rulesets/StatisticsProperty.h, rulesets/StatisticsProperty.cpp: Add a property handler for statistics. * rulesets/Character.cpp: When setting task, check if an existing task needs to be cleared first. When clearing a task, check whether a task exists or not. * rulesets/Character.cpp: When initiating combat task from task factory, check to see if the task is successfully created before using it. * rulesets/Py_Property.cpp, rulesets/Py_Property.h: New python wrapper class for entity properties. * rulesets/Py_Mind.cpp: Re-work getattr logic to make it clearer. * rulesets/Py_Object.cpp: Return Py_None when an Atlas Element cannot be converted to python. This ensures that this function never returns null. * rulesets/Py_Statistics.cpp: Add temporary handlers for hardcoded statistics for "attack", "defence", and "strength". * rulesets/Py_Task.cpp: Add wrappers for methods Task.irrelevant and Task.obsolete, as these are now required in combat scripts. * rulesets/Py_Task.h: Fix the PyTask_Check macro, which was miscoded. * rulesets/Py_Thing.cpp: Add wrapper for Entity.send_world so that scripts can channel ops through entities. * rulesets/Py_Thing.h, rulesets/Py_Thing.cpp: Add an addition structure for directlty wrapping Character in a type safe way. Add method structure pointer to Entity and Character wrappers so that the same getattr method is used for both. Add new method table for Character including wrappers for set_task and clear_task, allowing task scripts to add themselves and remove themselves from characters. Modify wrapEntity() to ensure that Character entities get the right wrapper. * rulesets/Py_Thing.cpp: Re-work getattr code so that properties and soft attributes are checked individually, rather than in a single call to Entity.get. Use new python property wrappers to wrap properties explicitly if required rather than converting to Atlas then to generic Python data. * rulesets/TerrainProperty.h: Fix incorrect class description in documentation. * rulesets/mason/world/tasks/Combat.py: Complete implementation of simple example combat. * server/TaskFactory.cpp: Remove debug output.
2005-12-30 18:02:40 +00:00
{
return (PyEntity *)PyCharacter_Type.tp_new(&PyCharacter_Type, 0, 0);
}
PyEntity * newPyMind()
{
return (PyEntity *)PyMind_Type.tp_new(&PyMind_Type, 0, 0);
}