Changeset 11974
- Timestamp:
- May 17, 2018, 4:04:14 PM (7 years ago)
- Location:
- code/branches/ScriptableController_FS18
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw
r11936 r11974 16 16 include("templates/spaceshipEscort.oxt") 17 17 include("templates/endurancetest_template.oxt") 18 include("templates/AAAAutonomousDroneTemplate.oxt") 18 19 ?> 19 20 … … 31 32 <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"/> 32 33 <SpawnPoint team=0 position="100,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort /> 34 <!-- <SpawnPoint team=2 position="0,0,0" lookat="0,0,0" spawnclass=AAAAutonomousDrone pawndesign=AAAAutonomousDroneTemplate /> --> 35 33 36 34 35 <AAAAutonomousDrone id="dummy" position="0,0,0">36 <attached>37 <Model scale="10" mesh="drone.mesh"/>38 </attached>39 <collisionShapes>40 <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />41 </collisionShapes>42 </AAAAutonomousDrone>43 37 44 38 -
code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua
r11936 r11974 60 60 61 61 62 function spawn_dummy() 63 orxPrint("Spawning dummy!") 64 spawnTest("dummy") 65 end 66 67 62 68 function kill_player_after_timeout(pawn) 63 69 orxPrint("Killing player after 5s") … … 86 92 87 93 94 function spawn_dummy_after_timeout(seconds) 95 orxPrint("Spawning dummy after " .. tostring(seconds)) 96 registerAfterTimeout(spawn_dummy, seconds) 97 end 88 98 89 99 90 move_dummy_after_timeout(5)91 kill_dummy_after_timeout(10)92 100 93 101 … … 96 104 97 105 98 spawn("ModularSpaceShip", "sepp") 99 setPosition("sepp", 500, 0, 0) 106 spawn_dummy_after_timeout(5) 107 108 -
code/branches/ScriptableController_FS18/data/levels/templates/AAAAutonomousDroneTemplate.oxt
r11928 r11974 1 <Template name=AAAAutonomousDroneTemplate> 2 <AAAAutonomousDrone> 3 <attached> 4 <Model scale="10" position="0,0,0" mesh="drone.mesh"/> 5 </attached> 6 <collisionShapes> 7 <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" /> 8 </collisionShapes> 9 </AAAAutonomousDrone> 10 </Template> -
code/branches/ScriptableController_FS18/src/orxonox/Level.cc
r11861 r11974 58 58 this->xmlfile_ = nullptr; 59 59 this->controller_.reset(new ScriptableController()); 60 this->controller_->level_ = this; 60 61 } 61 62 -
code/branches/ScriptableController_FS18/src/orxonox/Level.h
r11861 r11974 63 63 { return this->level_script_; } 64 64 65 void addObject(BaseObject* object); 65 66 66 67 private: 67 68 void registerVariables(); 68 void addObject(BaseObject* object);69 //void addObject(BaseObject* object); 69 70 BaseObject* getObject(unsigned int index) const; 70 71 -
code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc
r11861 r11974 133 133 Pawn *ScriptableController::getPawnByID(std::string id) const 134 134 { 135 if(id == "player" || id == "Player" || id == "PLAYER") 135 if(id == "player" || id == "Player" || id == "PLAYER") { 136 136 return orxonox_cast<Pawn*>(this->player_->getControllableEntity()); 137 orxout(user_status) << "Pawn is player!?" << std::endl; 138 } 139 137 140 138 141 auto pawn = this->pawns_.find(id); 142 143 if(pawn != this->pawns_.end()) { 144 orxout(user_status) << "Requested Pawn is available!" << std::endl; 145 } 146 139 147 return pawn != this->pawns_.end() ? pawn->second : nullptr; 140 148 } -
code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h
r11673 r11974 12 12 #include "worldentities/ControllableEntity.h" 13 13 #include "tools/Timer.h" 14 #include "Level.h" 14 15 15 16 struct lua_State; … … 31 32 { 32 33 public: 34 Level* level_ = nullptr; 33 35 /** 34 36 * @brief Run a lua script -
code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
r11936 r11974 37 37 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawn)>::registerFunction<&ScriptableControllerAPI::spawn>(this, lua, "spawn"); 38 38 39 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawnTest)>::registerFunction<&ScriptableControllerAPI::spawnTest>(this, lua, "spawnTest"); 40 39 41 40 42 … … 185 187 this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity)); 186 188 189 187 190 orxout(user_error) << "Third and final hit!" << std::endl; 188 } 191 192 } 193 194 195 196 197 198 void ScriptableControllerAPI::spawnTest(std::string id) 199 { 200 201 if(this->controller_->getWorldEntityByID(id) != nullptr) 202 { 203 orxout(user_warning) << "Script tried to spawn an object, but an object with the given ID exists already" << std::endl; 204 return; 205 } 206 207 208 Identifier *identifier = ClassByString("AAAAutonomousDrone"); 209 210 211 if(!identifier) 212 { 213 orxout(user_error) << "Script tried to spawn unknown object" << std::endl; 214 return; 215 } 216 217 if(!identifier->isLoadable()) 218 { 219 orxout(user_error) << "Script tried to spawn unloadable object" << std::endl; 220 return; 221 } 222 223 224 225 WorldEntity *entity; 226 Identifiable *obj = identifier->fabricate(this->controller_->getWorldEntityByID("Player")->getContext()); 227 228 orxout(user_status) << "First hit!" << std::endl; 229 230 if(obj->isA(ClassIdentifier<WorldEntity>::getIdentifier())) 231 { 232 orxout(user_status) << "Is WorldEntity!" << std::endl; 233 entity = orxonox_cast<WorldEntity*>(obj); 234 } 235 else if(obj->isA(ClassIdentifier<PlayerInfo>::getIdentifier())) 236 { 237 // TODO This does not work yet because somehow the controllable entity is not set 238 // yet at this stage. 239 // entity = orxonox_cast<PlayerInfo*>(obj)->getControllableEntity(); 240 241 orxout(user_status) << "Is PlayerInfo!" << std::endl; 242 243 //use TEMPLATES in the map to define objects that are not present on the map yet 244 return; 245 } 246 else 247 { 248 orxout(user_warning) << "Script tried to spawn an object that is neither a WorldEntity, nor a PlayerInfo" << std::endl; 249 250 return; 251 } 252 253 254 if(entity->isA(ClassIdentifier<MobileEntity>::getIdentifier())) { 255 orxout(user_status) << "Is MobileEntity!" << std::endl; 256 this->controller_->registerMobileEntity(id, orxonox_cast<MobileEntity*>(entity)); 257 } 258 259 if(entity->isA(ClassIdentifier<Pawn>::getIdentifier())) { 260 orxout(user_status) << "Is Pawn!" << std::endl; 261 this->controller_->registerPawn(id, orxonox_cast<Pawn*>(entity)); 262 } 263 264 this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity)); 265 266 if(this->controller_->getPawnByID(id) != nullptr) { 267 orxout(user_status) << "Pawn is indeed available!" << std::endl; 268 } 269 270 //for (Level* level : ObjectList<Level>()) 271 // level->loadedNewXMLName(this); 272 273 274 275 276 277 /////!!!!!!!!!!!!!!! 278 279 this->controller_->level_->addObject(orxonox_cast<Pawn*>(entity)); 280 281 282 283 284 orxout(user_status) << "Final hit!" << std::endl; 285 } 286 287 288 289 290 189 291 190 292 void ScriptableControllerAPI::setPosition(std::string id, double x, double y, double z) -
code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.h
r11902 r11974 152 152 void spawn(std::string type, std::string id); 153 153 154 void spawnTest(std::string id); 155 154 156 /** 155 157 * @brief Set the position of an object
Note: See TracChangeset
for help on using the changeset viewer.