[Orxonox-commit 7357] r11974 - in code/branches/ScriptableController_FS18: data/levels data/levels/scripts data/levels/templates src/orxonox src/orxonox/scriptablecontroller

adamc at orxonox.net adamc at orxonox.net
Thu May 17 16:04:14 CEST 2018


Author: adamc
Date: 2018-05-17 16:04:14 +0200 (Thu, 17 May 2018)
New Revision: 11974

Modified:
   code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw
   code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua
   code/branches/ScriptableController_FS18/data/levels/templates/AAAAutonomousDroneTemplate.oxt
   code/branches/ScriptableController_FS18/src/orxonox/Level.cc
   code/branches/ScriptableController_FS18/src/orxonox/Level.h
   code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc
   code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h
   code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
   code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.h
Log:
can

Modified: code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw
===================================================================
--- code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw	2018-05-17 14:04:14 UTC (rev 11974)
@@ -15,6 +15,7 @@
 <?lua
   include("templates/spaceshipEscort.oxt")
   include("templates/endurancetest_template.oxt")
+  include("templates/AAAAutonomousDroneTemplate.oxt")
 ?>
 
 <Level script="scripts/AAAScriptableControllerTest.lua">
@@ -30,16 +31,9 @@
 
     <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="100,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
+    <!-- <SpawnPoint team=2 position="0,0,0" lookat="0,0,0" spawnclass=AAAAutonomousDrone pawndesign=AAAAutonomousDroneTemplate />  -->
+    
 
-
-  <AAAAutonomousDrone id="dummy" position="0,0,0">
-    <attached>
-      <Model scale="10" mesh="drone.mesh"/>
-    </attached>
-    <collisionShapes>
-      <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />
-    </collisionShapes>
-  </AAAAutonomousDrone>
     
   
 

Modified: code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua
===================================================================
--- code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua	2018-05-17 14:04:14 UTC (rev 11974)
@@ -59,6 +59,12 @@
 end
 
 
+function spawn_dummy()
+	orxPrint("Spawning dummy!")
+	spawnTest("dummy")
+end
+
+
 function kill_player_after_timeout(pawn)
 	orxPrint("Killing player after 5s")
 
@@ -85,10 +91,12 @@
 end
 
 
+function spawn_dummy_after_timeout(seconds)
+	orxPrint("Spawning dummy after " .. tostring(seconds))
+	registerAfterTimeout(spawn_dummy, seconds)
+end
 
 
-move_dummy_after_timeout(5)
-kill_dummy_after_timeout(10)
 
 
 orxPrint("Script started! OMG ROFL LOL WTF")
@@ -95,5 +103,6 @@
 mytestfunction(3.0, 4.0)
 
 
-spawn("ModularSpaceShip", "sepp")
-setPosition("sepp", 500, 0, 0)
+spawn_dummy_after_timeout(5)
+
+

Modified: code/branches/ScriptableController_FS18/data/levels/templates/AAAAutonomousDroneTemplate.oxt
===================================================================
--- code/branches/ScriptableController_FS18/data/levels/templates/AAAAutonomousDroneTemplate.oxt	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/data/levels/templates/AAAAutonomousDroneTemplate.oxt	2018-05-17 14:04:14 UTC (rev 11974)
@@ -0,0 +1,10 @@
+<Template name=AAAAutonomousDroneTemplate>
+  <AAAAutonomousDrone>
+    <attached>
+      <Model scale="10" position="0,0,0" mesh="drone.mesh"/>
+    </attached>
+    <collisionShapes>
+      <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />
+    </collisionShapes>
+  </AAAAutonomousDrone>
+</Template>
\ No newline at end of file

Modified: code/branches/ScriptableController_FS18/src/orxonox/Level.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/Level.cc	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/Level.cc	2018-05-17 14:04:14 UTC (rev 11974)
@@ -57,6 +57,7 @@
         this->xmlfilename_ = this->getFilename();
         this->xmlfile_ = nullptr;
         this->controller_.reset(new ScriptableController());
+        this->controller_->level_ = this;
     }
 
     Level::~Level()

Modified: code/branches/ScriptableController_FS18/src/orxonox/Level.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/Level.h	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/Level.h	2018-05-17 14:04:14 UTC (rev 11974)
@@ -62,10 +62,11 @@
             inline const std::string &getScript(void)
                 { return this->level_script_; }
 
+            void addObject(BaseObject* object);
 
         private:
             void registerVariables();
-            void addObject(BaseObject* object);
+            //void addObject(BaseObject* object);
             BaseObject* getObject(unsigned int index) const;
 
             void addLodInfo(MeshLodInformation* object);

Modified: code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc	2018-05-17 14:04:14 UTC (rev 11974)
@@ -132,10 +132,18 @@
 
 Pawn *ScriptableController::getPawnByID(std::string id) const
 {
-    if(id == "player" || id == "Player" || id == "PLAYER")
+    if(id == "player" || id == "Player" || id == "PLAYER") {
         return orxonox_cast<Pawn*>(this->player_->getControllableEntity());
+        orxout(user_status) << "Pawn is player!?" << std::endl;
+    }
 
+
     auto pawn = this->pawns_.find(id);
+
+    if(pawn != this->pawns_.end()) {
+        orxout(user_status) << "Requested Pawn is available!" << std::endl;
+    }
+
     return pawn != this->pawns_.end() ? pawn->second : nullptr;
 }
 

