Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

small fixes

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