/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * Dominik Solenicki * */ #include "DivisionController.h" #include "infos/PlayerInfo.h" namespace orxonox { RegisterClass(DivisionController); //Leaders share the fact that they have Wingmans DivisionController::DivisionController(Context* context) : LeaderController(context) { RegisterObject(DivisionController); this->setFormationMode(FormationMode::DIAMOND); this->target_ = 0; this->myFollower_ = 0; this->myWingman_ = 0; this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); this->rank_ = Rank::DIVISIONLEADER; } DivisionController::~DivisionController() { // if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) // { // if (this->myFollower_) // { // this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); // if (this->myWingman_) // { // this->myWingman_->setAction(Action::FIGHTALL); // } // } // else if (this->myWingman_) // { // this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); // } // } for (size_t i = 0; i < this->actionpoints_.size(); ++i) { if(this->actionpoints_[i]) this->actionpoints_[i]->destroy(); } this->parsedActionpoints_.clear(); this->actionpoints_.clear(); } void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(DivisionController, XMLPort, xmlelement, mode); //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); } void DivisionController::tick(float dt) { if (!this->isActive()) return; SUPER(DivisionController, tick, dt); } void DivisionController::action() { if (!this || !this->getControllableEntity()) return; CommonController::action(); if (!this || !this->getControllableEntity()) return; if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) { if (this->myFollower_) { this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); } else if (this->myWingman_) { this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); } } } void DivisionController::stayNearProtect() { CommonController::stayNearProtect(); } bool DivisionController::setWingman(CommonController* cwingman) { WeakPtr wingman = orxonox_cast(cwingman); if (!this->myWingman_) { this->myWingman_ = wingman; return true; } else { return false; } } bool DivisionController::setFollower(LeaderController* myFollower) { if (!this->myFollower_) { this->myFollower_ = myFollower; return true; } else { return false; } } bool DivisionController::hasWingman() { if (this->myWingman_) return true; else return false; } bool DivisionController::hasFollower() { if (this->myFollower_) return true; else return false; } }