Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

can

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.