Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/controllers/TeamTargetProxy.cc

Last change on this file was 11071, checked in by landauf, 4 years ago

merged branch cpp11_v3 back to trunk

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