Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc @ 10869

Last change on this file since 10869 was 10869, checked in by gania, 9 years ago

fixed a bug and got rid of unnecessary Rank enumeration, used getIdentifire instead

File size: 4.7 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Dominik Solenicki
26 *
27 */
28
29#include "DivisionController.h"
30#include "infos/PlayerInfo.h"
31
32namespace orxonox
33{
34
35    RegisterClass(DivisionController);
36
37    //Leaders share the fact that they have Wingmans
38    DivisionController::DivisionController(Context* context) : LeaderController(context)
39    {
40        RegisterObject(DivisionController);
41       
42        this->setFormationMode(FormationMode::DIAMOND);
43        this->target_ = 0;
44        this->myFollower_ = 0;
45        this->myWingman_ = 0;
46        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
47    }
48
49    DivisionController::~DivisionController()
50    {
51        // if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
52        // {
53        //     if (this->myFollower_)
54        //     {
55        //         this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
56        //         if (this->myWingman_)
57        //         {
58        //             this->myWingman_->setAction(Action::FIGHTALL);
59        //         }
60        //     }
61        //     else if (this->myWingman_)
62        //     {
63        //         this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
64        //     }   
65        // }
66        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
67        {
68            if(this->actionpoints_[i])
69                this->actionpoints_[i]->destroy();
70        }
71        this->parsedActionpoints_.clear();
72        this->actionpoints_.clear();
73    } 
74
75    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(DivisionController, XMLPort, xmlelement, mode);
78
79        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
80    }
81    void DivisionController::tick(float dt)
82    {   
83        if (!this->isActive())
84            return;   
85        SUPER(DivisionController, tick, dt);
86    }
87    void DivisionController::action()
88    {   
89        if (!this || !this->getControllableEntity())
90            return;
91       
92        ActionpointController::action();
93        if (!this || !this->getControllableEntity())
94            return;
95        if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
96        {
97            if (this->myFollower_)
98            {
99                this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
100            }
101            else if (this->myWingman_)
102            {
103                this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
104            }   
105        }
106       
107    }
108    //I wanted to do it different here, but at this point I think nothing will change if I delete that method
109    void DivisionController::stayNearProtect()
110    {
111        ActionpointController::stayNearProtect();
112    }
113   
114    bool DivisionController::setWingman(CommonController* cwingman)
115    {
116
117        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
118        if (!this->myWingman_)
119        {
120            this->myWingman_ = wingman;
121            return true;
122        }
123        else
124        {
125            return false;
126        }
127    }
128    bool DivisionController::setFollower(LeaderController* myFollower)
129    {
130         if (!this->myFollower_)
131        {
132            this->myFollower_ = myFollower;
133            return true;
134        }
135        else
136        {
137            return false;
138        }
139    }
140    bool DivisionController::hasWingman()
141    {
142        if (this->myWingman_)
143            return true;
144        else
145            return false;
146    }
147    bool DivisionController::hasFollower()
148    {
149        if (this->myFollower_)
150            return true;
151        else
152            return false;
153    }
154}
Note: See TracBrowser for help on using the repository browser.