Changeset 10016
- Timestamp:
- Apr 3, 2014, 2:19:49 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
r10012 r10016 1 #include "ControllerDirector.h" 1 /* 2 First try of a scriptController. 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. 3 */ 4 5 #include "ScriptController.h" 2 6 #include "core/CoreIncludes.h" 3 #include "core/XMLPort.h" 4 #include "worldentities/ControllableEntity.h" 7 8 namespace orxonox 9 { 10 RegisterClass(ScriptController); 11 12 ScriptController::ScriptController(Context* context) : ArtificialController(context) 13 { 14 //Working 15 RegisterObject(ScriptController); 16 orxout()<<"hello universe constructor"<< endl; 17 18 this->player_=NULL; 19 this->entity_=NULL; 20 this->pTrigger_=NULL; 21 } 22 23 bool ScriptController::party(bool bTriggered, BaseObject* trigger) 24 { 25 //XMLPortEventSink seems not to execute the party function 26 orxout()<<"hello universe party"<< endl; 27 return true; 28 } 29 30 31 void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 32 { 33 SUPER(ScriptController, XMLPort, xmlelement, mode); 34 35 36 XMLPortEventSink(ScriptController, BaseObject, "party", party, xmlelement, mode); 37 // Working 38 orxout()<<"hello universe xmlport"<< endl; 39 } 40 41 void ScriptController::tick(float dt) 42 { 43 44 //Get controllable entity which is attached to this controller in the XML file. 45 ControllableEntity* entity = this->getControllableEntity(); 46 if (!entity) 47 orxout()<<"No controllable entity found"<<endl; 48 return; 49 50 51 52 SUPER(ScriptController, tick, dt); 53 } 54 55 void ScriptController::takeControl(Controller * controller, BaseObject * trigger) { 56 57 preparationToTakeControl(trigger); 58 setNewController(controller); 59 60 } 61 62 63 bool ScriptController::preparationToTakeControl(BaseObject * trigger) { 64 65 this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger); 66 this->player_ = NULL; 67 68 // Check whether it is a player trigger and extract pawn from it 69 if(pTrigger != NULL) 70 { 71 if(!pTrigger->isForPlayer()) { // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 72 orxout(verbose, context::docking) << "Docking:execute PlayerTrigger was not triggered by a player.." << endl; 73 return false; 74 } 75 player_ = pTrigger->getTriggeringPlayer(); //Get the object which triggered the event. 76 } 77 else 78 { 79 orxout(verbose, context::docking) << "Docking::execute Not a player trigger, can't extract pawn from it.." << endl; 80 return false; 81 } 82 83 84 this->entity_ = this->player_->getControllableEntity(); 85 assert(this->entity_); 86 87 } 88 89 void ScriptController::setNewController(Controller * controller) { 90 91 92 orxout(verbose) << "New Controller is going to be set!" << endl; 93 94 this->entity_->setDestroyWhenPlayerLeft(false); 95 this->player_->pauseControl(); 96 this->entity_->setController(controller); 97 this->setControllableEntity(this->entity_); 98 99 100 101 } 102 103 104 105 106 /* Detaillierte Planung 107 Director nimmt event auf und hängt dann einen controller (momentan als erstellt zu betrachten) an objekt, welches event ausgelöst hat. 5 108 6 109 7 110 111 Klassenvariablen 8 112 9 namespace orxonox 10 { 113 ...? brauchts überhaupt? 114 115 Variablen (in Funktionen auftretend): 116 117 Playerinfo * player enthält infos über objekt, welches event ausgelöst hat.Relevant für Inputseite des Directors 118 119 Funktion: 120 121 Auf Seite des Inputs des Directors: 122 123 preparationForControlTakeOver(...) Vorbereitende Massnahmen um neuen Controller anzuhängen, z.B. player = pTrigger->getTriggeringPlayer(); 124 Orientierung an execute Funktion von Dock.cc 125 126 Auf Outputseite des Directors: 127 128 takeControl(...) Orientierung an DockingController.cc 129 130 tick() Soll von Event ausgelöst werden, wenn z.B. Kamera an Endposition angelangt ist. Danach soll wieder ein 131 menschlicher Spieler die Kontrolle übernehmen (wie? new human controller? Klasse noch angucken!). 132 */ 11 133 12 134 13 RegisterClass(ControllerDirector);14 15 ControllerDirector::ControllerDirector(Context* context) : BaseObject(context)16 {17 RegisterObject(ControllerDirector);18 19 20 }21 ControllerDirector::~ControllerDirector(){}22 23 24 25 135 26 136 }
Note: See TracChangeset
for help on using the changeset viewer.