Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/MasterController.cc @ 12380

Last change on this file since 12380 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.7 KB
RevLine 
[10954]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 *      Gani Aliguzhinov
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "MasterController.h"
30#include "controllers/ActionpointController.h"
31namespace orxonox
32{
33
34    RegisterClass(MasterController);
35
36    //Leaders share the fact that they have Wingmans
[10958]37    MasterController::MasterController(Context* context) : Controller(context)
[10954]38    {
39        RegisterObject(MasterController);
40        this->controllers_.clear();
41        this->numberOfTicksPassedSinceLastActionCall_ = 0;
42        this->indexOfCurrentController_ = 0;
43        this->ticks_ = 0;
44    }
45
46    MasterController::~MasterController()
47    {
48        this->controllers_.clear();
49    } 
[10974]50    /*HACK*/
51    //the whole idea is a hack
[10954]52    void MasterController::tick(float dt)
53    {   
54        if (!this->isActive())
55            return; 
56        ++this->ticks_;
57        if (this->ticks_ == 1)
58        {
[10955]59            //fill the vector in the first tick
[11071]60            for (ActionpointController* controller : ObjectList<ActionpointController>())
[10954]61            {
62                //----0ptr?----
[11071]63                if (!controller)
[10954]64                    continue;
[11071]65                this->controllers_.push_back(controller);
[10954]66            }
67        }
68        else
69        {
70            if (this->controllers_.empty())
71                return;
72
[10955]73            //iterate over vecotr with the index, keep index in boundaries
[10954]74            if (this->indexOfCurrentController_ >= this->controllers_.size())
75            {
76                this->indexOfCurrentController_ = 0;
77            }
[10955]78            //each 9 ticks index is incremented
[10954]79            if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
80            {
81                this->numberOfTicksPassedSinceLastActionCall_ = 0;
82            }
83
84            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
85            {
86                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
87                {
[10974]88                    //check if 0ptr
[10954]89                    if (!this->controllers_.at(this->indexOfCurrentController_))
90                    {
91                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
92                        return;
93                    }
[10974]94                    //call maneuver for current index
[10954]95                    this->controllers_.at(this->indexOfCurrentController_)->maneuver();
96                }
97                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
98                {
[10974]99                    //check if 0ptr
[10954]100                    if (!this->controllers_.at(this->indexOfCurrentController_))
101                    {
102                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
103                        return;
104                    }
[10974]105                    //call canFire for current index
[10954]106                    this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
107                }
108                ++this->numberOfTicksPassedSinceLastActionCall_;
109            }
110            else
111            {
[10974]112                //check if 0ptr
[10954]113                if (!this->controllers_.at(this->indexOfCurrentController_))
114                {
115                    this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
116                    return;
117                }
[10974]118                //call action for current index
119                this->controllers_.at(this->indexOfCurrentController_)->action();   
120                 
[10958]121                //bCopyOrientation makes ship oscillate like crazy if set to true all the time.s
122                this->controllers_.at(this->indexOfCurrentController_)->bCopyOrientation_ = this->ticks_ % 3 == 0;
[10954]123
124                ++this->numberOfTicksPassedSinceLastActionCall_;
125                ++this->indexOfCurrentController_;
126            }
127        }
128    }
129}
Note: See TracBrowser for help on using the repository browser.