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