Modified: code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h	2018-05-17 14:04:14 UTC (rev 11974)
@@ -11,6 +11,7 @@
 #include "worldentities/WorldEntity.h"
 #include "worldentities/ControllableEntity.h"
 #include "tools/Timer.h"
+#include "Level.h"
 
 struct lua_State;
 
@@ -30,6 +31,7 @@
 class ScriptableController
 {
 public:
+    Level* level_ = nullptr;
     /**
      * @brief Run a lua script
      * @param file_path Path to the script

Modified: code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	2018-05-17 14:04:14 UTC (rev 11974)
@@ -36,8 +36,10 @@
         LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::killPawn)>::registerFunction<&ScriptableControllerAPI::killPawn>(this, lua, "killPawn");
         LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawn)>::registerFunction<&ScriptableControllerAPI::spawn>(this, lua, "spawn");
 
+        LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawnTest)>::registerFunction<&ScriptableControllerAPI::spawnTest>(this, lua, "spawnTest");
 
 
+
         LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::myTestFunction)>::registerFunction<&ScriptableControllerAPI::myTestFunction>(this, lua, "mytestfunction");
         LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::moveControllableEntity)>::registerFunction<&ScriptableControllerAPI::moveControllableEntity>(this, lua, "moveControllableEntity");
 
@@ -184,9 +186,109 @@
 
         this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity));
 
+
         orxout(user_error) << "Third and final hit!" << std::endl;
+
     }
 
+
+
+
+
+    void ScriptableControllerAPI::spawnTest(std::string id)
+    {
+        
+        if(this->controller_->getWorldEntityByID(id) != nullptr)
+        {
+            orxout(user_warning) << "Script tried to spawn an object, but an object with the given ID exists already" << std::endl;
+            return;
+        }
+        
+
+        Identifier *identifier = ClassByString("AAAAutonomousDrone");
+        
+        
+        if(!identifier)
+        {
+            orxout(user_error) << "Script tried to spawn unknown object" << std::endl;
+            return;
+        }
+
+        if(!identifier->isLoadable())
+        {
+            orxout(user_error) << "Script tried to spawn unloadable object" << std::endl;
+            return;
+        }
+
+        
+
+        WorldEntity *entity;
+        Identifiable *obj = identifier->fabricate(this->controller_->getWorldEntityByID("Player")->getContext());
+
+        orxout(user_status) << "First hit!" << std::endl;
+
+        if(obj->isA(ClassIdentifier<WorldEntity>::getIdentifier()))
+        {
+            orxout(user_status) << "Is WorldEntity!" << std::endl;
+            entity = orxonox_cast<WorldEntity*>(obj);
+        }
+        else if(obj->isA(ClassIdentifier<PlayerInfo>::getIdentifier()))
+        {
+            // TODO This does not work yet because somehow the controllable entity is not set
+            // yet at this stage.
+    //        entity = orxonox_cast<PlayerInfo*>(obj)->getControllableEntity();
+
+            orxout(user_status) << "Is PlayerInfo!" << std::endl;
+
+            //use TEMPLATES in the map to define objects that are not present on the map yet
+            return;
+        }
+        else
+        {
+            orxout(user_warning) << "Script tried to spawn an object that is neither a WorldEntity, nor a PlayerInfo" << std::endl;
+            
+            return;
+        }
+
+
+        if(entity->isA(ClassIdentifier<MobileEntity>::getIdentifier())) {
+            orxout(user_status) << "Is MobileEntity!" << std::endl;
+            this->controller_->registerMobileEntity(id, orxonox_cast<MobileEntity*>(entity));
+        }
+
+        if(entity->isA(ClassIdentifier<Pawn>::getIdentifier())) {
+            orxout(user_status) << "Is Pawn!" << std::endl;
+            this->controller_->registerPawn(id, orxonox_cast<Pawn*>(entity));
+        }
+
+        this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity));
+
+        if(this->controller_->getPawnByID(id) != nullptr) {
+            orxout(user_status) << "Pawn is indeed available!" << std::endl;
+        }
+
+        //for (Level* level : ObjectList<Level>())
+        //    level->loadedNewXMLName(this);
+
+
+
+
+
+        /////!!!!!!!!!!!!!!!
+
+        this->controller_->level_->addObject(orxonox_cast<Pawn*>(entity));
+
+
+
+
+        orxout(user_status) << "Final hit!" << std::endl;
+    }
+
+
+
+
+
+
     void ScriptableControllerAPI::setPosition(std::string id, double x, double y, double z)
     {
         WorldEntity *entity = this->controller_->getWorldEntityByID(id);

Modified: code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.h
===================================================================
--- code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.h	2018-05-17 14:03:22 UTC (rev 11973)
+++ code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.h	2018-05-17 14:04:14 UTC (rev 11974)
@@ -151,6 +151,8 @@
      */
     void spawn(std::string type, std::string id);
 
+    void spawnTest(std::string id);
+
     /**
      * @brief Set the position of an object
      * @param id The ID of the object



More information about the Orxonox-commit mailing list