Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

low on battery

File size: 9.6 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    {
[10793]59        if (this->target_ )
60        {
61            this->setPositionOfTarget(target_->getWorldPosition());
62
63        }
[10759]64        /*if (this->target_)
[10731]65        {
[10759]66            this->aimAtTarget();
67            this->doFire();
68            this->bShooting_ = true;
69        }*/
[10789]70       
71       /* if (this->bHasTargetPosition_)
[10729]72        {
73            this->moveToTargetPosition();
[10789]74        }*/
75        if (executingMoveToPoint_)
76        {
77            executingMoveToPoint_ = !this->moveAndRoll(dt);
[10729]78        }
[10796]79        else
80        {
81            if (this->target_)
82            {
83                this->positionOfTarget_ = getPredictedPosition( 
84                    this->getControllableEntity()->getWorldPosition(), 
85                    hardcoded_projectile_speed, 
86                    this->target_->getWorldPosition(), 
87                    this->target_->getVelocity() 
88                    );
89                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
90                float diffLength = diffVector.length();
91               /* Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
92                Vector3* targetPosition = new Vector3 ( 0, 0, -200 );
93                Vector3 target = rotationToTarget * (*targetPosition);*/
94                if (diffLength > 200)
95                    this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
96               
97                else
98                    this->setTargetPosition( this->getControllableEntity()->getWorldPosition() );
99                executingMoveToPoint_ = true; 
100            }
101           
102           
103            if (this->maneuverType_ == ManeuverType::OFFENSIVE)
104            {
105                this->attack();
106                this->moveAndRoll(dt);
107            }
108        }
[10780]109        if (this->bShooting_)
110            doFire();
[10722]111        SUPER(DivisionController, tick, dt);
[10718]112
[10678]113    }
[10725]114    void DivisionController::action()
115    {
[10763]116/*
117        Vector3* pos = new Vector3(4000,1000,2000);
118        this->setTargetPosition(*pos);*/
[10793]119       
120/*        if (!this->target_)
121        {
[10763]122
[10793]123            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
124            {
125                if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*it)->getTeam())
126                    continue;
127
128               
129
130                if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
131                {
132                    this->setTarget(*it);
133                }
134            }
135        }*/
[10796]136        //this->chooseManeuverType();
[10793]137        switch (this->maneuverType_)
138        {
139            case ManeuverType::NONE:
140            {
141                setTargetPositionOfFollower();
142                setTargetPositionOfWingman();
143                break;
144            }
[10796]145            case ManeuverType::DEFENCIVE:
[10793]146            {
147                this->gunsD();
[10796]148                break;
[10793]149            }
150            case ManeuverType::OFFENSIVE:
151            {
152                this->attack();
[10796]153                break;
[10793]154            }
[10796]155            case ManeuverType::NEUTRAL:
156            {
157                this->scissors();
158            }
159            default:
160            {
161                this->gunsD();
162                break;
163            }
[10793]164        }
165       
[10796]166        /*if (!executingMoveToPoint_)
[10789]167        {
168            Vector3* targetPosition = new Vector3 (0, 0, -2000);
169            moveToPoint(*targetPosition, 180);
170            executingMoveToPoint_ = true;
171        }
[10796]172        */
[10797]173        // if (this->myFollower_ && this->target_)
174        //     this->myFollower_->setTarget(this->target_);
175        // if (this->target_ && this->myWingman_)
176        //     this->myWingman_->setTarget(this->target_);
[10759]177    /*           
[10731]178        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
[10717]179        {
[10759]180            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
[10731]181            {
[10759]182                this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
183                             
[10731]184                break;
185            }
[10759]186        }
187           */
[10762]188        if (canFire())
[10780]189           this->bShooting_ = true;
190        else
191            this->bShooting_ = false;
[10709]192    }
[10725]193
[10731]194   
195
[10729]196    void DivisionController::setTargetPositionOfWingman()
[10725]197    {
198        if (!this->myWingman_)
199            return;
[10729]200        Vector3* targetRelativePositionOfWingman;
[10725]201        switch (this->formationMode_){
[10759]202            case FormationMode::WALL:
[10725]203            {
[10729]204                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
[10725]205                break;
206            }
[10759]207            case FormationMode::FINGER4: 
[10725]208            {
[10759]209                targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 
[10725]210                break;
211            }
[10759]212            case FormationMode::VEE: 
[10725]213            {
214                break;
215            }
[10759]216            case FormationMode::DIAMOND: 
[10725]217            {
[10759]218                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                 
[10725]219                break;
220            }
221        }
[10729]222        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
223       
224        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
225        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
226       
227        myWingman_->setTargetOrientation(orient);
228        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
[10725]229       
230    }
[10729]231    void DivisionController::setTargetPositionOfFollower()
[10725]232    {
233        if (!this->myFollower_)
234            return;
[10759]235        this->myFollower_->setFormationMode(this->formationMode_);
236
[10729]237        Vector3* targetRelativePositionOfFollower;
[10725]238        switch (this->formationMode_){
[10759]239            case FormationMode::WALL:
[10725]240            {
[10729]241                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
[10725]242                break;
243            }
[10759]244            case FormationMode::FINGER4: 
[10725]245            {
[10759]246                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
[10725]247                break;
248            }
[10759]249            case FormationMode::VEE: 
[10725]250            {
251                break;
252            }
[10759]253            case FormationMode::DIAMOND: 
[10725]254            {
[10759]255                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
[10725]256                break;
257            }
258        }
[10729]259        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
260       
261        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
262        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
263       
264        myFollower_->setTargetOrientation(orient);
265        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
[10725]266       
[10729]267    }
[10731]268
269
270    bool DivisionController::setWingman(CommonController* cwingman)
271    {
272
273        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
274        if (!this->myWingman_)
275        {
276            this->myWingman_ = wingman;
277            return true;
278        }
279        else
280        {
281            return false;
282        }
283   
284    }
285    bool DivisionController::setFollower(LeaderController* myFollower)
286    {
287         if (!this->myFollower_)
288        {
289            this->myFollower_ = myFollower;
290            return true;
291        }
292        else
293        {
294            return false;
295        }
296    }
297    bool DivisionController::hasWingman()
298    {
299        if (this->myWingman_)
300            return true;
301        else
302            return false;
303    }
304    bool DivisionController::hasFollower()
305    {
306        if (this->myFollower_)
307            return true;
308        else
309            return false;
310    }
311
312
[10719]313    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[10678]314    {
315        SUPER(DivisionController, XMLPort, xmlelement, mode);
316
317        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
[10719]318    }
[10678]319
320   
321   
322
323}
Note: See TracBrowser for help on using the repository browser.