[11165] | 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 | |
---|
| 54 | namespace 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 | } |
---|
| 72 | |
---|
| 73 | void NewScriptController::takeControl(int ctrlid) |
---|
| 74 | { |
---|
| 75 | /* Output some debugging information */ |
---|
| 76 | orxout(verbose) << "NewScriptController: Taking control" << endl; |
---|
| 77 | orxout(verbose) << "This-pointer: " << this << endl; |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | /* Store the entity pointer in a private variable */ |
---|
| 81 | this->entity_ = this->player_->getControllableEntity(); |
---|
| 82 | assert(this->entity_); |
---|
| 83 | |
---|
| 84 | /* Add the controller here to this entity. Apparently this still leaves |
---|
| 85 | * any preexisting human controllers in place. |
---|
| 86 | */ |
---|
| 87 | this->entity_->setDestroyWhenPlayerLeft(false); |
---|
| 88 | this->player_->stopTemporaryControl(); |
---|
| 89 | this->entity_->setController(this); |
---|
| 90 | this->setControllableEntity(this->entity_); |
---|
| 91 | this->entity_->mouseLook(); |
---|
| 92 | this->entity_->setVisible(false); |
---|
| 93 | |
---|
| 94 | // TODO take the human Controllers control dont forget to give it back in the destructor |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | void NewScriptController::tick(float dt) |
---|
| 99 | { |
---|
| 100 | /* Call the tick function of the classes we derive from */ |
---|
| 101 | SUPER(ScriptController, tick, dt); |
---|
| 102 | |
---|
| 103 | /* If this controller has no entity entry, do nothing */ |
---|
| 104 | if( !(this->entity_) ) return; |
---|
| 105 | |
---|
| 106 | /* See if time has come for the next event to be run */ |
---|
| 107 | if(this->taskList_->size() > 0 && this->taskList_->front().getStartTime() <= scTime_) |
---|
| 108 | { /* Execute the next event on the list */ |
---|
| 109 | activeTasks_->push_back(taskList_->front()); |
---|
| 110 | taskList_->pop(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /* Update the local timers in this object */ |
---|
| 114 | scTime_ += dt; |
---|
| 115 | |
---|
| 116 | /* tick active tasks and delete completed tasks */ |
---|
| 117 | for(std::vector<Task>::iterator it = activeTasks_->begin(); it != activeTasks_->end(); it++) |
---|
| 118 | { |
---|
| 119 | it->tick(dt); |
---|
| 120 | if ( !(it->getIsRunning()) ) |
---|
| 121 | { |
---|
| 122 | activeTasks_->erase(it); |
---|
| 123 | it--; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | void NewScriptController::createAndAddTask(Task newTask) |
---|
| 132 | { |
---|
| 133 | taskList_->push(newTask); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | } |
---|