Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc @ 10909

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

decided to get rid of action timer and call action in tick instead: action is being called once in 2 sec in a tick, 2 sec were split in 4 * 0.25 sec, with 0.25 sec gap for each member of division to call its action, resulted in significant speed up.

File size: 4.7 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 "DivisionController.h"
30#include "infos/PlayerInfo.h"
31
32namespace orxonox
33{
34
35    RegisterClass(DivisionController);
36
37    //Leaders share the fact that they have Wingmans
38    DivisionController::DivisionController(Context* context) : ActionpointController(context)
39    {
40        RegisterObject(DivisionController);
41        this->setFormationMode(FormationMode::DIAMOND);
42        this->target_ = 0;
43        this->myFollower_ = 0;
44        this->myWingman_ = 0;
45        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
46    }
47
48    DivisionController::~DivisionController()
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 DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
60    {
61        SUPER(DivisionController, XMLPort, xmlelement, mode);
62
63        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
64    }
65    void DivisionController::tick(float dt)
66    {   
67        if (!this->isActive())
68            return;   
69        SUPER(DivisionController, tick, dt);
70        if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.5f && !this->bActionCalled_)
71        {
72            this->action();
73            this->bActionCalled_ = true;
74        }
75        if (this->timeOffset_ > 1.0f)
76        {
77            this->bActionCalled_ = false;
78        }
79
80       
81    }
82    void DivisionController::action()
83    {   
84        if (!this || !this->getControllableEntity())
85            return;
86       
87        ActionpointController::action();
88        if (!this || !this->getControllableEntity())
89            return;
90        if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
91        {
92            if (this->myFollower_)
93            {
94                this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
95            }
96            else if (this->myWingman_)
97            {
98                this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
99            }   
100        }
101       
102    }
103    //I wanted to do it different here, but at this point I think nothing will change if I delete that method
104    void DivisionController::stayNearProtect()
105    {
106        ActionpointController::stayNearProtect();
107    }
108   
109    bool DivisionController::setWingman(ActionpointController* newWingman)
110    {
111        if (!this->myWingman_)
112        {
113            this->myWingman_ = newWingman;
114            if (!this->hasFollower())
115                newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
116            return true;
117        }
118        else
119        {
120            return false;
121        }
122    }
123    bool DivisionController::setFollower(ActionpointController* newFollower)
124    {
125        if (!this->myFollower_)
126        {
127            this->myFollower_ = newFollower;
128            if (this->hasWingman())
129            {
130                this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false);
131            }
132
133            newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
134           
135            return true;
136        }
137        else
138        {
139            return false;
140        }
141    }
142    bool DivisionController::hasWingman()
143    {
144        if (this->myWingman_)
145            return true;
146        else
147            return false;
148    }
149    bool DivisionController::hasFollower()
150    {
151        if (this->myFollower_)
152            return true;
153       
154        return false;
155    }
156}
Note: See TracBrowser for help on using the repository browser.