Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc @ 10759

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

small fixes

File size: 6.5 KB
RevLine 
[10678]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
31
32namespace orxonox
33{
34
35    RegisterClass(DivisionController);
36
[10709]37    DivisionController::DivisionController(Context* context) : LeaderController(context)
[10678]38    {
39        RegisterObject(DivisionController);
[10759]40       
41        this->setFormationMode(FormationMode::DIAMOND);
[10725]42
43        this->myFollower_ = 0;
44        this->myWingman_ = 0;
45        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
[10759]46        this->rank_ = Rank::DIVISIONLEADER;
[10725]47
[10759]48        Vector3* pos = new Vector3(-4000,-1000,-2000);
[10731]49        this->setTargetPosition(*pos);
50
[10678]51    }
52
53    DivisionController::~DivisionController()
54    {
[10725]55     
56    } 
[10731]57
58   
[10725]59    void DivisionController::tick(float dt)
[10718]60    {
[10759]61        /*if (this->target_)
[10731]62        {
[10759]63            this->aimAtTarget();
64            this->doFire();
65            this->bShooting_ = true;
66        }*/
[10731]67     
[10729]68        if (this->bHasTargetPosition_)
69        {
70            this->moveToTargetPosition();
71        }
72
[10722]73        SUPER(DivisionController, tick, dt);
[10718]74
[10678]75    }
[10725]76    void DivisionController::action()
77    {
[10729]78        setTargetPositionOfFollower();
79        setTargetPositionOfWingman();
[10759]80
81       
82        if (this->myFollower_ && this->target_)
83            this->myFollower_->setTarget(this->target_);
84        if (this->target_ && this->myWingman_)
85            this->myWingman_->setTarget(this->target_);
86    /*           
[10731]87        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
[10717]88        {
[10759]89            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
[10731]90            {
[10759]91                this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
92                             
[10731]93                break;
94            }
[10759]95        }
96           */
[10731]97     
[10709]98    }
[10725]99
[10731]100   
101
[10729]102    void DivisionController::setTargetPositionOfWingman()
[10725]103    {
104        if (!this->myWingman_)
105            return;
[10729]106        Vector3* targetRelativePositionOfWingman;
[10725]107        switch (this->formationMode_){
[10759]108            case FormationMode::WALL:
[10725]109            {
[10729]110                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
[10725]111                break;
112            }
[10759]113            case FormationMode::FINGER4: 
[10725]114            {
[10759]115                targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 
[10725]116                break;
117            }
[10759]118            case FormationMode::VEE: 
[10725]119            {
120                break;
121            }
[10759]122            case FormationMode::DIAMOND: 
[10725]123            {
[10759]124                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                 
[10725]125                break;
126            }
127        }
[10729]128        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
129       
130        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
131        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
132       
133        myWingman_->setTargetOrientation(orient);
134        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
[10725]135       
136    }
[10729]137    void DivisionController::setTargetPositionOfFollower()
[10725]138    {
139        if (!this->myFollower_)
140            return;
[10759]141        this->myFollower_->setFormationMode(this->formationMode_);
142
[10729]143        Vector3* targetRelativePositionOfFollower;
[10725]144        switch (this->formationMode_){
[10759]145            case FormationMode::WALL:
[10725]146            {
[10729]147                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
[10725]148                break;
149            }
[10759]150            case FormationMode::FINGER4: 
[10725]151            {
[10759]152                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
[10725]153                break;
154            }
[10759]155            case FormationMode::VEE: 
[10725]156            {
157                break;
158            }
[10759]159            case FormationMode::DIAMOND: 
[10725]160            {
[10759]161                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
[10725]162                break;
163            }
164        }
[10729]165        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
166       
167        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
168        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
169       
170        myFollower_->setTargetOrientation(orient);
171        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
[10725]172       
[10729]173    }
[10731]174
175
176    bool DivisionController::setWingman(CommonController* cwingman)
177    {
178
179        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
180        if (!this->myWingman_)
181        {
182            this->myWingman_ = wingman;
183            return true;
184        }
185        else
186        {
187            return false;
188        }
189   
190    }
191    bool DivisionController::setFollower(LeaderController* myFollower)
192    {
193         if (!this->myFollower_)
194        {
195            this->myFollower_ = myFollower;
196            return true;
197        }
198        else
199        {
200            return false;
201        }
202    }
203    bool DivisionController::hasWingman()
204    {
205        if (this->myWingman_)
206            return true;
207        else
208            return false;
209    }
210    bool DivisionController::hasFollower()
211    {
212        if (this->myFollower_)
213            return true;
214        else
215            return false;
216    }
217
218
[10719]219    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[10678]220    {
221        SUPER(DivisionController, XMLPort, xmlelement, mode);
222
223        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
[10719]224    }
[10678]225
226   
227   
228
229}
Note: See TracBrowser for help on using the repository browser.