[10719] | 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 "SectionController.h" |
---|
| 30 | |
---|
| 31 | namespace orxonox |
---|
| 32 | { |
---|
| 33 | |
---|
| 34 | RegisterClass(SectionController); |
---|
| 35 | static const float ACTION_INTERVAL = 1.0f; |
---|
| 36 | |
---|
| 37 | SectionController::SectionController(Context* context) : LeaderController(context) |
---|
| 38 | { |
---|
| 39 | RegisterObject(SectionController); |
---|
[10725] | 40 | this->setFormationMode(WALL); |
---|
| 41 | |
---|
[10719] | 42 | bIsDivisionLeader_ = false; |
---|
| 43 | this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this))); |
---|
[10725] | 44 | this->myWingman_ = 0; |
---|
| 45 | this->myDivisionLeader_ = 0; |
---|
| 46 | this->desiredRelativePosition_ = 0; |
---|
[10719] | 47 | |
---|
[10725] | 48 | orxout(internal_error) << this << "Was created" << endl; |
---|
[10719] | 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | SectionController::~SectionController() |
---|
| 53 | { |
---|
[10725] | 54 | |
---|
| 55 | } |
---|
| 56 | /*void SectionController::setDesiredPositionOfWingman() |
---|
| 57 | { |
---|
| 58 | if (!this->myWingman_) |
---|
| 59 | return; |
---|
| 60 | |
---|
| 61 | switch (this->formationMode_){ |
---|
| 62 | case WALL: |
---|
| 63 | { |
---|
| 64 | myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0); |
---|
| 65 | break; |
---|
| 66 | } |
---|
| 67 | case FINGER4: |
---|
| 68 | { |
---|
| 69 | break; |
---|
| 70 | } |
---|
| 71 | case VEE: |
---|
| 72 | { |
---|
| 73 | break; |
---|
| 74 | } |
---|
| 75 | case DIAMOND: |
---|
| 76 | { |
---|
| 77 | break; |
---|
| 78 | } |
---|
[10719] | 79 | } |
---|
[10725] | 80 | |
---|
[10719] | 81 | } |
---|
[10725] | 82 | */ |
---|
[10722] | 83 | LeaderController* SectionController::findNewDivisionLeader() |
---|
[10719] | 84 | { |
---|
| 85 | |
---|
| 86 | if (!this->getControllableEntity()) |
---|
[10722] | 87 | return 0; |
---|
[10719] | 88 | |
---|
[10722] | 89 | LeaderController* closestLeader = 0; |
---|
| 90 | float minDistance = std::numeric_limits<float>::infinity(); |
---|
[10719] | 91 | //go through all pawns |
---|
| 92 | for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it) |
---|
| 93 | { |
---|
[10722] | 94 | //0ptr or not DivisionController? |
---|
| 95 | if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity())) |
---|
| 96 | continue; |
---|
[10719] | 97 | //same team? |
---|
| 98 | if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())) |
---|
| 99 | continue; |
---|
| 100 | |
---|
| 101 | //is equal to this? |
---|
| 102 | if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) |
---|
| 103 | continue; |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
[10722] | 107 | |
---|
[10719] | 108 | |
---|
| 109 | float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); |
---|
[10722] | 110 | |
---|
| 111 | if (distance < minDistance && !(it->hasFollower())) |
---|
| 112 | { |
---|
| 113 | closestLeader = *it; |
---|
| 114 | minDistance = distance; |
---|
| 115 | } |
---|
| 116 | /* // is pawn in range? |
---|
[10719] | 117 | if (distance < RADIUS_TO_SEARCH_FOR_LEADER) |
---|
| 118 | { |
---|
| 119 | |
---|
| 120 | if ((it)->setFollower(this)) |
---|
| 121 | return (*it); |
---|
[10722] | 122 | }*/ |
---|
[10719] | 123 | } |
---|
[10722] | 124 | if (closestLeader) |
---|
| 125 | { |
---|
| 126 | if (closestLeader->setFollower(this)) |
---|
| 127 | return closestLeader; |
---|
| 128 | } |
---|
| 129 | return 0; |
---|
[10719] | 130 | |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | void SectionController::action() |
---|
| 134 | { |
---|
| 135 | //this->target_ = this->sectionTarget_; |
---|
| 136 | if (!myDivisionLeader_) |
---|
| 137 | { |
---|
| 138 | LeaderController* newDivisionLeader = findNewDivisionLeader(); |
---|
[10722] | 139 | this->myDivisionLeader_ = newDivisionLeader; |
---|
[10725] | 140 | if (newDivisionLeader) |
---|
[10719] | 141 | orxout(internal_error) << "new DivisionLeader set" << endl; |
---|
[10725] | 142 | |
---|
[10719] | 143 | } |
---|
[10725] | 144 | /* setDesiredPositionOfWingman(); |
---|
| 145 | */ } |
---|
[10719] | 146 | /* |
---|
| 147 | Wingmen and Leaders attack target_, which is a member variable of their classes. |
---|
| 148 | Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless |
---|
| 149 | Wingman covers Leader's rear. |
---|
| 150 | Leader's target_ must always equal sectionTarget_. |
---|
| 151 | if section has a target, its Leader shoots at it, but doesn't follow. |
---|
| 152 | Every section is a part of division. Division consisting of one Section is still a division. |
---|
| 153 | Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController. |
---|
| 154 | Division leader ONLY can follow target_ while in formation flight. |
---|
| 155 | If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint. |
---|
| 156 | Division Leader's sectionTarget_ must equal divisionTarget_, |
---|
| 157 | but the other section, that is not a leading section, can attack any target that is near divisonTarget_ |
---|
| 158 | |
---|
| 159 | */ |
---|
[10725] | 160 | /* void SectionController::keepDivisionTick() |
---|
| 161 | { |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_) |
---|
| 165 | { |
---|
| 166 | |
---|
| 167 | Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + |
---|
| 168 | (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); |
---|
| 169 | this->moveToPosition (desiredAbsolutePosition); |
---|
| 170 | } |
---|
| 171 | }*/ |
---|
[10719] | 172 | void SectionController::tick(float dt) |
---|
[10725] | 173 | { |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | /* |
---|
[10719] | 177 | if (!this->isActive()) |
---|
| 178 | return; |
---|
| 179 | |
---|
| 180 | //--------------------------Stay in division-------------------------- |
---|
[10725] | 181 | this->keepDivisionTick(); |
---|
[10719] | 182 | */ |
---|
| 183 | //If ordered to move -> move to a target Point |
---|
| 184 | |
---|
| 185 | //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. |
---|
| 186 | //(Section shoots same target, Boss's section shoots another target) |
---|
[10725] | 187 | |
---|
[10719] | 188 | |
---|
| 189 | //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; |
---|
| 190 | |
---|
| 191 | SUPER(SectionController, tick, dt); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 196 | { |
---|
| 197 | SUPER(SectionController, XMLPort, xmlelement, mode); |
---|
| 198 | |
---|
| 199 | //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | } |
---|