[10678] | 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 | * Dominik Solenicki |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "DivisionController.h" |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | RegisterClass(DivisionController); |
---|
| 36 | |
---|
[10709] | 37 | DivisionController::DivisionController(Context* context) : LeaderController(context) |
---|
[10678] | 38 | { |
---|
| 39 | RegisterObject(DivisionController); |
---|
[10725] | 40 | this->setFormationMode(WALL); |
---|
| 41 | |
---|
| 42 | this->myFollower_ = 0; |
---|
| 43 | this->myWingman_ = 0; |
---|
| 44 | this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); |
---|
[10731] | 45 | this->rank_ = DIVISIONLEADER; |
---|
[10725] | 46 | |
---|
[10731] | 47 | Vector3* pos = new Vector3(500,500,-500); |
---|
| 48 | this->setTargetPosition(*pos); |
---|
| 49 | |
---|
[10678] | 50 | } |
---|
| 51 | |
---|
| 52 | DivisionController::~DivisionController() |
---|
| 53 | { |
---|
[10725] | 54 | |
---|
| 55 | } |
---|
[10731] | 56 | |
---|
| 57 | |
---|
[10725] | 58 | void DivisionController::tick(float dt) |
---|
[10718] | 59 | { |
---|
[10731] | 60 | if (this->target_) |
---|
| 61 | { |
---|
[10737] | 62 | //this->aimAtTarget(); |
---|
| 63 | //this->doFire(); |
---|
| 64 | //this->bShooting_ = true; |
---|
[10731] | 65 | } |
---|
| 66 | |
---|
[10729] | 67 | if (this->bHasTargetPosition_) |
---|
| 68 | { |
---|
| 69 | this->moveToTargetPosition(); |
---|
| 70 | } |
---|
| 71 | |
---|
[10722] | 72 | SUPER(DivisionController, tick, dt); |
---|
[10718] | 73 | |
---|
[10678] | 74 | } |
---|
[10725] | 75 | void DivisionController::action() |
---|
| 76 | { |
---|
[10729] | 77 | setTargetPositionOfFollower(); |
---|
| 78 | setTargetPositionOfWingman(); |
---|
[10737] | 79 | /* |
---|
[10731] | 80 | for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) |
---|
[10717] | 81 | { |
---|
[10731] | 82 | if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) |
---|
| 83 | { |
---|
| 84 | this->target_=it->getControllableEntity(); |
---|
| 85 | this->setTargetPosition(this->target_->getWorldPosition()); |
---|
| 86 | break; |
---|
| 87 | } |
---|
[10737] | 88 | }*/ |
---|
[10731] | 89 | |
---|
| 90 | |
---|
[10709] | 91 | } |
---|
[10725] | 92 | |
---|
[10731] | 93 | |
---|
| 94 | |
---|
[10729] | 95 | void DivisionController::setTargetPositionOfWingman() |
---|
[10725] | 96 | { |
---|
| 97 | if (!this->myWingman_) |
---|
| 98 | return; |
---|
[10729] | 99 | Vector3* targetRelativePositionOfWingman; |
---|
[10725] | 100 | switch (this->formationMode_){ |
---|
| 101 | case WALL: |
---|
| 102 | { |
---|
[10729] | 103 | targetRelativePositionOfWingman = new Vector3 (400, 0, 0); |
---|
[10725] | 104 | break; |
---|
| 105 | } |
---|
| 106 | case FINGER4: |
---|
| 107 | { |
---|
| 108 | break; |
---|
| 109 | } |
---|
| 110 | case VEE: |
---|
| 111 | { |
---|
| 112 | break; |
---|
| 113 | } |
---|
| 114 | case DIAMOND: |
---|
| 115 | { |
---|
| 116 | break; |
---|
| 117 | } |
---|
| 118 | } |
---|
[10729] | 119 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
| 120 | |
---|
| 121 | Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + |
---|
| 122 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); |
---|
| 123 | |
---|
| 124 | myWingman_->setTargetOrientation(orient); |
---|
| 125 | myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); |
---|
[10725] | 126 | |
---|
| 127 | } |
---|
[10729] | 128 | void DivisionController::setTargetPositionOfFollower() |
---|
[10725] | 129 | { |
---|
| 130 | if (!this->myFollower_) |
---|
| 131 | return; |
---|
[10729] | 132 | Vector3* targetRelativePositionOfFollower; |
---|
[10725] | 133 | switch (this->formationMode_){ |
---|
| 134 | case WALL: |
---|
| 135 | { |
---|
[10729] | 136 | targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); |
---|
[10725] | 137 | break; |
---|
| 138 | } |
---|
| 139 | case FINGER4: |
---|
| 140 | { |
---|
| 141 | break; |
---|
| 142 | } |
---|
| 143 | case VEE: |
---|
| 144 | { |
---|
| 145 | break; |
---|
| 146 | } |
---|
| 147 | case DIAMOND: |
---|
| 148 | { |
---|
| 149 | break; |
---|
| 150 | } |
---|
| 151 | } |
---|
[10729] | 152 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
| 153 | |
---|
| 154 | Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + |
---|
| 155 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); |
---|
| 156 | |
---|
| 157 | myFollower_->setTargetOrientation(orient); |
---|
| 158 | myFollower_->setTargetPosition(targetAbsolutePositionOfFollower); |
---|
[10725] | 159 | |
---|
[10729] | 160 | } |
---|
[10731] | 161 | |
---|
| 162 | |
---|
| 163 | bool DivisionController::setWingman(CommonController* cwingman) |
---|
| 164 | { |
---|
| 165 | |
---|
| 166 | WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); |
---|
| 167 | if (!this->myWingman_) |
---|
| 168 | { |
---|
| 169 | this->myWingman_ = wingman; |
---|
| 170 | return true; |
---|
| 171 | } |
---|
| 172 | else |
---|
| 173 | { |
---|
| 174 | return false; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | } |
---|
| 178 | bool DivisionController::setFollower(LeaderController* myFollower) |
---|
| 179 | { |
---|
| 180 | if (!this->myFollower_) |
---|
| 181 | { |
---|
| 182 | this->myFollower_ = myFollower; |
---|
| 183 | return true; |
---|
| 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | return false; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | bool DivisionController::hasWingman() |
---|
| 191 | { |
---|
| 192 | if (this->myWingman_) |
---|
| 193 | return true; |
---|
| 194 | else |
---|
| 195 | return false; |
---|
| 196 | } |
---|
| 197 | bool DivisionController::hasFollower() |
---|
| 198 | { |
---|
| 199 | if (this->myFollower_) |
---|
| 200 | return true; |
---|
| 201 | else |
---|
| 202 | return false; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
[10719] | 206 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[10678] | 207 | { |
---|
| 208 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
| 209 | |
---|
| 210 | //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); |
---|
[10719] | 211 | } |
---|
[10678] | 212 | |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | } |
---|