Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

All compiling, WingmanControllers actually find LeaderControllers and connect to them, SectionControllers find DivisionControllers and connect. TODO write tick functions, helper functions to CommonController

File size: 5.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        bIsDivisionLeader_ = false;
41        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
42
43
44    }
45   
46    SectionController::~SectionController()
47    {
48        if (this->isInitialized())
49        {
50           
51        }
52    }
53     LeaderController* SectionController::findNewDivisionLeader()
54    {
55
56        if (!this->getControllableEntity())
57            return NULL;
58
59       
60        //go through all pawns
61        for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
62        {
63
64            //same team?
65            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
66                continue;
67
68            //is equal to this?
69            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
70                continue;
71
72
73           
74            //nullptr or not DivisionController?
75            if (!(it) || !(it)->bIsDivisionLeader_)
76                continue;
77
78            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
79
80            // is pawn in range?
81            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
82            {
83
84                if ((it)->setFollower(this))
85                    return (*it);
86            }
87        }
88                return NULL;
89
90    }
91
92    void SectionController::action()
93    {
94        //this->target_ = this->sectionTarget_;       
95        if (!myDivisionLeader_)
96        {
97            LeaderController* newDivisionLeader = findNewDivisionLeader();
98            myDivisionLeader_ = newDivisionLeader;
99           /* if (newDivisionLeader)
100                orxout(internal_error) << "new DivisionLeader set" << endl;
101            else
102                orxout(internal_error) << "null division leader" << endl;*/
103        }
104    }
105    /*
106    Wingmen and Leaders attack target_, which is a member variable of their classes.
107    Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
108    Wingman covers Leader's rear.
109    Leader's target_ must always equal sectionTarget_.
110    if section has a target, its Leader shoots at it, but doesn't follow.
111    Every section is a part of division. Division consisting of one Section is still a division.
112    Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
113    Division leader ONLY can follow target_ while in formation flight.
114    If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
115    Division Leader's sectionTarget_ must equal divisionTarget_,
116    but the other section, that is not a leading section, can attack any target that is near divisonTarget_
117
118    */
119    void SectionController::tick(float dt)
120    {/*
121        if (!this->isActive())
122            return;
123       
124        //--------------------------Stay in division--------------------------
125        this->keepDivisionTick();*/
126        /*keepDivisionTick(){
127            if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
128                Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
129                    (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
130                this->moveToPosition (desiredAbsolutePosition);
131            }
132        }
133        */
134        /*//If ordered to attack -> follow target and shoot
135        if (this->bAttackOrder_)
136        {
137 
138        }
139        //If ordered to move -> move to a target Point
140       
141        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
142        //(Section shoots same target, Boss's section shoots another target)
143        {
144
145        }*/
146
147        //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
148       
149        SUPER(SectionController, tick, dt);
150    }
151   
152
153    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
154    {
155        SUPER(SectionController, XMLPort, xmlelement, mode);
156
157        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
158    }
159
160   
161   
162
163}
Note: See TracBrowser for help on using the repository browser.