Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

can

Location:
code/branches/ScriptableController_FS18/src/orxonox/scriptablecontroller
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.