Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc @ 10718

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

bugfix

File size: 6.0 KB
RevLine 
[10678]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 "LeaderController.h"
[10718]30#include "core/CoreIncludes.h"
[10678]31
[10718]32#include "core/XMLPort.h"
33#include "core/command/ConsoleCommandIncludes.h"
[10678]34
[10718]35#include "worldentities/ControllableEntity.h"
36#include "worldentities/pawns/Pawn.h"
37
[10678]38namespace orxonox
39{
40
41    RegisterClass(LeaderController);
42
[10717]43    static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
44
45    LeaderController::LeaderController(Context* context) : CommonController(context)
[10678]46    {
[10709]47
[10678]48        RegisterObject(LeaderController);
[10717]49        bIsDivisionLeader_ = false;
50
[10709]51        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
[10678]52    }
53
[10709]54
[10678]55    LeaderController::~LeaderController()
56    {
57    }
58
[10717]59    LeaderController* LeaderController::findNewDivisionLeader()
60    {
61
62        if (!this->getControllableEntity())
63            return NULL;
64
65       
66        //go through all pawns
67        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
68        {
69
70            //same team?
71            if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
72                continue;
73
74            //Does it have a Controller?
75            Controller* controller = 0;
76
77            if (it->getController())
78                controller = it->getController();
79            else if (it->getXMLController())
80                controller = it->getXMLController();
81
82            if (!controller)
83                continue;
84
85            //is equal to this?
86            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
87                continue;
88
89
90            LeaderController* newLeader = orxonox_cast<LeaderController*>(controller);
91
92            //nullptr or not DivisionController?
93            if (!newLeader || !newLeader->bIsDivisionLeader_)
94                continue;
95
96            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
97
98            // is pawn in range?
99            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
100            {
101
102                if (newLeader->setFollower(this))
103                    return newLeader;
104            }
105        }
106                return NULL;
107
108    }
[10678]109    void LeaderController::action()
110    {
[10709]111        //this->target_ = this->sectionTarget_;       
[10717]112        if (!myDivisionLeader_)
113        {
114            LeaderController* newDivisionLeader = findNewDivisionLeader();
115            myDivisionLeader_ = newDivisionLeader;
116            orxout(internal_error) << "new DivisionLeader set" << endl;
117        }
[10678]118    }
[10682]119    /*
120    Wingmen and Leaders attack target_, which is a member variable of their classes.
121    Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
122    Wingman covers Leader's rear.
123    Leader's target_ must always equal sectionTarget_.
124    if section has a target, its Leader shoots at it, but doesn't follow.
125    Every section is a part of division. Division consisting of one Section is still a division.
126    Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
127    Division leader ONLY can follow target_ while in formation flight.
128    If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
129    Division Leader's sectionTarget_ must equal divisionTarget_,
130    but the other section, that is not a leading section, can attack any target that is near divisonTarget_
[10678]131
[10682]132    */
[10678]133    void LeaderController::tick(float dt)
[10709]134    {/*
[10682]135        if (!this->isActive())
136            return;
137       
138        //--------------------------Stay in division--------------------------
[10709]139        this->keepDivisionTick();*/
[10682]140        /*keepDivisionTick(){
141            if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
142                Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
143                    (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
144                this->moveToPosition (desiredAbsolutePosition);
145            }
146        }
147        */
[10709]148        /*//If ordered to attack -> follow target and shoot
[10682]149        if (this->bAttackOrder_)
150        {
[10709]151 
[10682]152        }
153        //If ordered to move -> move to a target Point
[10709]154       
[10682]155        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
156        //(Section shoots same target, Boss's section shoots another target)
157        {
158
[10709]159        }*/
[10682]160
[10717]161        orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
[10709]162       
[10678]163        SUPER(LeaderController, tick, dt);
164    }
[10717]165    bool LeaderController::setWingman(WingmanController* wingman)
[10709]166    {
[10717]167        if (!this->myWingman_)
168        {
169            this->myWingman_ = wingman;
170            return true;
171        }
172        else
173        {
174            return false;
175        }
[10709]176    }
[10717]177    bool LeaderController::isLeader()
178    {
179        return true;
180    }
[10678]181//**********************************************NEW
[10681]182   /* void LeaderController::defaultBehaviour(float maxrand)
[10678]183    { 
184       
[10681]185    }*/
[10678]186
187}
Note: See TracBrowser for help on using the repository browser.