[Orxonox-commit 7241] r11855 - in code/branches/ScriptableController_FS18: . data/levels src/libraries/core src/libraries/tools src/orxonox src/orxonox/infos src/orxonox/items src/orxonox/worldentities src/orxonox/worldentities/pawns

adamc at orxonox.net adamc at orxonox.net
Thu Apr 12 14:07:04 CEST 2018


Author: adamc
Date: 2018-04-12 14:07:03 +0200 (Thu, 12 Apr 2018)
New Revision: 11855

Added:
   code/branches/ScriptableController_FS18/data/levels/scriptableControllerTest.oxw
   code/branches/ScriptableController_FS18/data/levels/scripts/
   code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/
Modified:
   code/branches/ScriptableController_FS18/
   code/branches/ScriptableController_FS18/src/libraries/core/BaseObject.h
   code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc
   code/branches/ScriptableController_FS18/src/libraries/tools/Timer.h
   code/branches/ScriptableController_FS18/src/orxonox/CMakeLists.txt
   code/branches/ScriptableController_FS18/src/orxonox/Level.cc
   code/branches/ScriptableController_FS18/src/orxonox/Level.h
   code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.cc
   code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.h
   code/branches/ScriptableController_FS18/src/orxonox/infos/HumanPlayer.cc
   code/branches/ScriptableController_FS18/src/orxonox/items/ShipPart.cc
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.cc
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.h
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/MobileEntity.cc
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.cc
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.h
   code/branches/ScriptableController_FS18/src/orxonox/worldentities/pawns/Pawn.cc
Log:
merged HS17 into FS18

Index: code/branches/ScriptableController_FS18
===================================================================
--- code/branches/ScriptableController_FS18	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18	2018-04-12 12:07:03 UTC (rev 11855)

Property changes on: code/branches/ScriptableController_FS18
___________________________________________________________________
Modified: svn:mergeinfo
## -16,6 +16,7 ##
 /code/branches/SOBv2_HS17:11459-11765
 /code/branches/SciptableControllerFS15:10308-10613
 /code/branches/ScriptableController:9999-10075
+/code/branches/ScriptableController_HS17:11462-11854
 /code/branches/SpaceRace_HS16:11214-11357
 /code/branches/StoryModeMap_HS16:11221-11358
 /code/branches/SuperOrxoBros_FS17:11365-11448
Copied: code/branches/ScriptableController_FS18/data/levels/scriptableControllerTest.oxw (from rev 11854, code/branches/ScriptableController_HS17/data/levels/scriptableControllerTest.oxw)
===================================================================
--- code/branches/ScriptableController_FS18/data/levels/scriptableControllerTest.oxw	                        (rev 0)
+++ code/branches/ScriptableController_FS18/data/levels/scriptableControllerTest.oxw	2018-04-12 12:07:03 UTC (rev 11855)
@@ -0,0 +1,42 @@
+<LevelInfo
+ name = "scriptableControllerTest"
+ description = "A level with absolutely nothing in it."
+ tags = "test"
+ screenshot = "emptylevel.png"
+/>
+
+<?lua
+  include("stats.oxo")
+  include("HUDTemplates3.oxo")
+  include("templates/lodInformation.oxt")
+  include("templates/HeavyCruiser.oxt")
+?>
+
+<?lua
+  include("templates/spaceshipEscort.oxt")
+  include("templates/endurancetest_template.oxt")
+?>
+
+<Level script="scripts/scriptableControllerTest.lua">
+  <templates>
+    <Template link=lodtemplate_default />
+  </templates>
+  <?lua include("includes/notifications.oxi") ?>
+
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
+    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
+
+    <ModularSpaceShip id="Station" velocity= "0,0,0" position="50000000,0,0" lookat= "0,0,0" health="500" maxhealth="500" initialhealth="500">
+      <templates>
+        <Template link=endurance />
+      </templates>
+    </ModularSpaceShip>
+    
+  </Scene>
+</Level>
+

Modified: code/branches/ScriptableController_FS18/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/ScriptableController_FS18/src/libraries/core/BaseObject.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/libraries/core/BaseObject.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -57,6 +57,7 @@
     class Scene;
     class Gametype;
     class Level;
+    class ScriptableController;
 
     /// The BaseObject is the parent of all classes representing an instance in the game.
     class _CoreExport BaseObject : public OrxonoxClass
@@ -191,6 +192,7 @@
 
             static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
 
+
         protected:
             void addEventState(const std::string& name, EventState* container);
             EventState* getEventState(const std::string& name) const;

