Changeset 10012 for code/branches/ScriptableController
- Timestamp:
- Apr 3, 2014, 1:21:01 PM (11 years ago)
- Location:
- code/branches/ScriptableController
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
r9667 r10012 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 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. 27 3 */ 28 4 … … 36 12 ScriptController::ScriptController(Context* context) : ArtificialController(context) 37 13 { 14 //Working 38 15 RegisterObject(ScriptController); 16 orxout()<<"hello universe constructor"<< endl; 17 18 this->player_=NULL; 19 this->entity_=NULL; 20 this->pTrigger_=NULL; 39 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. 108 109 110 111 Klassenvariablen 112 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 */ 133 134 135 40 136 } -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
r9667 r10012 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "ArtificialController.h" 34 #include "core/EventIncludes.h" 35 34 36 35 37 namespace orxonox … … 41 43 virtual ~ScriptController() { } 42 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 bool party(bool bTriggered, BaseObject* trigger); 47 void tick(float dt); 48 void takeControl(Controller * controller, BaseObject * trigger); 49 bool preparationToTakeControl(BaseObject * trigger); 50 void setNewController(Controller * controller); 51 52 43 53 private: 54 55 PlayerInfo* player_; 56 57 ControllableEntity* entity_; 58 59 PlayerTrigger * pTrigger_; 60 61 44 62 }; 45 63 }
Note: See TracChangeset
for help on using the changeset viewer.