| [10954] | 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 | * Gani Aliguzhinov |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "MasterController.h" |
|---|
| 30 | #include "controllers/ActionpointController.h" |
|---|
| 31 | namespace orxonox |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | RegisterClass(MasterController); |
|---|
| 35 | |
|---|
| 36 | //Leaders share the fact that they have Wingmans |
|---|
| 37 | MasterController::MasterController(Context* context) : FightingController(context) |
|---|
| 38 | { |
|---|
| 39 | RegisterObject(MasterController); |
|---|
| 40 | // orxout(internal_error) << "MasterController was created" << endl; |
|---|
| 41 | |
|---|
| 42 | this->controllers_.clear(); |
|---|
| 43 | this->numberOfTicksPassedSinceLastActionCall_ = 0; |
|---|
| 44 | this->indexOfCurrentController_ = 0; |
|---|
| 45 | this->ticks_ = 0; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | MasterController::~MasterController() |
|---|
| 49 | { |
|---|
| 50 | this->controllers_.clear(); |
|---|
| 51 | } |
|---|
| 52 | void MasterController::tick(float dt) |
|---|
| 53 | { |
|---|
| 54 | if (!this->isActive()) |
|---|
| 55 | return; |
|---|
| 56 | ++this->ticks_; |
|---|
| 57 | //orxout(internal_error) << "Tick = " << this->ticks_ << endl; |
|---|
| 58 | if (this->ticks_ == 1) |
|---|
| 59 | { |
|---|
| [10955] | 60 | //fill the vector in the first tick |
|---|
| [10954] | 61 | for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it) |
|---|
| 62 | { |
|---|
| 63 | //----0ptr?---- |
|---|
| 64 | if (!it) |
|---|
| 65 | continue; |
|---|
| 66 | this->controllers_.push_back(*it); |
|---|
| 67 | } |
|---|
| 68 | //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl; |
|---|
| 69 | } |
|---|
| 70 | else |
|---|
| 71 | { |
|---|
| [10955] | 72 | |
|---|
| [10954] | 73 | if (this->controllers_.empty()) |
|---|
| 74 | return; |
|---|
| 75 | |
|---|
| [10955] | 76 | //iterate over vecotr with the index, keep index in boundaries |
|---|
| [10954] | 77 | if (this->indexOfCurrentController_ >= this->controllers_.size()) |
|---|
| 78 | { |
|---|
| 79 | this->indexOfCurrentController_ = 0; |
|---|
| 80 | } |
|---|
| [10955] | 81 | //each 9 ticks index is incremented |
|---|
| [10954] | 82 | if (this->numberOfTicksPassedSinceLastActionCall_ >= 9) |
|---|
| 83 | { |
|---|
| 84 | this->numberOfTicksPassedSinceLastActionCall_ = 0; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | if (this->numberOfTicksPassedSinceLastActionCall_ > 0) |
|---|
| 88 | { |
|---|
| [10955] | 89 | //call maneuver for current index |
|---|
| [10954] | 90 | if (this->numberOfTicksPassedSinceLastActionCall_ == 3) |
|---|
| 91 | { |
|---|
| 92 | if (!this->controllers_.at(this->indexOfCurrentController_)) |
|---|
| 93 | { |
|---|
| 94 | this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_); |
|---|
| 95 | return; |
|---|
| 96 | } |
|---|
| 97 | //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl; |
|---|
| 98 | this->controllers_.at(this->indexOfCurrentController_)->maneuver(); |
|---|
| 99 | } |
|---|
| 100 | else if (this->numberOfTicksPassedSinceLastActionCall_ == 6) |
|---|
| 101 | { |
|---|
| [10955] | 102 | //call canFire for current index |
|---|
| [10954] | 103 | if (!this->controllers_.at(this->indexOfCurrentController_)) |
|---|
| 104 | { |
|---|
| 105 | this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_); |
|---|
| 106 | return; |
|---|
| 107 | } |
|---|
| 108 | //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl; |
|---|
| 109 | this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire(); |
|---|
| 110 | } |
|---|
| 111 | ++this->numberOfTicksPassedSinceLastActionCall_; |
|---|
| 112 | } |
|---|
| 113 | else |
|---|
| 114 | { |
|---|
| [10955] | 115 | //call action for current index |
|---|
| [10954] | 116 | if (!this->controllers_.at(this->indexOfCurrentController_)) |
|---|
| 117 | { |
|---|
| 118 | this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_); |
|---|
| 119 | return; |
|---|
| 120 | } |
|---|
| 121 | //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl; |
|---|
| 122 | this->controllers_.at(this->indexOfCurrentController_)->action(); |
|---|
| 123 | |
|---|
| 124 | ++this->numberOfTicksPassedSinceLastActionCall_; |
|---|
| 125 | ++this->indexOfCurrentController_; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | } |
|---|