Modified: code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -157,6 +157,14 @@
         this->setTimer(interval, bLoop, executor, bKillAfterCall);
     }
 
+    Timer::Timer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
+    {
+        this->init();
+        RegisterObject(Timer);
+
+        this->setTimer(interval, bLoop, func, bKillAfterCall);
+    }
+
     /**
         @brief Initializes the Timer
     */
@@ -192,13 +200,24 @@
         this->bLoop_ = bLoop;
         this->executor_ = executor;
         this->bActive_ = true;
+        this->isStdFunction_ = false;
 
         this->time_ = this->interval_;
         this->bKillAfterCall_ = bKillAfterCall;
 
-        executor->getFunctor()->setSafeMode(true);
+        if(executor != nullptr)
+            executor->getFunctor()->setSafeMode(true);
     }
 
+    void Timer::setTimer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
+    {
+        // Without the cast, the call would be ambiguous, because nullptr is castable to
+        // both, ExecutorPtr and std::function.
+        this->setTimer(interval, bLoop, static_cast<ExecutorPtr>(nullptr), bKillAfterCall);
+        this->function_ = func;
+        this->isStdFunction_ = true;
+    }
+
     /**
         @brief Calls the executor and destroys the timer if requested.
     */
@@ -206,7 +225,10 @@
     {
         bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer
 
-        (*this->executor_)();
+        if(this->isStdFunction_)
+            this->function_();
+        else
+            (*this->executor_)();
 
         if (temp)
             delete this;

Modified: code/branches/ScriptableController_FS18/src/libraries/tools/Timer.h
===================================================================
--- code/branches/ScriptableController_FS18/src/libraries/tools/Timer.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/libraries/tools/Timer.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -107,8 +107,10 @@
             Timer();
 
             Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
+            Timer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
 
             void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
+            void setTimer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
 
             void run();
 
@@ -152,7 +154,9 @@
             void init();
 
             ExecutorPtr executor_;  //!< The executor of the function that will be called when the time expires
+            std::function<void (void)> function_;
 
+            bool isStdFunction_;
             long long interval_;    //!< The time-interval in micro seconds
             bool bLoop_;            //!< If true, the executor gets called every @a interval seconds
             bool bActive_;          //!< If true, the timer ticks and calls the executor if the time's up

Modified: code/branches/ScriptableController_FS18/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/CMakeLists.txt	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/CMakeLists.txt	2018-04-12 12:07:03 UTC (rev 11855)
@@ -50,6 +50,7 @@
 ADD_SUBDIRECTORY(interfaces)
 ADD_SUBDIRECTORY(items)
 ADD_SUBDIRECTORY(overlays)
+ADD_SUBDIRECTORY(scriptablecontroller)
 ADD_SUBDIRECTORY(sound)
 ADD_SUBDIRECTORY(weaponsystem)
 ADD_SUBDIRECTORY(worldentities)

Modified: code/branches/ScriptableController_FS18/src/orxonox/Level.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/Level.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/Level.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -41,6 +41,7 @@
 #include "gametypes/Gametype.h"
 #include "overlays/OverlayGroup.h"
 #include "LevelManager.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
 {
@@ -55,6 +56,7 @@
         this->registerVariables();
         this->xmlfilename_ = this->getFilename();
         this->xmlfile_ = nullptr;
+        this->controller_.reset(new ScriptableController());
     }
 
     Level::~Level()
@@ -78,6 +80,8 @@
         XMLPortParam(Level, "plugins",  setPluginsString,  getPluginsString,  xmlelement, mode);
         XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
 
+        XMLPortParamLoadOnly(Level, "script", setScript, xmlelement, mode);
+
         XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode);
         XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
     }

Modified: code/branches/ScriptableController_FS18/src/orxonox/Level.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/Level.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/Level.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -41,6 +41,8 @@
 
 namespace orxonox
 {
+    class ScriptableController;
+
     class _OrxonoxExport Level : public BaseObject, public Synchronisable, public Context
     {
         public:
@@ -54,7 +56,13 @@
 
             MeshLodInformation* getLodInfo(std::string meshName) const;
 
+            inline ScriptableController *getScriptableController(void)
+                { return this->controller_.get(); }
 
+            inline const std::string &getScript(void)
+                { return this->level_script_; }
+
+
         private:
             void registerVariables();
             void addObject(BaseObject* object);
@@ -77,14 +85,20 @@
 
             void networkcallback_applyXMLFile();
 
+            inline void setScript(const std::string &script)
+                { this->level_script_ = script; }
+
+
             std::string                    pluginsString_;
             std::list<PluginReference*>    plugins_;
-
             std::string                    gametype_;
             std::string                    xmlfilename_;
             XMLFile*                       xmlfile_;
             std::list<BaseObject*>         objects_;
             std::map<std::string,MeshLodInformation*>  lodInformation_;
+
+            std::unique_ptr<ScriptableController> controller_;
+            std::string           level_script_;
     };
 }
 

