[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: |
---|
[10885] | 23 | * Gani Aliguzhinov |
---|
[10678] | 24 | * Co-authors: |
---|
[10885] | 25 | * ... |
---|
[10678] | 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 |
---|
[10886] | 38 | DivisionController::DivisionController(Context* context) : ActionpointController(context) |
---|
[10678] | 39 | { |
---|
| 40 | RegisterObject(DivisionController); |
---|
[10759] | 41 | this->setFormationMode(FormationMode::DIAMOND); |
---|
[10763] | 42 | this->target_ = 0; |
---|
[10725] | 43 | this->myFollower_ = 0; |
---|
| 44 | this->myWingman_ = 0; |
---|
[10678] | 45 | } |
---|
| 46 | |
---|
| 47 | DivisionController::~DivisionController() |
---|
| 48 | { |
---|
[10854] | 49 | for (size_t i = 0; i < this->actionpoints_.size(); ++i) |
---|
| 50 | { |
---|
| 51 | if(this->actionpoints_[i]) |
---|
| 52 | this->actionpoints_[i]->destroy(); |
---|
| 53 | } |
---|
| 54 | this->parsedActionpoints_.clear(); |
---|
| 55 | this->actionpoints_.clear(); |
---|
[10725] | 56 | } |
---|
[10731] | 57 | |
---|
[10826] | 58 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 59 | { |
---|
| 60 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
[10912] | 61 | |
---|
[10826] | 62 | } |
---|
[10725] | 63 | void DivisionController::tick(float dt) |
---|
[10803] | 64 | { |
---|
| 65 | if (!this->isActive()) |
---|
[10861] | 66 | return; |
---|
[10953] | 67 | |
---|
[10722] | 68 | SUPER(DivisionController, tick, dt); |
---|
[10909] | 69 | |
---|
[10678] | 70 | } |
---|
[10725] | 71 | void DivisionController::action() |
---|
[10854] | 72 | { |
---|
[10946] | 73 | if (!this || !this->getControllableEntity() || !this->isActive()) |
---|
[10859] | 74 | return; |
---|
[10861] | 75 | |
---|
[10864] | 76 | ActionpointController::action(); |
---|
[10861] | 77 | if (!this || !this->getControllableEntity()) |
---|
| 78 | return; |
---|
| 79 | if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) |
---|
| 80 | { |
---|
[10974] | 81 | //when this dies, its follower will execute all its actionpoints, if follower dies before this, wingman will do this |
---|
[10861] | 82 | if (this->myFollower_) |
---|
| 83 | { |
---|
| 84 | this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 85 | } |
---|
| 86 | else if (this->myWingman_) |
---|
| 87 | { |
---|
| 88 | this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 89 | } |
---|
| 90 | } |
---|
[10915] | 91 | |
---|
[10859] | 92 | |
---|
[10709] | 93 | } |
---|
[10869] | 94 | //I wanted to do it different here, but at this point I think nothing will change if I delete that method |
---|
[10854] | 95 | void DivisionController::stayNearProtect() |
---|
| 96 | { |
---|
[10864] | 97 | ActionpointController::stayNearProtect(); |
---|
[10854] | 98 | } |
---|
| 99 | |
---|
[10885] | 100 | bool DivisionController::setWingman(ActionpointController* newWingman) |
---|
[10731] | 101 | { |
---|
| 102 | if (!this->myWingman_) |
---|
| 103 | { |
---|
[10877] | 104 | this->myWingman_ = newWingman; |
---|
[10885] | 105 | if (!this->hasFollower()) |
---|
| 106 | newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
[10731] | 107 | return true; |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | return false; |
---|
| 112 | } |
---|
| 113 | } |
---|
[10885] | 114 | bool DivisionController::setFollower(ActionpointController* newFollower) |
---|
[10731] | 115 | { |
---|
[10877] | 116 | if (!this->myFollower_) |
---|
[10731] | 117 | { |
---|
[10877] | 118 | this->myFollower_ = newFollower; |
---|
[10882] | 119 | if (this->hasWingman()) |
---|
| 120 | { |
---|
| 121 | this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false); |
---|
| 122 | } |
---|
[10885] | 123 | |
---|
| 124 | newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 125 | |
---|
[10731] | 126 | return true; |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | return false; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | bool DivisionController::hasWingman() |
---|
| 134 | { |
---|
| 135 | if (this->myWingman_) |
---|
| 136 | return true; |
---|
| 137 | else |
---|
| 138 | return false; |
---|
| 139 | } |
---|
| 140 | bool DivisionController::hasFollower() |
---|
| 141 | { |
---|
| 142 | if (this->myFollower_) |
---|
| 143 | return true; |
---|
[10882] | 144 | |
---|
| 145 | return false; |
---|
[10731] | 146 | } |
---|
[10915] | 147 | |
---|
[10678] | 148 | } |
---|