[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 "LeaderController.h" |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | RegisterClass(LeaderController); |
---|
| 36 | |
---|
[10717] | 37 | static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; |
---|
| 38 | |
---|
| 39 | LeaderController::LeaderController(Context* context) : CommonController(context) |
---|
[10678] | 40 | { |
---|
[10709] | 41 | |
---|
[10678] | 42 | RegisterObject(LeaderController); |
---|
[10717] | 43 | bIsDivisionLeader_ = false; |
---|
| 44 | |
---|
[10709] | 45 | //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); |
---|
[10678] | 46 | } |
---|
| 47 | |
---|
[10709] | 48 | |
---|
[10678] | 49 | LeaderController::~LeaderController() |
---|
| 50 | { |
---|
| 51 | } |
---|
| 52 | |
---|
[10717] | 53 | LeaderController* LeaderController::findNewDivisionLeader() |
---|
| 54 | { |
---|
| 55 | |
---|
| 56 | if (!this->getControllableEntity()) |
---|
| 57 | return NULL; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | //go through all pawns |
---|
| 61 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | //same team? |
---|
| 65 | if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) |
---|
| 66 | continue; |
---|
| 67 | |
---|
| 68 | //Does it have a Controller? |
---|
| 69 | Controller* controller = 0; |
---|
| 70 | |
---|
| 71 | if (it->getController()) |
---|
| 72 | controller = it->getController(); |
---|
| 73 | else if (it->getXMLController()) |
---|
| 74 | controller = it->getXMLController(); |
---|
| 75 | |
---|
| 76 | if (!controller) |
---|
| 77 | continue; |
---|
| 78 | |
---|
| 79 | //is equal to this? |
---|
| 80 | if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) |
---|
| 81 | continue; |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | LeaderController* newLeader = orxonox_cast<LeaderController*>(controller); |
---|
| 85 | |
---|
| 86 | //nullptr or not DivisionController? |
---|
| 87 | if (!newLeader || !newLeader->bIsDivisionLeader_) |
---|
| 88 | continue; |
---|
| 89 | |
---|
| 90 | float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); |
---|
| 91 | |
---|
| 92 | // is pawn in range? |
---|
| 93 | if (distance < RADIUS_TO_SEARCH_FOR_LEADER) |
---|
| 94 | { |
---|
| 95 | |
---|
| 96 | if (newLeader->setFollower(this)) |
---|
| 97 | return newLeader; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | return NULL; |
---|
| 101 | |
---|
| 102 | } |
---|
[10678] | 103 | void LeaderController::action() |
---|
| 104 | { |
---|
[10709] | 105 | //this->target_ = this->sectionTarget_; |
---|
[10717] | 106 | if (!myDivisionLeader_) |
---|
| 107 | { |
---|
| 108 | LeaderController* newDivisionLeader = findNewDivisionLeader(); |
---|
| 109 | myDivisionLeader_ = newDivisionLeader; |
---|
| 110 | orxout(internal_error) << "new DivisionLeader set" << endl; |
---|
| 111 | } |
---|
[10678] | 112 | } |
---|
[10682] | 113 | /* |
---|
| 114 | Wingmen and Leaders attack target_, which is a member variable of their classes. |
---|
| 115 | Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless |
---|
| 116 | Wingman covers Leader's rear. |
---|
| 117 | Leader's target_ must always equal sectionTarget_. |
---|
| 118 | if section has a target, its Leader shoots at it, but doesn't follow. |
---|
| 119 | Every section is a part of division. Division consisting of one Section is still a division. |
---|
| 120 | Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController. |
---|
| 121 | Division leader ONLY can follow target_ while in formation flight. |
---|
| 122 | If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint. |
---|
| 123 | Division Leader's sectionTarget_ must equal divisionTarget_, |
---|
| 124 | but the other section, that is not a leading section, can attack any target that is near divisonTarget_ |
---|
[10678] | 125 | |
---|
[10682] | 126 | */ |
---|
[10678] | 127 | void LeaderController::tick(float dt) |
---|
[10709] | 128 | {/* |
---|
[10682] | 129 | if (!this->isActive()) |
---|
| 130 | return; |
---|
| 131 | |
---|
| 132 | //--------------------------Stay in division-------------------------- |
---|
[10709] | 133 | this->keepDivisionTick();*/ |
---|
[10682] | 134 | /*keepDivisionTick(){ |
---|
| 135 | if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){ |
---|
| 136 | Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + |
---|
| 137 | (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); |
---|
| 138 | this->moveToPosition (desiredAbsolutePosition); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | */ |
---|
[10709] | 142 | /*//If ordered to attack -> follow target and shoot |
---|
[10682] | 143 | if (this->bAttackOrder_) |
---|
| 144 | { |
---|
[10709] | 145 | |
---|
[10682] | 146 | } |
---|
| 147 | //If ordered to move -> move to a target Point |
---|
[10709] | 148 | |
---|
[10682] | 149 | //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. |
---|
| 150 | //(Section shoots same target, Boss's section shoots another target) |
---|
| 151 | { |
---|
| 152 | |
---|
[10709] | 153 | }*/ |
---|
[10682] | 154 | |
---|
[10717] | 155 | orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; |
---|
[10709] | 156 | |
---|
[10678] | 157 | SUPER(LeaderController, tick, dt); |
---|
| 158 | } |
---|
[10717] | 159 | bool LeaderController::setWingman(WingmanController* wingman) |
---|
[10709] | 160 | { |
---|
[10717] | 161 | if (!this->myWingman_) |
---|
| 162 | { |
---|
| 163 | this->myWingman_ = wingman; |
---|
| 164 | return true; |
---|
| 165 | } |
---|
| 166 | else |
---|
| 167 | { |
---|
| 168 | return false; |
---|
| 169 | } |
---|
[10709] | 170 | } |
---|
[10717] | 171 | bool LeaderController::isLeader() |
---|
| 172 | { |
---|
| 173 | return true; |
---|
| 174 | } |
---|
[10678] | 175 | //**********************************************NEW |
---|
[10681] | 176 | /* void LeaderController::defaultBehaviour(float maxrand) |
---|
[10678] | 177 | { |
---|
| 178 | |
---|
[10681] | 179 | }*/ |
---|
[10678] | 180 | |
---|
| 181 | } |
---|