Modified: code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -42,6 +42,8 @@
 #include "controllers/HumanController.h"
 #include "interfaces/GametypeMessageListener.h"
 #include "interfaces/NotificationListener.h"
+#include "scriptablecontroller/scriptable_controller.h"
+#include "Level.h"
 
 #include "PlayerInfo.h"
 
@@ -75,6 +77,7 @@
         this->counter_ = 10;
         this->spawned_ = false;
         this->readyToSpawn_ = false;
+        this->isFirstSpawn_ = true;
 
         this->registerVariables();
     }
@@ -309,9 +312,21 @@
         if(GameMode::isMaster())
         {
             if(this->hasStarted() && !this->hasEnded())
-
                 this->setSpawnedHelper(player, true);
         }
+
+        // TODO We might want to handle the subsequent spawns as well somehow
+        if(player->isHumanPlayer() && player->isLocalPlayer() && this->isFirstSpawn_)
+        {
+            this->isFirstSpawn_ = false;
+            this->getLevel()->getScriptableController()->setPlayer(player);
+
+            // This handles paths relative to the 'level' directory
+            std::string script = this->getLevel()->getScript();
+            if(script.at(0) != '/')
+                script = "../levels/" + script; // Not very dynamic
+            this->getLevel()->getScriptableController()->runScript(script);
+        }
     }
 
     /**

Modified: code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/infos/GametypeInfo.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -82,6 +82,7 @@
             */
             inline bool isStartCountdownRunning() const
                 { return this->bStartCountdownRunning_; }
