Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed firing direction

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