Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added a little bit of firing functionality

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