+
             void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
 
             /**
@@ -165,6 +166,7 @@
             std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned.
             bool spawned_; //!< Whether the local Player is currently spawned.
             bool readyToSpawn_; //!< Whether the local Player is ready to spawn.
+            bool isFirstSpawn_;
     };
 }
 

Modified: code/branches/ScriptableController_FS18/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/infos/HumanPlayer.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/infos/HumanPlayer.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -37,6 +37,8 @@
 #include "controllers/NewHumanController.h"
 #include "gametypes/Gametype.h"
 #include "overlays/OverlayGroup.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
 {

Modified: code/branches/ScriptableController_FS18/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/items/ShipPart.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/items/ShipPart.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -41,6 +41,8 @@
 #include "worldentities/StaticEntity.h"
 #include "items/PartDestructionEvent.h"
 #include "chat/ChatManager.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 
 namespace orxonox
@@ -214,6 +216,11 @@
                 parent_->setHealth(parent_->getHealth() - ((damage - shielddamage) - healthdamage) * (1- this->damageAbsorption_));
             }
         }
+
+        // This is a bit hacky, but it takes away damage control from the pawn, so it has to handle
+        // that as well.
+        this->getLevel()->getScriptableController()->pawnHit(parent_, originator, parent_->getHealth(), parent_->getShieldHealth());
+
         if (this->health_ < 0)
             this->death();
 

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -38,6 +38,7 @@
 #include "network/NetworkFunctionIncludes.h"
 
 #include "Scene.h"
+#include "Level.h"
 #include "infos/PlayerInfo.h"
 #include "controllers/NewHumanController.h"
 #include "graphics/Camera.h"
@@ -66,7 +67,6 @@
         this->hud_ = nullptr;
         this->camera_ = nullptr;
         this->xmlcontroller_ = nullptr;
-        //this->controller_ = nullptr;
         this->reverseCamera_ = nullptr;
         this->bDestroyWhenPlayerLeft_ = false;
         this->cameraPositionRootNode_ = this->node_->createChildSceneNode();

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/ControllableEntity.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -175,6 +175,7 @@
             inline int getTeam() const
                 { return this->team_; }
 
+
         protected:
             virtual void preDestroy() override;
 

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/MobileEntity.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/MobileEntity.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/MobileEntity.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -35,6 +35,8 @@
 #include "core/XMLPort.h"
 
 #include "Scene.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
 {
@@ -71,6 +73,9 @@
             else
                 this->setAngularVelocity(rotationAxis.normalisedCopy() * rotationRate.valueRadians());
         }
+
+        if(!this->id_.empty() && this->getLevel() != nullptr)
+            this->getLevel()->getScriptableController()->registerMobileEntity(this->id_, this);
     }
 
     void MobileEntity::tick(float dt)

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -43,7 +43,9 @@
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 #include "Scene.h"
+#include "Level.h"
 #include "collisionshapes/WorldEntityCollisionShape.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
 {
@@ -78,6 +80,7 @@
         this->parent_ = nullptr;
         this->parentID_ = OBJECTID_UNKNOWN;
         this->bDeleteWithParent_ = true;
+        this->id_ = -1;
 
         this->node_->setPosition(Vector3::ZERO);
         this->node_->setOrientation(Quaternion::IDENTITY);
@@ -159,6 +162,7 @@
         XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
         XMLPortParamTemplate(WorldEntity, "scale3D",     setScale3D,     getScale3D,     xmlelement, mode, const Vector3&);
         XMLPortParam        (WorldEntity, "scale",       setScale,       getScale,       xmlelement, mode);
+        XMLPortParamLoadOnly(WorldEntity, "id",          setID,                xmlelement, mode);
         XMLPortParamLoadOnly(WorldEntity, "lookat",      lookAt_xmlport,       xmlelement, mode);
         XMLPortParamLoadOnly(WorldEntity, "direction",   setDirection_xmlport, xmlelement, mode);
         XMLPortParamLoadOnly(WorldEntity, "yaw",         yaw_xmlport,          xmlelement, mode);
@@ -180,6 +184,9 @@
         XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode);
         // Attached collision shapes
         XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
+
+        if(!this->id_.empty() && this->getLevel() != nullptr)
+            this->getLevel()->getScriptableController()->registerWorldEntity(this->id_, this);
     }
 
     void WorldEntity::registerVariables()

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.h	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/WorldEntity.h	2018-04-12 12:07:03 UTC (rev 11855)
@@ -110,6 +110,12 @@
             virtual void changedActivity(void) override;
             virtual void changedVisibility(void) override;
 
+            inline std::string getID(void)
+                { return this->id_; }
+
+            inline void setID(std::string id)
+                { this->id_ = id; }
+
             virtual void setPosition(const Vector3& position) = 0;
             inline void setPosition(float x, float y, float z)
                 { this->setPosition(Vector3(x, y, z)); }
@@ -441,6 +447,7 @@
             virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
 
             btRigidBody*  physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance.
+            std::string   id_;           //!< Used by the ScriptableController to identify objects
 
         private:
             void recalculateMassProps();

Modified: code/branches/ScriptableController_FS18/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/worldentities/pawns/Pawn.cc	2018-04-12 11:40:36 UTC (rev 11854)
+++ code/branches/ScriptableController_FS18/src/orxonox/worldentities/pawns/Pawn.cc	2018-04-12 12:07:03 UTC (rev 11855)
@@ -49,6 +49,8 @@
 #include "weaponsystem/Munition.h"
 #include "sound/WorldSound.h"
 #include "core/object/ObjectListIterator.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 #include "controllers/FormationController.h"
 
@@ -159,6 +161,9 @@
         XMLPortParam(Pawn, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
 
         XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
+
+        if(!this->id_.empty() && this->getLevel() != nullptr)
+            this->getLevel()->getScriptableController()->registerPawn(this->id_, this);
     }
 
     void Pawn::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
@@ -281,7 +286,7 @@
         if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
         {
             // Health-damage cannot be absorbed by shields.
-            // Shield-damage only reduces shield health. 
+            // Shield-damage only reduces shield health.
             // Normal damage can be (partially) absorbed by shields.
 
             if (shielddamage >= this->getShieldHealth())
@@ -301,6 +306,7 @@
                 // set remaining damage to health
                 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
             }
+            this->getLevel()->getScriptableController()->pawnHit(this, originator, this->health_, this->shieldHealth_);
 
             this->lastHitOriginator_ = originator;
         }
@@ -401,6 +407,8 @@
                 this->goWithStyle();
             }
         }
+
+        this->getLevel()->getScriptableController()->pawnKilled(this);
     }
     void Pawn::goWithStyle()
     {
@@ -624,7 +632,7 @@
         else
         {
             // delete all debug models
-            for(Model* model : debugWeaponSlotModels_) 
+            for(Model* model : debugWeaponSlotModels_)
             {
                 model->destroy();
             }
@@ -649,4 +657,4 @@
             it->drawWeapons(bDraw);
         }
     }
-}
\ No newline at end of file
+}



More information about the Orxonox-commit mailing list