Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationHS14merge/src/modules/objects/controllers/TeamTargetProxy.cc @ 10248

Last change on this file since 10248 was 10215, checked in by landauf, 10 years ago

replaced tabs with spaces. no changes in code.

File size: 2.9 KB
Line 
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"
30#include "worldentities/ControllableEntity.h"
31#include "worldentities/pawns/Pawn.h"
32
33namespace orxonox
34{
35    RegisterClass(TeamTargetProxy);
36
37   /**
38       @brief
39       Sets default values for all variables.
40
41       @param context
42       The context
43    */
44    TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context)
45    {
46        RegisterObject(TeamTargetProxy);
47
48        this->once_ = false;
49    }
50
51    /**
52        @brief
53        Destructor. Nothing to see here.
54     */
55    TeamTargetProxy::~TeamTargetProxy()
56    {
57    }
58
59    /**
60        @brief
61        Copies the team and the target from the parent.
62
63        That's all there is.
64    */
65    void TeamTargetProxy::tick(float dt)
66    {
67        if (!this->isActive() || !this->getControllableEntity())
68            return;
69
70        ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
71
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        }
76
77        if(!this->once_)
78            this->once_ = true;
79
80        //Teams aren't set immediately, after creation, so we have to check every tick...
81        if(parent)
82        {
83            Controller* parentcontroller = parent->getController();
84            if(parentcontroller)
85            {
86                this->setTeam(parentcontroller->getTeam());
87            }
88            else
89            {
90                this->setTeam(parent->getTeam());
91            }
92            this->getControllableEntity()->setTeam(parent->getTeam());
93        }
94
95        if(parent)
96        {
97            Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
98            if(parenttarget)
99            {
100                this->setTarget(parenttarget);
101                this->getControllableEntity()->setTarget(parenttarget);
102            }
103        }
104    }
105}
Note: See TracBrowser for help on using the repository browser.