[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); |
---|
[11071] | 42 | this->target_ = nullptr; |
---|
| 43 | this->myFollower_ = nullptr; |
---|
| 44 | this->myWingman_ = nullptr; |
---|
[10678] | 45 | } |
---|
| 46 | |
---|
| 47 | DivisionController::~DivisionController() |
---|
| 48 | { |
---|
[11071] | 49 | for (WorldEntity* actionpoint : this->actionpoints_) |
---|
[10854] | 50 | { |
---|
[11071] | 51 | if (actionpoint) |
---|
| 52 | actionpoint->destroy(); |
---|
[10854] | 53 | } |
---|
| 54 | this->parsedActionpoints_.clear(); |
---|
| 55 | this->actionpoints_.clear(); |
---|
[10725] | 56 | } |
---|
| 57 | void DivisionController::action() |
---|
[10854] | 58 | { |
---|
[10946] | 59 | if (!this || !this->getControllableEntity() || !this->isActive()) |
---|
[10859] | 60 | return; |
---|
[10861] | 61 | |
---|
[10864] | 62 | ActionpointController::action(); |
---|
[10861] | 63 | if (!this || !this->getControllableEntity()) |
---|
| 64 | return; |
---|
| 65 | if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) |
---|
| 66 | { |
---|
[10974] | 67 | //when this dies, its follower will execute all its actionpoints, if follower dies before this, wingman will do this |
---|
[10861] | 68 | if (this->myFollower_) |
---|
| 69 | { |
---|
| 70 | this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 71 | } |
---|
| 72 | else if (this->myWingman_) |
---|
| 73 | { |
---|
| 74 | this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 75 | } |
---|
| 76 | } |
---|
[10915] | 77 | |
---|
[10859] | 78 | |
---|
[10709] | 79 | } |
---|
[10869] | 80 | //I wanted to do it different here, but at this point I think nothing will change if I delete that method |
---|
[10854] | 81 | void DivisionController::stayNearProtect() |
---|
| 82 | { |
---|
[10864] | 83 | ActionpointController::stayNearProtect(); |
---|
[10854] | 84 | } |
---|
| 85 | |
---|
[10885] | 86 | bool DivisionController::setWingman(ActionpointController* newWingman) |
---|
[10731] | 87 | { |
---|
| 88 | if (!this->myWingman_) |
---|
| 89 | { |
---|
[10877] | 90 | this->myWingman_ = newWingman; |
---|
[10885] | 91 | if (!this->hasFollower()) |
---|
| 92 | newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
[10731] | 93 | return true; |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | { |
---|
| 97 | return false; |
---|
| 98 | } |
---|
| 99 | } |
---|
[10885] | 100 | bool DivisionController::setFollower(ActionpointController* newFollower) |
---|
[10731] | 101 | { |
---|
[10877] | 102 | if (!this->myFollower_) |
---|
[10731] | 103 | { |
---|
[10877] | 104 | this->myFollower_ = newFollower; |
---|
[10882] | 105 | if (this->hasWingman()) |
---|
| 106 | { |
---|
| 107 | this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false); |
---|
| 108 | } |
---|
[10885] | 109 | |
---|
| 110 | newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
| 111 | |
---|
[10731] | 112 | return true; |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | return false; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | bool DivisionController::hasWingman() |
---|
| 120 | { |
---|
| 121 | if (this->myWingman_) |
---|
| 122 | return true; |
---|
| 123 | else |
---|
| 124 | return false; |
---|
| 125 | } |
---|
| 126 | bool DivisionController::hasFollower() |
---|
| 127 | { |
---|
| 128 | if (this->myFollower_) |
---|
| 129 | return true; |
---|
[10882] | 130 | |
---|
| 131 | return false; |
---|
[10731] | 132 | } |
---|
[10915] | 133 | |
---|
[10678] | 134 | } |
---|