Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc @ 10854

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

Fixed some bugs, only DivisionController works for now

File size: 4.3 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 "WingmanController.h"
30
31
32namespace orxonox
33{
34
35    RegisterClass(WingmanController);
36   
37    //CommonController contains all common functionality of AI Controllers
38    WingmanController::WingmanController(Context* context) : CommonController(context)
39    {
40        RegisterObject(WingmanController);
41        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
42        this->myLeader_ = 0;
43        this->rank_ = Rank::WINGMAN;
44        this->bFirstAction_ = true;
45
46    }
47
48    WingmanController::~WingmanController()
49    {
50        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
51        {
52            if(this->actionpoints_[i])
53                this->actionpoints_[i]->destroy();
54        }
55        this->parsedActionpoints_.clear();
56        this->actionpoints_.clear();
57    }
58 
59    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
60    {
61        SUPER(WingmanController, XMLPort, xmlelement, mode);
62
63        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
64    }
65   
66    //----in tick, move (or look) and shoot----
67    void WingmanController::tick(float dt)
68    {   
69        if (!this->isActive())
70            return;
71       
72       
73        SUPER(WingmanController, tick, dt);
74    }
75   
76    //----action for hard calculations----
77    void WingmanController::action()
78    {
79
80        //----If no leader, find one----
81        if (!this->myLeader_)
82        {
83            CommonController* newLeader = findNewLeader();
84            this->myLeader_ = newLeader;
85           
86        }
87        //----If have leader, he will deal with logic----
88        else
89        {
90
91        }
92        if (!this->myLeader_)
93        {
94           CommonController::action();
95        }
96        else if (this->myLeader_)
97        {
98
99        }
100       
101    }
102     
103   
104   
105    //----POST: closest leader that is ready to take a new wingman is returned----
106    CommonController* WingmanController::findNewLeader()
107    {
108
109        if (!this->getControllableEntity())
110            return 0;
111
112        //----vars for finding the closest leader----
113        CommonController* closestLeader = 0;
114        float minDistance =  std::numeric_limits<float>::infinity();
115        Gametype* gt = this->getGametype();
116        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
117        {
118            //----0ptr or not a leader or dead?----
119            if (!it || 
120                (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 
121                !(it->getControllableEntity()))
122                continue;
123           
124            //----same team?----
125            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )
126                continue;
127           
128            //----check distance----
129            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
130            if (distance < minDistance && !(it->hasWingman()))
131            {
132                closestLeader = *it;
133                minDistance = distance;
134            }
135           
136        }
137        if (closestLeader)
138        {
139            //----Racing conditions----
140            if (closestLeader->setWingman(this))
141                return closestLeader;
142        }
143        return 0;
144    }
145
146
147
148
149}
Note: See TracBrowser for help on using the repository browser.