Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Works for DivisionController for now. Almost balanced AI! Dodges bullets (still killable, which is good), but goes crazy when close. So to be destroyed when far away. TODO implement formation flight when not in fight

File size: 5.9 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->isActive())
60            return;
61        if (this->bHasTargetPosition_)
62        {
63            this->moveToTargetPosition(dt);
64        }
65        else if (this->bLookAtTarget_)
66        {
67            this->lookAtTarget(dt);
68        }
69        if (bShooting_)
70        {
71            this->doFire();
72        }
73       
74        SUPER(DivisionController, tick, dt);
75
76    }
77    void DivisionController::action()
78    {
79        this->maneuver();
80        this->bShooting_ = this->canFire();
81       
82
83    }
84
85   
86
87    void DivisionController::setTargetPositionOfWingman()
88    {
89        if (!this->myWingman_)
90            return;
91        Vector3* targetRelativePositionOfWingman;
92        switch (this->formationMode_){
93            case FormationMode::WALL:
94            {
95                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
96                break;
97            }
98            case FormationMode::FINGER4: 
99            {
100                targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 
101                break;
102            }
103            case FormationMode::VEE: 
104            {
105                break;
106            }
107            case FormationMode::DIAMOND: 
108            {
109                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                 
110                break;
111            }
112        }
113        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
114       
115        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
116        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
117       
118        myWingman_->setTargetOrientation(orient);
119        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
120       
121    }
122    void DivisionController::setTargetPositionOfFollower()
123    {
124        if (!this->myFollower_)
125            return;
126        this->myFollower_->setFormationMode(this->formationMode_);
127
128        Vector3* targetRelativePositionOfFollower;
129        switch (this->formationMode_){
130            case FormationMode::WALL:
131            {
132                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
133                break;
134            }
135            case FormationMode::FINGER4: 
136            {
137                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
138                break;
139            }
140            case FormationMode::VEE: 
141            {
142                break;
143            }
144            case FormationMode::DIAMOND: 
145            {
146                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
147                break;
148            }
149        }
150        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
151       
152        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
153        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
154       
155        myFollower_->setTargetOrientation(orient);
156        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
157       
158    }
159
160
161    bool DivisionController::setWingman(CommonController* cwingman)
162    {
163
164        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
165        if (!this->myWingman_)
166        {
167            this->myWingman_ = wingman;
168            return true;
169        }
170        else
171        {
172            return false;
173        }
174   
175    }
176    bool DivisionController::setFollower(LeaderController* myFollower)
177    {
178         if (!this->myFollower_)
179        {
180            this->myFollower_ = myFollower;
181            return true;
182        }
183        else
184        {
185            return false;
186        }
187    }
188    bool DivisionController::hasWingman()
189    {
190        if (this->myWingman_)
191            return true;
192        else
193            return false;
194    }
195    bool DivisionController::hasFollower()
196    {
197        if (this->myFollower_)
198            return true;
199        else
200            return false;
201    }
202
203
204    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
205    {
206        SUPER(DivisionController, XMLPort, xmlelement, mode);
207
208        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
209    }
210
211   
212   
213
214}
Note: See TracBrowser for help on using the repository browser.