[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 | |
---|
[11172] | 46 | #include "DebugTask.h" |
---|
[11165] | 47 | #include "Task.h" |
---|
| 48 | #include "infos/PlayerInfo.h" |
---|
| 49 | #include "core/CoreIncludes.h" |
---|
| 50 | #include "worldentities/ControllableEntity.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 | |
---|
[11167] | 63 | // Set default values for all variables |
---|
| 64 | // - pointers to zero |
---|
[11165] | 65 | this->player_ = nullptr; |
---|
| 66 | this->entity_ = nullptr; |
---|
| 67 | |
---|
[11167] | 68 | // - times |
---|
[11165] | 69 | this->scTime_ = 0.0f; |
---|
| 70 | |
---|
[11172] | 71 | this->context_ = context; |
---|
[11167] | 72 | |
---|
[11172] | 73 | task_ = new DebugTask(context); |
---|
| 74 | |
---|
| 75 | //taskQueue_->push(new DebugTask); |
---|
| 76 | |
---|
[11165] | 77 | } |
---|
| 78 | |
---|
[11167] | 79 | |
---|
| 80 | |
---|
[11165] | 81 | void NewScriptController::takeControl(int ctrlid) |
---|
| 82 | { |
---|
[11167] | 83 | // Output some debugging information |
---|
[11165] | 84 | orxout(verbose) << "NewScriptController: Taking control" << endl; |
---|
| 85 | orxout(verbose) << "This-pointer: " << this << endl; |
---|
| 86 | |
---|
| 87 | |
---|
[11167] | 88 | // Store the entity pointer in a private variable |
---|
[11165] | 89 | this->entity_ = this->player_->getControllableEntity(); |
---|
| 90 | assert(this->entity_); |
---|
[11167] | 91 | |
---|
| 92 | this->ctrlid_ = ctrlid; |
---|
| 93 | if (ctrlid_ == 0) |
---|
| 94 | { |
---|
| 95 | ctrlid_ = 1; |
---|
| 96 | } |
---|
[11165] | 97 | |
---|
[11167] | 98 | // Add the controller here to this entity. Apparently this still leaves |
---|
| 99 | // any preexisting human controllers in place. |
---|
| 100 | |
---|
[11165] | 101 | this->entity_->setDestroyWhenPlayerLeft(false); |
---|
| 102 | this->player_->stopTemporaryControl(); |
---|
| 103 | this->entity_->setController(this); |
---|
| 104 | this->setControllableEntity(this->entity_); |
---|
| 105 | this->entity_->mouseLook(); |
---|
| 106 | this->entity_->setVisible(false); |
---|
| 107 | |
---|
| 108 | // TODO take the human Controllers control dont forget to give it back in the destructor |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | void NewScriptController::tick(float dt) |
---|
| 113 | { |
---|
[11167] | 114 | // Call the tick function of the classes we derive from |
---|
| 115 | SUPER(NewScriptController, tick, dt); |
---|
[11165] | 116 | |
---|
[11172] | 117 | |
---|
[11167] | 118 | // If this controller has no entity entry, do nothing |
---|
[11165] | 119 | if( !(this->entity_) ) return; |
---|
| 120 | |
---|
[11172] | 121 | taskQueue_->first()->tick(); |
---|
[11165] | 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | void NewScriptController::createAndAddTask(Task newTask) |
---|
| 126 | { |
---|
[11172] | 127 | taskQueue_->push(newTask); |
---|
[11165] | 128 | } |
---|
| 129 | |
---|
[11172] | 130 | void NewScriptController::debugOut(float startTime) |
---|
[11167] | 131 | { |
---|
[11172] | 132 | DebugTask* task = new DebugTask(context); |
---|
| 133 | task->initialize(10000); |
---|
| 134 | taskQueue_->push(task); |
---|
[11167] | 135 | } |
---|
[11165] | 136 | |
---|
[11172] | 137 | NewScriptController* NewScriptController::getNewScriptController() |
---|
[11167] | 138 | { |
---|
| 139 | /* Output a message that confirms this function was called */ |
---|
| 140 | orxout() << "Great success!" << std::endl; |
---|
| 141 | |
---|
| 142 | /* Debugging: print all the scriptcontroller object pointers */ |
---|
| 143 | for(NewScriptController* controller : ObjectList<NewScriptController>()) |
---|
| 144 | { orxout() << "Have object in list: " << controller << endl; } |
---|
| 145 | |
---|
| 146 | /* Find the first one with a nonzero ID */ |
---|
| 147 | for(NewScriptController* controller : ObjectList<NewScriptController>()) |
---|
| 148 | { |
---|
| 149 | // TODO: do some selection here. Currently just returns the first one |
---|
| 150 | if( controller->getID() > 0 ) |
---|
| 151 | { orxout() << "Controller to return: " << controller << endl; |
---|
| 152 | return controller; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | } |
---|
| 156 | return nullptr; |
---|
| 157 | } |
---|
| 158 | |
---|
[11165] | 159 | } |
---|