Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc @ 10955

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

cleaned up a bit

File size: 4.9 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 *      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
37    MasterController::MasterController(Context* context) : FightingController(context)
38    {
39        RegisterObject(MasterController);
40        // orxout(internal_error) << "MasterController was created" << endl;
41
42        this->controllers_.clear();
43        this->numberOfTicksPassedSinceLastActionCall_ = 0;
44        this->indexOfCurrentController_ = 0;
45        this->ticks_ = 0;
46    }
47
48    MasterController::~MasterController()
49    {
50        this->controllers_.clear();
51    } 
52    void MasterController::tick(float dt)
53    {   
54        if (!this->isActive())
55            return; 
56        ++this->ticks_;
57        //orxout(internal_error) << "Tick = " << this->ticks_ << endl;
58        if (this->ticks_ == 1)
59        {
60            //fill the vector in the first tick
61            for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
62            {
63                //----0ptr?----
64                if (!it)
65                    continue;
66                this->controllers_.push_back(*it);
67            }
68            //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl;
69        }
70        else
71        {
72
73            if (this->controllers_.empty())
74                return;
75
76            //iterate over vecotr with the index, keep index in boundaries
77            if (this->indexOfCurrentController_ >= this->controllers_.size())
78            {
79                this->indexOfCurrentController_ = 0;
80            }
81            //each 9 ticks index is incremented
82            if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
83            {
84                this->numberOfTicksPassedSinceLastActionCall_ = 0;
85            }
86
87            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
88            {
89                //call maneuver for current index
90                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
91                {
92                    if (!this->controllers_.at(this->indexOfCurrentController_))
93                    {
94                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
95                        return;
96                    }
97                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
98                    this->controllers_.at(this->indexOfCurrentController_)->maneuver();
99                }
100                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
101                {
102                    //call canFire for current index
103                    if (!this->controllers_.at(this->indexOfCurrentController_))
104                    {
105                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
106                        return;
107                    }
108                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
109                    this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
110                }
111                ++this->numberOfTicksPassedSinceLastActionCall_;
112            }
113            else
114            {
115                //call action for current index
116                if (!this->controllers_.at(this->indexOfCurrentController_))
117                {
118                    this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
119                    return;
120                }
121                //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl;
122                this->controllers_.at(this->indexOfCurrentController_)->action();
123
124                ++this->numberOfTicksPassedSinceLastActionCall_;
125                ++this->indexOfCurrentController_;
126            }
127        }
128    }
129}
Note: See TracBrowser for help on using the repository browser.