[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" |
---|
[10026] | 13 | #include "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 | |
---|
[10024] | 53 | preparationToTakeControl(trigger); |
---|
| 54 | setNewController(controller); |
---|
[10026] | 55 | LuaState test = new Luastate(); |
---|
| 56 | test.doFile("/tmp/myluahelloworld.lua"); |
---|
| 57 | |
---|
[10024] | 58 | } |
---|
| 59 | |
---|
[10016] | 60 | |
---|
[10024] | 61 | bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) { |
---|
[10016] | 62 | |
---|
[10024] | 63 | this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger); |
---|
[10016] | 64 | this->player_ = NULL; |
---|
| 65 | |
---|
[10024] | 66 | orxout() << "Preparation to take Control!" << endl; |
---|
[10016] | 67 | // Check whether it is a player trigger and extract pawn from it |
---|
[10024] | 68 | if(this->pTrigger_ != NULL) |
---|
[10016] | 69 | { |
---|
[10024] | 70 | |
---|
| 71 | player_ = this->pTrigger_->getTriggeringPlayer(); //Get the object which triggered the event. |
---|
[10016] | 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
[10024] | 75 | orxout() << "ControllerDirector::preparationToTakeControl Not a player trigger, can't extract pawn from it.." << endl; |
---|
[10016] | 76 | return false; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | this->entity_ = this->player_->getControllableEntity(); |
---|
| 81 | assert(this->entity_); |
---|
| 82 | |
---|
[10024] | 83 | return true; |
---|
| 84 | |
---|
[10016] | 85 | } |
---|
| 86 | |
---|
[10024] | 87 | void ControllerDirector::setNewController(Controller * controller) { |
---|
[10016] | 88 | |
---|
| 89 | |
---|
[10024] | 90 | orxout() << "New Controller is going to be set!" << endl; |
---|
[10016] | 91 | |
---|
[10024] | 92 | this->entity_->setDestroyWhenPlayerLeft(false); |
---|
| 93 | this->player_->pauseControl(); |
---|
| 94 | this->entity_->setController(controller); |
---|
| 95 | this->setControllableEntity(this->entity_); |
---|
| 96 | |
---|
[10026] | 97 | |
---|
| 98 | |
---|
[10024] | 99 | } |
---|
[10016] | 100 | |
---|
[10012] | 101 | |
---|
| 102 | |
---|
[10024] | 103 | } |
---|
[10016] | 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|