Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed a bug

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