Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added a canFire() function

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