Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc @ 10725

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

fixed pointers

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 "SectionController.h"
30
31namespace orxonox
32{
33
34    RegisterClass(SectionController);
35    static const float ACTION_INTERVAL = 1.0f;
36
37    SectionController::SectionController(Context* context) : LeaderController(context)
38    {
39        RegisterObject(SectionController);
40                this->setFormationMode(WALL);
41
42        bIsDivisionLeader_ = false;
43        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
44        this->myWingman_ = 0;
45        this->myDivisionLeader_ = 0;
46        this->desiredRelativePosition_ = 0;
47
48        orxout(internal_error) << this << "Was created" << endl;
49
50    }
51   
52    SectionController::~SectionController()
53    {
54       
55    }
56    /*void SectionController::setDesiredPositionOfWingman()
57    {
58        if (!this->myWingman_)
59            return;
60
61        switch (this->formationMode_){
62            case WALL:
63            {
64                myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
65                break;
66            }
67            case FINGER4:
68            {
69                break;
70            }
71            case VEE:
72            {
73                break;
74            }
75            case DIAMOND:
76            {
77                break;
78            }
79        }
80       
81    }
82*/
83    LeaderController* SectionController::findNewDivisionLeader()
84    {
85
86        if (!this->getControllableEntity())
87            return 0;
88
89        LeaderController* closestLeader = 0;
90        float minDistance =  std::numeric_limits<float>::infinity();
91        //go through all pawns
92        for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
93        {
94            //0ptr or not DivisionController?
95            if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
96                continue;
97            //same team?
98            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
99                continue;
100
101            //is equal to this?
102            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
103                continue;
104
105
106           
107           
108
109            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
110           
111            if (distance < minDistance && !(it->hasFollower()))
112            {
113                closestLeader = *it;
114                minDistance = distance;
115            }
116           /* // is pawn in range?
117            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
118            {
119
120                if ((it)->setFollower(this))
121                    return (*it);
122            }*/
123        }
124        if (closestLeader)
125        {
126            if (closestLeader->setFollower(this))
127                return closestLeader;
128        }
129        return 0;
130
131    }
132
133    void SectionController::action()
134    {
135        //this->target_ = this->sectionTarget_;       
136        if (!myDivisionLeader_)
137        {
138            LeaderController* newDivisionLeader = findNewDivisionLeader();
139            this->myDivisionLeader_ = newDivisionLeader;
140            if (newDivisionLeader)
141                orxout(internal_error) << "new DivisionLeader set" << endl;
142
143        }
144/*        setDesiredPositionOfWingman();
145*/    }
146    /*
147    Wingmen and Leaders attack target_, which is a member variable of their classes.
148    Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
149    Wingman covers Leader's rear.
150    Leader's target_ must always equal sectionTarget_.
151    if section has a target, its Leader shoots at it, but doesn't follow.
152    Every section is a part of division. Division consisting of one Section is still a division.
153    Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
154    Division leader ONLY can follow target_ while in formation flight.
155    If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
156    Division Leader's sectionTarget_ must equal divisionTarget_,
157    but the other section, that is not a leading section, can attack any target that is near divisonTarget_
158
159    */
160   /* void SectionController::keepDivisionTick()
161    {
162
163
164        if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_)
165        {
166
167            Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) +
168                (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
169            this->moveToPosition (desiredAbsolutePosition);
170        }
171    }*/
172    void SectionController::tick(float dt)
173    {
174       
175
176       /*
177        if (!this->isActive())
178            return;
179       
180        //--------------------------Stay in division--------------------------
181        this->keepDivisionTick();
182        */
183        //If ordered to move -> move to a target Point
184       
185        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
186        //(Section shoots same target, Boss's section shoots another target)
187       
188
189        //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
190       
191        SUPER(SectionController, tick, dt);
192    }
193   
194
195    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
196    {
197        SUPER(SectionController, XMLPort, xmlelement, mode);
198
199        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
200    }
201
202   
203   
204
205}
Note: See TracBrowser for help on using the repository browser.