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" |
---|
30 | #include "infos/PlayerInfo.h" |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | #include "worldentities/ControllableEntity.h" |
---|
33 | #include "core/LuaState.h" |
---|
34 | #include <cmath> |
---|
35 | |
---|
36 | namespace orxonox |
---|
37 | { |
---|
38 | RegisterClass(ScriptController); |
---|
39 | |
---|
40 | //ScriptController::ScriptController(Context* context, ControllableEntity* CE) : ArtificialController(context) |
---|
41 | ScriptController::ScriptController(Context* context) : ArtificialController(context) |
---|
42 | { |
---|
43 | RegisterObject(ScriptController); |
---|
44 | //set_controlled(CE); |
---|
45 | this->ctrlid_ = 0; |
---|
46 | } |
---|
47 | |
---|
48 | void ScriptController::takeControl(int ctrlid) |
---|
49 | { |
---|
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_); |
---|
60 | } |
---|
61 | |
---|
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 | |
---|
70 | void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
71 | { |
---|
72 | //XMLPortParam(ScriptController, BaseObject, "lsrc", set_luasrc, xmlelement, mode); |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | const Vector3& ScriptController::getPosition() |
---|
77 | { |
---|
78 | return this->entity_->getPosition(); |
---|
79 | } |
---|
80 | |
---|
81 | ScriptController* ScriptController::getScriptController() |
---|
82 | { |
---|
83 | /* Output a message that confirms this function was called */ |
---|
84 | orxout() << "Great success!" << std::endl; |
---|
85 | |
---|
86 | /* Debugging: print all the scriptcontroller object pointers */ |
---|
87 | for(ObjectList<ScriptController>::iterator it = |
---|
88 | ObjectList<ScriptController>::begin(); |
---|
89 | it != ObjectList<ScriptController>::end(); ++it) |
---|
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) |
---|
96 | { |
---|
97 | // TODO: do some selection here. Currently just returns the first one |
---|
98 | if( (*it)->getID() > 0 ) |
---|
99 | return *it; |
---|
100 | |
---|
101 | } |
---|
102 | return NULL; |
---|
103 | } |
---|
104 | |
---|
105 | void ScriptController::tick(float dt) |
---|
106 | { |
---|
107 | /* If this controller has no entity entry, do nothing */ |
---|
108 | if( !(this->entity_) ) |
---|
109 | return; |
---|
110 | |
---|
111 | //orxout() << "Rotating!" << endl; |
---|
112 | |
---|
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 | |
---|
120 | void ScriptController::moveToPosition_beta(float x, float y, float z ) |
---|
121 | { |
---|
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; |
---|
126 | |
---|
127 | |
---|
128 | this->entity_->lookAt(target); |
---|
129 | this->entity_->moveFrontBack(-1000*target.length()); |
---|
130 | |
---|
131 | |
---|
132 | /* This works fine */ |
---|
133 | orxout()<<x<<" "<<y<<" "<<z<<endl; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | /* TODO: hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl |
---|
138 | kein vektor3 definierbar ist |
---|
139 | |
---|
140 | NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden |
---|
141 | |
---|
142 | tick funktion?*/ |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | } |
---|