[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" |
---|
[10849] | 30 | #include "infos/PlayerInfo.h" |
---|
[10678] | 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | RegisterClass(DivisionController); |
---|
| 36 | |
---|
[10826] | 37 | //Leaders share the fact that they have Wingmans |
---|
[10709] | 38 | DivisionController::DivisionController(Context* context) : LeaderController(context) |
---|
[10678] | 39 | { |
---|
| 40 | RegisterObject(DivisionController); |
---|
[10759] | 41 | |
---|
| 42 | this->setFormationMode(FormationMode::DIAMOND); |
---|
[10763] | 43 | this->target_ = 0; |
---|
[10725] | 44 | this->myFollower_ = 0; |
---|
| 45 | this->myWingman_ = 0; |
---|
| 46 | this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); |
---|
[10759] | 47 | this->rank_ = Rank::DIVISIONLEADER; |
---|
[10678] | 48 | } |
---|
| 49 | |
---|
| 50 | DivisionController::~DivisionController() |
---|
| 51 | { |
---|
[10854] | 52 | if (this->myFollower_) |
---|
| 53 | { |
---|
| 54 | this->myFollower_->takeActionpoints(this->parsedActionpoints_); |
---|
| 55 | } |
---|
| 56 | for (size_t i = 0; i < this->actionpoints_.size(); ++i) |
---|
| 57 | { |
---|
| 58 | if(this->actionpoints_[i]) |
---|
| 59 | this->actionpoints_[i]->destroy(); |
---|
| 60 | } |
---|
| 61 | this->parsedActionpoints_.clear(); |
---|
| 62 | this->actionpoints_.clear(); |
---|
[10725] | 63 | } |
---|
[10731] | 64 | |
---|
[10826] | 65 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 66 | { |
---|
| 67 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
| 68 | |
---|
| 69 | //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); |
---|
| 70 | } |
---|
[10725] | 71 | void DivisionController::tick(float dt) |
---|
[10803] | 72 | { |
---|
| 73 | if (!this->isActive()) |
---|
| 74 | return; |
---|
[10722] | 75 | SUPER(DivisionController, tick, dt); |
---|
[10678] | 76 | } |
---|
[10725] | 77 | void DivisionController::action() |
---|
[10854] | 78 | { |
---|
| 79 | CommonController::action(); |
---|
| 80 | |
---|
[10709] | 81 | } |
---|
[10854] | 82 | void DivisionController::stayNearProtect() |
---|
| 83 | { |
---|
| 84 | CommonController::stayNearProtect(); |
---|
| 85 | } |
---|
[10729] | 86 | void DivisionController::setTargetPositionOfWingman() |
---|
[10725] | 87 | { |
---|
| 88 | if (!this->myWingman_) |
---|
| 89 | return; |
---|
[10729] | 90 | Vector3* targetRelativePositionOfWingman; |
---|
[10725] | 91 | switch (this->formationMode_){ |
---|
[10759] | 92 | case FormationMode::WALL: |
---|
[10725] | 93 | { |
---|
[10729] | 94 | targetRelativePositionOfWingman = new Vector3 (400, 0, 0); |
---|
[10725] | 95 | break; |
---|
| 96 | } |
---|
[10759] | 97 | case FormationMode::FINGER4: |
---|
[10725] | 98 | { |
---|
[10832] | 99 | targetRelativePositionOfWingman = new Vector3 (400, 0, 200); |
---|
[10725] | 100 | break; |
---|
| 101 | } |
---|
[10826] | 102 | |
---|
[10759] | 103 | case FormationMode::DIAMOND: |
---|
[10725] | 104 | { |
---|
[10832] | 105 | targetRelativePositionOfWingman = new Vector3 (400, 0, 200); |
---|
[10725] | 106 | break; |
---|
| 107 | } |
---|
| 108 | } |
---|
[10729] | 109 | Quaternion orient = this->getControllableEntity()->getWorldOrientation(); |
---|
| 110 | |
---|
| 111 | Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + |
---|
| 112 | (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); |
---|
| 113 | |
---|
[10805] | 114 | myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient); |
---|
[10725] | 115 | |
---|
| 116 | } |
---|
[10854] | 117 | |
---|
[10731] | 118 | bool DivisionController::setWingman(CommonController* cwingman) |
---|
| 119 | { |
---|
| 120 | |
---|
| 121 | WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); |
---|
| 122 | if (!this->myWingman_) |
---|
| 123 | { |
---|
| 124 | this->myWingman_ = wingman; |
---|
| 125 | return true; |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
| 129 | return false; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | bool DivisionController::setFollower(LeaderController* myFollower) |
---|
| 133 | { |
---|
| 134 | if (!this->myFollower_) |
---|
| 135 | { |
---|
| 136 | this->myFollower_ = myFollower; |
---|
| 137 | return true; |
---|
| 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
| 141 | return false; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | bool DivisionController::hasWingman() |
---|
| 145 | { |
---|
| 146 | if (this->myWingman_) |
---|
| 147 | return true; |
---|
| 148 | else |
---|
| 149 | return false; |
---|
| 150 | } |
---|
| 151 | bool DivisionController::hasFollower() |
---|
| 152 | { |
---|
| 153 | if (this->myFollower_) |
---|
| 154 | return true; |
---|
| 155 | else |
---|
| 156 | return false; |
---|
| 157 | } |
---|
[10678] | 158 | } |
---|