[10016] | 1 | /* |
---|
[10024] | 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. |
---|
[10016] | 3 | */ |
---|
| 4 | |
---|
[10024] | 5 | #include "ControllerDirector.h" |
---|
[10012] | 6 | #include "core/CoreIncludes.h" |
---|
| 7 | |
---|
[10024] | 8 | //#include "network/NetworkFunction.h" |
---|
| 9 | |
---|
| 10 | #include "infos/HumanPlayer.h" |
---|
| 11 | #include "interfaces/PlayerTrigger.h" |
---|
| 12 | #include "worldentities/pawns/Pawn.h" |
---|
[10035] | 13 | #include "core/LuaState.h" |
---|
[10024] | 14 | |
---|
[10026] | 15 | |
---|
[10016] | 16 | namespace orxonox |
---|
| 17 | { |
---|
[10024] | 18 | RegisterClass(ControllerDirector); |
---|
[10012] | 19 | |
---|
[10024] | 20 | ControllerDirector::ControllerDirector(Context* context) : ArtificialController(context) |
---|
[10016] | 21 | { |
---|
| 22 | //Working |
---|
[10024] | 23 | RegisterObject(ControllerDirector); |
---|
[10016] | 24 | orxout()<<"hello universe constructor"<< endl; |
---|
[10012] | 25 | |
---|
[10024] | 26 | this->player_=NULL; |
---|
| 27 | this->entity_=NULL; |
---|
| 28 | this->pTrigger_=NULL; |
---|
[10016] | 29 | } |
---|
[10012] | 30 | |
---|
| 31 | |
---|
[10024] | 32 | void ControllerDirector::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[10016] | 33 | { |
---|
[10024] | 34 | SUPER(ControllerDirector, XMLPort, xmlelement, mode); |
---|
[10012] | 35 | |
---|
[10016] | 36 | |
---|
[10026] | 37 | orxout()<<"ControllerDriector::XMLPort An instance of ControllerDirector has been created."<< endl; |
---|
[10016] | 38 | } |
---|
| 39 | |
---|
[10024] | 40 | void ControllerDirector::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[10012] | 41 | { |
---|
[10024] | 42 | SUPER(ControllerDirector, XMLEventPort, xmlelement, mode); |
---|
[10012] | 43 | |
---|
[10026] | 44 | XMLPortEventSink(ControllerDirector, BaseObject, "takeControl", takeControl, xmlelement, mode); |
---|
[10024] | 45 | |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | void ControllerDirector::takeControl(Controller * controller, BaseObject * trigger) { |
---|
[10016] | 52 | |
---|
[10035] | 53 | // preparationTo(trigger); |
---|
| 54 | // setNewController(controller); |
---|
| 55 | LuaState * test = new LuaState(); |
---|
| 56 | orxout()<<"test takecontrol."<< endl; |
---|
| 57 | test->doFile("testscript.lua"); |
---|
[10026] | 58 | |
---|
[10024] | 59 | } |
---|
| 60 | |
---|
[10016] | 61 | |
---|
[10035] | 62 | /*bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) { |
---|
[10016] | 63 | |
---|
[10024] | 64 | this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger); |
---|
[10016] | 65 | this->player_ = NULL; |
---|
| 66 | |
---|
[10024] | 67 | orxout() << "Preparation to take Control!" << endl; |
---|
[10016] | 68 | // Check whether it is a player trigger and extract pawn from it |
---|
[10024] | 69 | if(this->pTrigger_ != NULL) |
---|
[10016] | 70 | { |
---|
[10024] | 71 | |
---|
| 72 | player_ = this->pTrigger_->getTriggeringPlayer(); //Get the object which triggered the event. |
---|
[10016] | 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
[10024] | 76 | orxout() << "ControllerDirector::preparationToTakeControl Not a player trigger, can't extract pawn from it.." << endl; |
---|
[10016] | 77 | return false; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | this->entity_ = this->player_->getControllableEntity(); |
---|
| 82 | assert(this->entity_); |
---|
| 83 | |
---|
[10024] | 84 | return true; |
---|
| 85 | |
---|
[10016] | 86 | } |
---|
| 87 | |
---|
[10024] | 88 | void ControllerDirector::setNewController(Controller * controller) { |
---|
[10016] | 89 | |
---|
| 90 | |
---|
[10024] | 91 | orxout() << "New Controller is going to be set!" << endl; |
---|
[10016] | 92 | |
---|
[10024] | 93 | this->entity_->setDestroyWhenPlayerLeft(false); |
---|
| 94 | this->player_->pauseControl(); |
---|
| 95 | this->entity_->setController(controller); |
---|
| 96 | this->setControllableEntity(this->entity_); |
---|
| 97 | |
---|
[10026] | 98 | |
---|
| 99 | |
---|
[10024] | 100 | } |
---|
[10035] | 101 | */ |
---|
[10016] | 102 | |
---|
[10012] | 103 | |
---|
| 104 | |
---|
[10024] | 105 | } |
---|
[10016] | 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|