Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added Master

File size: 4.6 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            for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
61            {
62                //----0ptr?----
63                if (!it)
64                    continue;
65                this->controllers_.push_back(*it);
66            }
67            //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl;
68        }
69        else
70        {
71            if (this->controllers_.empty())
72                return;
73
74            if (this->indexOfCurrentController_ >= this->controllers_.size())
75            {
76                this->indexOfCurrentController_ = 0;
77            }
78            if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
79            {
80                this->numberOfTicksPassedSinceLastActionCall_ = 0;
81            }
82
83            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
84            {
85                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
86                {
87                    if (!this->controllers_.at(this->indexOfCurrentController_))
88                    {
89                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
90                        return;
91                    }
92                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
93                    this->controllers_.at(this->indexOfCurrentController_)->maneuver();
94                }
95                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
96                {
97                    if (!this->controllers_.at(this->indexOfCurrentController_))
98                    {
99                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
100                        return;
101                    }
102                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
103                    this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
104                }
105                ++this->numberOfTicksPassedSinceLastActionCall_;
106            }
107            else
108            {
109                if (!this->controllers_.at(this->indexOfCurrentController_))
110                {
111                    this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
112                    return;
113                }
114                //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl;
115                this->controllers_.at(this->indexOfCurrentController_)->action();
116
117                ++this->numberOfTicksPassedSinceLastActionCall_;
118                ++this->indexOfCurrentController_;
119            }
120        }
121    }
122}
Note: See TracBrowser for help on using the repository browser.