Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12398 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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