| [10049] | 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 | *      Martin Mueller | 
|---|
|  | 24 | *   Co-authors: | 
|---|
|  | 25 | *      ... | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
|  | 28 |  | 
|---|
|  | 29 | #include "TeamTargetProxy.h" | 
|---|
| [10060] | 30 | #include "worldentities/ControllableEntity.h" | 
|---|
| [10049] | 31 | #include "worldentities/pawns/Pawn.h" | 
|---|
|  | 32 |  | 
|---|
| [10060] | 33 | namespace orxonox | 
|---|
|  | 34 | { | 
|---|
| [10215] | 35 | RegisterClass(TeamTargetProxy); | 
|---|
| [10049] | 36 |  | 
|---|
| [10060] | 37 | /** | 
|---|
|  | 38 | @brief | 
|---|
|  | 39 | Sets default values for all variables. | 
|---|
|  | 40 |  | 
|---|
|  | 41 | @param context | 
|---|
|  | 42 | The context | 
|---|
|  | 43 | */ | 
|---|
| [10215] | 44 | TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context) | 
|---|
|  | 45 | { | 
|---|
|  | 46 | RegisterObject(TeamTargetProxy); | 
|---|
| [10049] | 47 |  | 
|---|
| [10215] | 48 | this->once_ = false; | 
|---|
|  | 49 | } | 
|---|
| [10049] | 50 |  | 
|---|
| [10060] | 51 | /** | 
|---|
|  | 52 | @brief | 
|---|
|  | 53 | Destructor. Nothing to see here. | 
|---|
|  | 54 | */ | 
|---|
| [10215] | 55 | TeamTargetProxy::~TeamTargetProxy() | 
|---|
|  | 56 | { | 
|---|
|  | 57 | } | 
|---|
| [10049] | 58 |  | 
|---|
| [10060] | 59 | /** | 
|---|
|  | 60 | @brief | 
|---|
|  | 61 | Copies the team and the target from the parent. | 
|---|
|  | 62 |  | 
|---|
|  | 63 | That's all there is. | 
|---|
|  | 64 | */ | 
|---|
| [10215] | 65 | void TeamTargetProxy::tick(float dt) | 
|---|
|  | 66 | { | 
|---|
|  | 67 | if (!this->isActive() || !this->getControllableEntity()) | 
|---|
|  | 68 | return; | 
|---|
| [10049] | 69 |  | 
|---|
|  | 70 | ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent()); | 
|---|
|  | 71 |  | 
|---|
| [10060] | 72 | if(this->getTeam() != -1 && !this->once_ && parent) | 
|---|
|  | 73 | { | 
|---|
|  | 74 | orxout(internal_warning) << "TeamTargetProxy: Team already set, may result in undesired behaviour. Will get overridden by the parent's team." << endl; | 
|---|
|  | 75 | } | 
|---|
| [10049] | 76 |  | 
|---|
| [10060] | 77 | if(!this->once_) | 
|---|
|  | 78 | this->once_ = true; | 
|---|
|  | 79 |  | 
|---|
|  | 80 | //Teams aren't set immediately, after creation, so we have to check every tick... | 
|---|
| [10049] | 81 | if(parent) | 
|---|
|  | 82 | { | 
|---|
| [10060] | 83 | Controller* parentcontroller = parent->getController(); | 
|---|
|  | 84 | if(parentcontroller) | 
|---|
| [10049] | 85 | { | 
|---|
| [10060] | 86 | this->setTeam(parentcontroller->getTeam()); | 
|---|
| [10049] | 87 | } | 
|---|
| [10060] | 88 | else | 
|---|
|  | 89 | { | 
|---|
|  | 90 | this->setTeam(parent->getTeam()); | 
|---|
|  | 91 | } | 
|---|
|  | 92 | this->getControllableEntity()->setTeam(parent->getTeam()); | 
|---|
|  | 93 | } | 
|---|
| [10049] | 94 |  | 
|---|
| [10060] | 95 | if(parent) | 
|---|
|  | 96 | { | 
|---|
| [10049] | 97 | Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); | 
|---|
|  | 98 | if(parenttarget) | 
|---|
|  | 99 | { | 
|---|
|  | 100 | this->setTarget(parenttarget); | 
|---|
|  | 101 | this->getControllableEntity()->setTarget(parenttarget); | 
|---|
|  | 102 | } | 
|---|
|  | 103 | } | 
|---|
| [10215] | 104 | } | 
|---|
|  | 105 | } | 
|---|