Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc @ 10012

Last change on this file since 10012 was 10012, checked in by mkronig, 11 years ago

commit 3.4.2014

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/*
2First 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"
6#include "core/CoreIncludes.h"
7
8namespace 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
107Director 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
136}
Note: See TracBrowser for help on using the repository browser.