Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

changed the NewScriptController and Task classes

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 "Task.h"
47#include "infos/PlayerInfo.h"
48#include "core/CoreIncludes.h"
49#include "worldentities/ControllableEntity.h"
50#include "core/LuaState.h"
51#include "core/LuaState.h"
52#include "util/Math.h"
53
54namespace orxonox
55{
56    RegisterClass(NewScriptController);
57
58    NewScriptController::NewScriptController(Context* context) : ArtificialController(context)
59    {
60        RegisterObject(NewScriptController);
61
62
63        // Set default values for all variables
64        // - pointers to zero
65        this->player_ = nullptr;
66        this->entity_ = nullptr;
67
68        // - times
69        this->scTime_ = 0.0f;
70
71        //taskList_->push(new DebugTask);
72
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        // See if time has come for the next event to be run
118        if(this->taskList_->size() > 0 && this->taskList_->front().getStartTime() <= scTime_)
119        { // Execute the next event on the list
120          activeTasks_->push_back(taskList_->front());
121          taskList_->pop();
122        }
123
124        // Update the local timers in this object
125        scTime_ += dt;
126
127        // tick active tasks and delete completed tasks
128        for(std::vector<Task>::iterator it = activeTasks_->begin(); it != activeTasks_->end(); it++)
129        {
130          it->tick(dt);
131          if ( !(it->getIsRunning()) )
132          {
133            activeTasks_->erase(it);
134            it--;
135          }
136
137        }
138*/
139    }
140
141
142    void NewScriptController::createAndAddTask(Task newTask)
143    {
144      taskList_->push(newTask);
145    }
146
147    void NewScriptController::debugOut()
148    {
149      orxout() << "NewScriptController: Taking control" << endl;
150    }
151
152    NewScriptController* NewScriptController::getNewScriptController()
153    {
154      /* Output a message that confirms this function was called */
155      orxout() << "Great success!" << std::endl;
156
157      /* Debugging: print all the scriptcontroller object pointers */
158      for(NewScriptController* controller : ObjectList<NewScriptController>())
159      { orxout() << "Have object in list: " << controller << endl; }
160
161      /* Find the first one with a nonzero ID */
162      for(NewScriptController* controller : ObjectList<NewScriptController>())
163      { 
164        // TODO: do some selection here. Currently just returns the first one
165        if( controller->getID() > 0 )
166        { orxout() << "Controller to return: " << controller << endl;
167          return controller;
168        }
169     
170      }
171      return nullptr;
172    }
173
174}
Note: See TracBrowser for help on using the repository browser.