Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11974


Ignore:
Timestamp:
May 17, 2018, 4:04:14 PM (6 years ago)
Author:
adamc
Message:

can

Location:
code/branches/ScriptableController_FS18
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_FS18/data/levels/AAAScriptableControllerTest.oxw

    r11936 r11974  
    1616  include("templates/spaceshipEscort.oxt")
    1717  include("templates/endurancetest_template.oxt")
     18  include("templates/AAAAutonomousDroneTemplate.oxt")
    1819?>
    1920
     
    3132    <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"/>
    3233    <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   
    3336
    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>
    4337   
    4438 
  • code/branches/ScriptableController_FS18/data/levels/scripts/AAAScriptableControllerTest.lua

    r11936 r11974  
    6060
    6161
     62function spawn_dummy()
     63        orxPrint("Spawning dummy!")
     64        spawnTest("dummy")
     65end
     66
     67
    6268function kill_player_after_timeout(pawn)
    6369        orxPrint("Killing player after 5s")
     
    8692
    8793
     94function spawn_dummy_after_timeout(seconds)
     95        orxPrint("Spawning dummy after " .. tostring(seconds))
     96        registerAfterTimeout(spawn_dummy, seconds)
     97end
    8898
    8999
    90 move_dummy_after_timeout(5)
    91 kill_dummy_after_timeout(10)
    92100
    93101
     
    96104
    97105
    98 spawn("ModularSpaceShip", "sepp")
    99 setPosition("sepp", 500, 0, 0)
     106spawn_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  
    5858        this->xmlfile_ = nullptr;
    5959        this->controller_.reset(new ScriptableController());
     60        this->controller_->level_ = this;
    6061    }
    6162
  • code/branches/ScriptableController_FS18/src/orxonox/Level.h

    r11861 r11974  
    6363                { return this->level_script_; }
    6464
     65            void addObject(BaseObject* object);
    6566
    6667        private:
    6768            void registerVariables();
    68             void addObject(BaseObject* object);
     69            //void addObject(BaseObject* object);
    6970            BaseObject* getObject(unsigned int index) const;
    7071
  • code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.cc

    r11861 r11974  
    133133Pawn *ScriptableController::getPawnByID(std::string id) const
    134134{
    135     if(id == "player" || id == "Player" || id == "PLAYER")
     135    if(id == "player" || id == "Player" || id == "PLAYER") {
    136136        return orxonox_cast<Pawn*>(this->player_->getControllableEntity());
     137        orxout(user_status) << "Pawn is player!?" << std::endl;
     138    }
     139
    137140
    138141    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
    139147    return pawn != this->pawns_.end() ? pawn->second : nullptr;
    140148}
  • code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller.h

    r11673 r11974  
    1212#include "worldentities/ControllableEntity.h"
    1313#include "tools/Timer.h"
     14#include "Level.h"
    1415
    1516struct lua_State;
     
    3132{
    3233public:
     34    Level* level_ = nullptr;
    3335    /**
    3436     * @brief Run a lua script
  • code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller/scriptable_controller_api.cc

    r11936 r11974  
    3737        LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawn)>::registerFunction<&ScriptableControllerAPI::spawn>(this, lua, "spawn");
    3838
     39        LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawnTest)>::registerFunction<&ScriptableControllerAPI::spawnTest>(this, lua, "spawnTest");
     40
    3941
    4042
     
    185187        this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity));
    186188
     189
    187190        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
    189291
    190292    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  
    152152    void spawn(std::string type, std::string id);
    153153
     154    void spawnTest(std::string id);
     155
    154156    /**
    155157     * @brief Set the position of an object
Note: See TracChangeset for help on using the changeset viewer.