[Orxonox-commit 6297] r10954 - code/branches/campaignHS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Mon Dec 7 20:45:07 CET 2015


Author: gania
Date: 2015-12-07 20:45:07 +0100 (Mon, 07 Dec 2015)
New Revision: 10954

Added:
   code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
   code/branches/campaignHS15/src/orxonox/controllers/MasterController.h
Log:
added Master

Added: code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	                        (rev 0)
+++ code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	2015-12-07 19:45:07 UTC (rev 10954)
@@ -0,0 +1,122 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Gani Aliguzhinov
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "MasterController.h"
+#include "controllers/ActionpointController.h"
+namespace orxonox
+{
+
+    RegisterClass(MasterController);
+
+    //Leaders share the fact that they have Wingmans
+    MasterController::MasterController(Context* context) : FightingController(context)
+    {
+        RegisterObject(MasterController);
+        // orxout(internal_error) << "MasterController was created" << endl;
+
+        this->controllers_.clear();
+        this->numberOfTicksPassedSinceLastActionCall_ = 0;
+        this->indexOfCurrentController_ = 0;
+        this->ticks_ = 0;
+    }
+
+    MasterController::~MasterController()
+    {
+        this->controllers_.clear();
+    } 
+    void MasterController::tick(float dt)
+    {   
+        if (!this->isActive())
+            return;  
+        ++this->ticks_;
+        //orxout(internal_error) << "Tick = " << this->ticks_ << endl;
+        if (this->ticks_ == 1)
+        {
+            for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
+            {
+                //----0ptr?----
+                if (!it)
+                    continue;
+                this->controllers_.push_back(*it);
+            }
+            //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl;
+        }
+        else
+        {
+            if (this->controllers_.empty())
+                return;
+
+            if (this->indexOfCurrentController_ >= this->controllers_.size())
+            {
+                this->indexOfCurrentController_ = 0;
+            }
+            if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
+            {
+                this->numberOfTicksPassedSinceLastActionCall_ = 0;
+            }
+
+            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
+            {
+                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
+                {
+                    if (!this->controllers_.at(this->indexOfCurrentController_))
+                    {
+                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
+                        return;
+                    }
+                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
+                    this->controllers_.at(this->indexOfCurrentController_)->maneuver();
+                }
+                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
+                {
+                    if (!this->controllers_.at(this->indexOfCurrentController_))
+                    {
+                        this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
+                        return;
+                    }
+                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
+                    this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
+                }
+                ++this->numberOfTicksPassedSinceLastActionCall_;
+            }
+            else
+            {
+                if (!this->controllers_.at(this->indexOfCurrentController_))
+                {
+                    this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
+                    return;
+                }
+                //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl;
+                this->controllers_.at(this->indexOfCurrentController_)->action();
+
+                ++this->numberOfTicksPassedSinceLastActionCall_;
+                ++this->indexOfCurrentController_;
+            }
+        }
+    }
+}

Added: code/branches/campaignHS15/src/orxonox/controllers/MasterController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/MasterController.h	                        (rev 0)
+++ code/branches/campaignHS15/src/orxonox/controllers/MasterController.h	2015-12-07 19:45:07 UTC (rev 10954)
@@ -0,0 +1,64 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Gani Aliguzhinov
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MasterController_H__
+#define _MasterController_H__
+
+#include "controllers/FightingController.h"
+#include "tools/interfaces/Tickable.h"
+
+
+
+namespace orxonox
+{
+    class _OrxonoxExport MasterController : public FightingController, public Tickable
+    {
+        public:
+            //----[language demanded functions]----            
+                MasterController(Context* context);
+
+                virtual ~MasterController();
+            //----[/language demanded functions]----            
+
+            //----[orxonox demanded functions]----
+                virtual void tick(float dt); 
+
+            //----[orxonox demanded functions]----
+
+        protected:
+          
+        private:
+            std::vector<WeakPtr<FightingController> > controllers_;
+            size_t indexOfCurrentController_;
+            unsigned int numberOfTicksPassedSinceLastActionCall_;
+            unsigned int ticks_;     //<! local tick counter            
+
+    };
+}
+
+#endif /* _MasterController_H__ */




More information about the Orxonox-commit mailing list