- Timestamp:
- May 7, 2014, 2:03:18 PM (11 years ago)
- Location:
- code/branches/ScriptableController/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
r10035 r10046 1 1 /* 2 First try of a ControllerDirector. Target: An event occurs in the levelTry.oxw file, which is "heard" by an object of the type of this class. It then SHOULD (because it is not working) execute the party function. 2 * First try of a ControllerDirector. Target: An event occurs in the levelTry.oxw 3 * file, which is "heard" by an object of the type of this class. It then SHOULD 4 * (because it is not working) execute the party function. 3 5 */ 4 6 … … 20 22 ControllerDirector::ControllerDirector(Context* context) : ArtificialController(context) 21 23 { 22 //Working 24 // Register the object with the framework 23 25 RegisterObject(ControllerDirector); 26 27 // output a message to ensure we know the constructor was run 24 28 orxout()<<"hello universe constructor"<< endl; 25 29 26 this->player_=NULL; 27 this->entity_=NULL; 28 this->pTrigger_=NULL; 30 // Initialize member variables 31 this->player_ = NULL; 32 this->entity_ = NULL; 33 this->pTrigger_ = NULL; 29 34 } 30 31 35 32 36 void ControllerDirector::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 34 38 SUPER(ControllerDirector, XMLPort, xmlelement, mode); 35 39 36 37 orxout()<<"ControllerDriector::XMLPort An instance of ControllerDirector has been created."<< endl;40 orxout()<< "ControllerDirector::XMLPort " 41 << "An instance of ControllerDirector has been created." << endl; 38 42 } 39 43 40 44 void ControllerDirector::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 41 45 { 46 // Call the xmleventport functions of the classes we derive from 42 47 SUPER(ControllerDirector, XMLEventPort, xmlelement, mode); 43 48 44 XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", takeControl, xmlelement, mode); 45 49 // Add an event sink for a "takeControl" event, which leads to the 50 // function takeControl() being called. 51 XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", 52 takeControl, xmlelement, mode); 46 53 } 47 54 … … 49 56 50 57 51 void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) { 58 void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) 59 { 60 /* Output a message confirming that the function was called */ 61 orxout()<<"test takecontrol."<< endl; 52 62 63 /* First, we set up a new controller to attach to the unit that 64 * triggered our event. 65 */ 66 static int ctrlid = 0; 53 67 // preparationTo(trigger); 54 68 // setNewController(controller); 55 LuaState * test = new LuaState(); 56 orxout()<<"test takecontrol."<< endl; 57 test->doFile("testscript.lua"); 58 69 70 /* Set up a luastate to use for running the scripts */ 71 LuaState * ls = new LuaState(); 72 73 /* Assemble a string to define a controller id variable in lua space */ 74 std::stringstream tmp; 75 tmp << "newctrlid = " << ctrlid; 76 std::string todo = tmp.str(); 77 78 /* Run the string using the luastate created earlier */ 79 ls->doString(todo); 80 81 /* Now run the script on this controller. This will still have the above 82 * variable "newctrlid" defined, which means it can make use of it. 83 */ 84 ls->doFile("testscript.lua"); 85 86 /* Increase the controller ID so we have a different one for 87 * the next time it is triggered */ 88 ctrlid += 1; 59 89 } 60 90 -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
r10045 r10046 67 67 ScriptController* ScriptController::getScriptController() 68 68 { 69 /* Output a message that confirms this function was called */ 69 70 orxout() << "Great success!" << std::endl; 71 72 /* Loop over all the scriptcontrollers currently present in the game */ 70 73 for(ObjectList<ScriptController>::iterator it = 71 74 ObjectList<ScriptController>::begin(); … … 83 86 void ScriptController::moveToPosition_beta(float x, float y, float z ) 84 87 { 88 /* The section commented out here below throws segfaults */ 89 //const Vector3 local=getPosition(); 90 //const Vector3 target=Vector3(x,y,z); 91 //Vector3 way=target-local; 92 93 94 //this->controlled->lookAt(target); 95 //this->controlled->moveFrontBack(way.length()); 85 96 86 const Vector3 local=getPosition(); 87 const Vector3 target=Vector3(x,y,z); 88 89 Vector3 way=target-local; 90 91 92 this->controlled->lookAt(target); 93 94 this->controlled->moveFrontBack(way.length()); 95 96 97 /*orxout()<<x<<" "<<y<<" "<<z<<endl;*/ 98 99 100 101 97 98 /* This works fine */ 99 orxout()<<x<<" "<<y<<" "<<z<<endl; 102 100 } 103 101 -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
r10045 r10046 50 50 51 51 void set_luasrc(std::string); 52 53 52 void set_controlled(ControllableEntity*); 54 53
Note: See TracChangeset
for help on using the changeset viewer.