Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10855 was 10855, checked in by gania, 8 years ago

introduced loops

File size: 4.6 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        this->rank_ = Rank::DIVISIONLEADER;
48    }
49
50    DivisionController::~DivisionController()
51    {
52        if (this->myFollower_)
53        {
54            this->myFollower_->takeActionpoints(this->parsedActionpoints_);
55        }
56        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
57        {
58            if(this->actionpoints_[i])
59                this->actionpoints_[i]->destroy();
60        }
61        this->parsedActionpoints_.clear();
62        this->actionpoints_.clear();
63    } 
64
65    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
66    {
67        SUPER(DivisionController, XMLPort, xmlelement, mode);
68
69        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
70    }
71    void DivisionController::tick(float dt)
72    {   
73        if (!this->isActive())
74            return;
75        SUPER(DivisionController, tick, dt);
76    }
77    void DivisionController::action()
78    {   
79        CommonController::action();
80    }
81    void DivisionController::stayNearProtect()
82    {
83        CommonController::stayNearProtect();
84    }
85    void DivisionController::setTargetPositionOfWingman()
86    {
87        if (!this->myWingman_)
88            return;
89        Vector3* targetRelativePositionOfWingman;
90        switch (this->formationMode_){
91            case FormationMode::WALL:
92            {
93                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
94                break;
95            }
96            case FormationMode::FINGER4: 
97            {
98                targetRelativePositionOfWingman = new Vector3 (400, 0, 200); 
99                break;
100            }
101         
102            case FormationMode::DIAMOND: 
103            {
104                targetRelativePositionOfWingman = new Vector3 (400, 0, 200);                 
105                break;
106            }
107        }
108        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
109       
110        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
111        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
112       
113        myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient);
114       
115    }
116   
117    bool DivisionController::setWingman(CommonController* cwingman)
118    {
119
120        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
121        if (!this->myWingman_)
122        {
123            this->myWingman_ = wingman;
124            return true;
125        }
126        else
127        {
128            return false;
129        }
130    }
131    bool DivisionController::setFollower(LeaderController* myFollower)
132    {
133         if (!this->myFollower_)
134        {
135            this->myFollower_ = myFollower;
136            return true;
137        }
138        else
139        {
140            return false;
141        }
142    }
143    bool DivisionController::hasWingman()
144    {
145        if (this->myWingman_)
146            return true;
147        else
148            return false;
149    }
150    bool DivisionController::hasFollower()
151    {
152        if (this->myFollower_)
153            return true;
154        else
155            return false;
156    }
157}
Note: See TracBrowser for help on using the repository browser.