[10014] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "ScriptController.h" |
---|
[10047] | 30 | #include "infos/PlayerInfo.h" |
---|
[10014] | 31 | #include "core/CoreIncludes.h" |
---|
[10028] | 32 | #include "worldentities/ControllableEntity.h" |
---|
[10045] | 33 | #include "core/LuaState.h" |
---|
[10034] | 34 | #include <cmath> |
---|
[10014] | 35 | |
---|
| 36 | namespace orxonox |
---|
| 37 | { |
---|
| 38 | RegisterClass(ScriptController); |
---|
| 39 | |
---|
[10028] | 40 | //ScriptController::ScriptController(Context* context, ControllableEntity* CE) : ArtificialController(context) |
---|
| 41 | ScriptController::ScriptController(Context* context) : ArtificialController(context) |
---|
[10014] | 42 | { |
---|
| 43 | RegisterObject(ScriptController); |
---|
[10028] | 44 | //set_controlled(CE); |
---|
[10047] | 45 | this->ctrlid_ = 0; |
---|
[10014] | 46 | } |
---|
| 47 | |
---|
[10047] | 48 | void ScriptController::takeControl(int ctrlid) |
---|
[10014] | 49 | { |
---|
[10047] | 50 | orxout() << "ScriptController: Taking control" << endl; |
---|
| 51 | orxout() << "This-pointer: " << this << endl; |
---|
| 52 | this->ctrlid_ = ctrlid; |
---|
| 53 | this->entity_ = this->player_->getControllableEntity(); |
---|
| 54 | assert(this->entity_); |
---|
| 55 | |
---|
| 56 | this->entity_->setDestroyWhenPlayerLeft(false); |
---|
| 57 | this->player_->pauseControl(); |
---|
| 58 | this->entity_->setController(this); |
---|
| 59 | this->setControllableEntity(this->entity_); |
---|
[10014] | 60 | } |
---|
| 61 | |
---|
[10047] | 62 | /* Yet to be implemented and tested */ |
---|
| 63 | //void ScriptController::yieldControl() |
---|
| 64 | //{ |
---|
| 65 | //this->player_->startControl(this->entity_); |
---|
| 66 | //this->setActive(false); |
---|
| 67 | //this->controllableEntity_ = NULL; |
---|
| 68 | //} |
---|
| 69 | |
---|
[10014] | 70 | void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
[10028] | 72 | //XMLPortParam(ScriptController, BaseObject, "lsrc", set_luasrc, xmlelement, mode); |
---|
[10014] | 73 | |
---|
| 74 | } |
---|
| 75 | |
---|
[10034] | 76 | const Vector3& ScriptController::getPosition() |
---|
[10020] | 77 | { |
---|
[10047] | 78 | return this->entity_->getPosition(); |
---|
[10028] | 79 | } |
---|
[10014] | 80 | |
---|
[10045] | 81 | ScriptController* ScriptController::getScriptController() |
---|
| 82 | { |
---|
[10046] | 83 | /* Output a message that confirms this function was called */ |
---|
[10045] | 84 | orxout() << "Great success!" << std::endl; |
---|
[10046] | 85 | |
---|
[10047] | 86 | /* Debugging: print all the scriptcontroller object pointers */ |
---|
[10045] | 87 | for(ObjectList<ScriptController>::iterator it = |
---|
| 88 | ObjectList<ScriptController>::begin(); |
---|
| 89 | it != ObjectList<ScriptController>::end(); ++it) |
---|
[10047] | 90 | { orxout() << "Have object in list: " << *it << endl; } |
---|
| 91 | |
---|
| 92 | /* Find the first one with a nonzero ID */ |
---|
| 93 | for(ObjectList<ScriptController>::iterator it = |
---|
| 94 | ObjectList<ScriptController>::begin(); |
---|
| 95 | it != ObjectList<ScriptController>::end(); ++it) |
---|
[10045] | 96 | { |
---|
| 97 | // TODO: do some selection here. Currently just returns the first one |
---|
[10047] | 98 | if( (*it)->getID() > 0 ) |
---|
| 99 | return *it; |
---|
[10045] | 100 | |
---|
| 101 | } |
---|
| 102 | return NULL; |
---|
| 103 | } |
---|
| 104 | |
---|
[10047] | 105 | void ScriptController::tick(float dt) |
---|
| 106 | { |
---|
| 107 | /* If this controller has no entity entry, do nothing */ |
---|
| 108 | if( !(this->entity_) ) |
---|
| 109 | return; |
---|
[10045] | 110 | |
---|
[10047] | 111 | //orxout() << "Rotating!" << endl; |
---|
[10045] | 112 | |
---|
[10047] | 113 | //this->entity_->rotateYaw(-1.0f * 100.0f * dt); |
---|
| 114 | //this->entity_->rotatePitch(0.8f * 100.0f); |
---|
| 115 | |
---|
| 116 | SUPER(ScriptController, tick, dt); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
[10034] | 120 | void ScriptController::moveToPosition_beta(float x, float y, float z ) |
---|
| 121 | { |
---|
[10047] | 122 | //const Vector3 local = this->getPosition(); |
---|
| 123 | const Vector3 target = Vector3(100*x,100*y,100*z); |
---|
| 124 | //Vector3 way = target-local; |
---|
| 125 | orxout() << "Moving This-pointer: " << this << endl; |
---|
[10038] | 126 | |
---|
[10046] | 127 | |
---|
[10047] | 128 | this->entity_->lookAt(target); |
---|
| 129 | this->entity_->moveFrontBack(-1000*target.length()); |
---|
[10034] | 130 | |
---|
[10046] | 131 | |
---|
| 132 | /* This works fine */ |
---|
| 133 | orxout()<<x<<" "<<y<<" "<<z<<endl; |
---|
[10034] | 134 | } |
---|
| 135 | |
---|
[10047] | 136 | |
---|
[10038] | 137 | /* TODO: hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl |
---|
| 138 | kein vektor3 definierbar ist |
---|
[10034] | 139 | |
---|
[10038] | 140 | NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden |
---|
[10014] | 141 | |
---|
[10038] | 142 | tick funktion?*/ |
---|
[10028] | 143 | |
---|
| 144 | |
---|
| 145 | |
---|
[10014] | 146 | } |
---|