Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

compilable

File size: 9.7 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->setPositionOfTarget(target_->getWorldPosition());
62
63        }
64        /*if (this->target_)
65        {
66            this->aimAtTarget();
67            this->doFire();
68            this->bShooting_ = true;
69        }*/
70       
71        if (this->bHasTargetPosition_)
72        {
73            this->moveToTargetPosition(dt);
74        }
75       /* if (executingMoveToPoint_)
76        {
77            executingMoveToPoint_ = !this->moveAndRoll(dt);
78        }
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        }*/
109        if (this->bShooting_ && this->canFire())
110            doFire();
111        SUPER(DivisionController, tick, dt);
112
113    }
114    void DivisionController::action()
115    {
116/*
117        Vector3* pos = new Vector3(4000,1000,2000);
118        this->setTargetPosition(*pos);*/
119       
120/*        if (!this->target_)
121        {
122
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        }*/
136        //this->chooseManeuverType();
137                    this->maneuver();
138
139        switch (this->maneuverType_)
140        {
141            case ManeuverType::NONE:
142            {
143                setTargetPositionOfFollower();
144                setTargetPositionOfWingman();
145                break;
146            }
147            case ManeuverType::DEFENCIVE:
148            {
149                this->gunsD();
150                break;
151            }
152            case ManeuverType::OFFENSIVE:
153            {
154                this->attack();
155                break;
156            }
157            case ManeuverType::NEUTRAL:
158            {
159                this->scissors();
160            }
161            default:
162            {
163                this->gunsD();
164                break;
165            }
166        }
167       
168        /*if (!executingMoveToPoint_)
169        {
170            Vector3* targetPosition = new Vector3 (0, 0, -2000);
171            moveToPoint(*targetPosition, 180);
172            executingMoveToPoint_ = true;
173        }
174        */
175        // if (this->myFollower_ && this->target_)
176        //     this->myFollower_->setTarget(this->target_);
177        // if (this->target_ && this->myWingman_)
178        //     this->myWingman_->setTarget(this->target_);
179    /*           
180        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
181        {
182            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
183            {
184                this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
185                             
186                break;
187            }
188        }
189           */
190        if (canFire())
191           this->bShooting_ = true;
192        else
193            this->bShooting_ = false;
194    }
195
196   
197
198    void DivisionController::setTargetPositionOfWingman()
199    {
200        if (!this->myWingman_)
201            return;
202        Vector3* targetRelativePositionOfWingman;
203        switch (this->formationMode_){
204            case FormationMode::WALL:
205            {
206                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
207                break;
208            }
209            case FormationMode::FINGER4: 
210            {
211                targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 
212                break;
213            }
214            case FormationMode::VEE: 
215            {
216                break;
217            }
218            case FormationMode::DIAMOND: 
219            {
220                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                 
221                break;
222            }
223        }
224        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
225       
226        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
227        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
228       
229        myWingman_->setTargetOrientation(orient);
230        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
231       
232    }
233    void DivisionController::setTargetPositionOfFollower()
234    {
235        if (!this->myFollower_)
236            return;
237        this->myFollower_->setFormationMode(this->formationMode_);
238
239        Vector3* targetRelativePositionOfFollower;
240        switch (this->formationMode_){
241            case FormationMode::WALL:
242            {
243                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
244                break;
245            }
246            case FormationMode::FINGER4: 
247            {
248                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
249                break;
250            }
251            case FormationMode::VEE: 
252            {
253                break;
254            }
255            case FormationMode::DIAMOND: 
256            {
257                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
258                break;
259            }
260        }
261        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
262       
263        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
264        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
265       
266        myFollower_->setTargetOrientation(orient);
267        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
268       
269    }
270
271
272    bool DivisionController::setWingman(CommonController* cwingman)
273    {
274
275        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
276        if (!this->myWingman_)
277        {
278            this->myWingman_ = wingman;
279            return true;
280        }
281        else
282        {
283            return false;
284        }
285   
286    }
287    bool DivisionController::setFollower(LeaderController* myFollower)
288    {
289         if (!this->myFollower_)
290        {
291            this->myFollower_ = myFollower;
292            return true;
293        }
294        else
295        {
296            return false;
297        }
298    }
299    bool DivisionController::hasWingman()
300    {
301        if (this->myWingman_)
302            return true;
303        else
304            return false;
305    }
306    bool DivisionController::hasFollower()
307    {
308        if (this->myFollower_)
309            return true;
310        else
311            return false;
312    }
313
314
315    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
316    {
317        SUPER(DivisionController, XMLPort, xmlelement, mode);
318
319        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
320    }
321
322   
323   
324
325}
Note: See TracBrowser for help on using the repository browser.