Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

did nothing today

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