Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc @ 11178

Last change on this file since 11178 was 11178, checked in by plehmann, 8 years ago

scriptcontroller task system doesnt work. it seems like queue is the wrong data structure

File size: 5.6 KB
Line 
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 *      Paul Lehmann
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29 /*
30  * Currently available lua commands:
31  *
32  * IMPORTANT: ALL COMMANDS DO REQUIRE 7 PARAMETERS TO BE PROVIDED. FILL UP WITH ZEROES IN UNIMPORTANT PLACES.
33  *
34  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
35  *
36  * "Move And Look"     | mal          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
37  * "Rotate And Look"   | ral          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | Axis (1=x, 2=y, 3=z) |     -    |     -    | Duration
38  * "Spiral"            | spi          | GoTo X Coordinate    |  '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
39  * "Transition Look"   | chl          | From X Coordinate    |  '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
40  * "rotate round X crd"| rotX         | anchor coordinate    | angle(rad)|    -    |                      |          |          | Duration
41  * "Idle (Do nothing)" | idle         | Duration
42  */
43
44#include "NewScriptController.h"
45
46#include "DebugTask.h"
47#include "stringOutTask.h"
48#include "Task.h"
49#include "infos/PlayerInfo.h"
50#include "core/CoreIncludes.h"
51#include "worldentities/ControllableEntity.h"
52#include "core/LuaState.h"
53#include "util/Math.h"
54
55namespace orxonox
56{
57    RegisterClass(NewScriptController);
58
59    NewScriptController::NewScriptController(Context* context) : ArtificialController(context)
60    {
61        RegisterObject(NewScriptController);
62
63
64        // Set default values for all variables
65        // - pointers to zero
66        this->player_ = nullptr;
67        this->entity_ = nullptr;
68
69        // - times
70        this->scTime_ = 0.0f;
71
72        this->context_ = context;
73    }
74
75
76
77    void NewScriptController::takeControl(int ctrlid)
78    {
79        // Output some debugging information
80        orxout(verbose) << "NewScriptController: Taking control" << endl;
81        orxout(verbose) << "This-pointer: " << this << endl; 
82
83
84        // Store the entity pointer in a private variable
85        this->entity_ = this->player_->getControllableEntity();
86        assert(this->entity_);
87
88        this->ctrlid_ = ctrlid;
89        if (ctrlid_ == 0)
90        {
91          ctrlid_ = 1;
92        }
93         
94        // Add the controller here to this entity. Apparently this still leaves
95        // any preexisting human controllers in place.
96         
97        this->entity_->setDestroyWhenPlayerLeft(false);
98        this->player_->stopTemporaryControl();
99        this->entity_->setController(this);
100        this->setControllableEntity(this->entity_);
101        this->entity_->mouseLook();
102        this->entity_->setVisible(false);
103       
104        // TODO take the human Controllers control  dont forget to give it back in the destructor
105    }
106
107
108    void NewScriptController::tick(float dt)
109    {
110        // Call the tick function of the classes we derive from
111        SUPER(NewScriptController, tick, dt);
112
113
114        // If this controller has no entity entry, do nothing
115        if( !(this->entity_) ) return;
116
117
118/*
119        if(taskQueue_.front()->getStartTime() <= scTime_)
120        {
121          activeTasks_.push_back(taskQueue_.front());
122          taskQueue_.pop();
123        }
124
125        for(Task* task : activeTasks_)
126        {
127          task->tick(dt);
128        }*/
129
130        if(taskQueue_.front() != nullptr)
131        {
132          orxout() << taskQueue_.front() << endl;
133          //taskQueue_.front()->tick(dt);
134        }
135    }
136
137
138    void NewScriptController::createAndAddTask(Task newTask)
139    {
140      //taskQueue_->push(newTask);
141    }
142
143    void NewScriptController::debugOut(float startTime)
144    {
145      DebugTask* task = new DebugTask(context_);
146      task->initialize(startTime);
147      taskQueue_.push(task);
148    }
149
150    void NewScriptController::stringOut(float startTime, std::string output)
151    {
152      stringOutTask* task = new stringOutTask(context_);
153      task->initialize(startTime, output);
154      taskQueue_.push(task);
155    }
156
157    NewScriptController* NewScriptController::getNewScriptController() 
158    {
159      /* Output a message that confirms this function was called */
160      orxout() << "Great success!" << std::endl;
161
162      /* Debugging: print all the scriptcontroller object pointers */
163      for(NewScriptController* controller : ObjectList<NewScriptController>())
164      { orxout() << "Have object in list: " << controller << endl; }
165
166      /* Find the first one with a nonzero ID */
167      for(NewScriptController* controller : ObjectList<NewScriptController>())
168      { 
169        // TODO: do some selection here. Currently just returns the first one
170        if( controller->getID() > 0 )
171        { orxout() << "Controller to return: " << controller << endl;
172          return controller;
173        }
174     
175      }
176      return nullptr;
177    }
178
179}
Note: See TracBrowser for help on using the repository browser.