Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 26, 2015, 5:44:31 PM (9 years ago)
Author:
gania
Message:

Restructured

Location:
code/branches/AI_HS15/src/orxonox/controllers
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt

    r10678 r10709  
    1313  FleetController.cc
    1414  DivisionController.cc
    15   SectionController.cc
    1615  LeaderController.cc
    1716  WingmanController.cc
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10678 r10709  
    3535    RegisterClass(DivisionController);
    3636
    37     DivisionController::DivisionController(Context* context) : FleetController(context)
     37    DivisionController::DivisionController(Context* context) : LeaderController(context)
    3838    {
    3939        RegisterObject(DivisionController);
     
    4747        }
    4848    }
    49 
     49    void DivisionController::setLeader(LeaderController* leader)
     50    {
     51        this->leader_ = leader;
     52    }
    5053    /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5154    {
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10681 r10709  
    3030#define _DivisionController_H__
    3131
    32 #include "controllers/FleetController.h"
     32#include "controllers/LeaderController.h"
     33
    3334
    3435
    3536namespace orxonox
    3637{
    37     class _OrxonoxExport DivisionController : public FleetController
     38    class _OrxonoxExport DivisionController : public LeaderController
    3839    {
    3940        public:
     
    4849                inline FormationMode getFormationMode() const
    4950                        { return this->formationMode_; }
     51                        virtual void setLeader(LeaderController* leader);
     52
    5053                       
    51                         virtual void doFire();
    52 
    53                         //WAYPOINT FUNCTIONS`
    54             void addWaypoint(WorldEntity* waypoint);
    55             WorldEntity* getWaypoint(unsigned int index) const;
    56 
    57             inline void setAccuracy(float accuracy)
    58                 { this->squaredaccuracy_ = accuracy*accuracy; }
    59             inline float getAccuracy() const
    60                 { return sqrt(this->squaredaccuracy_); }
    61             void updatePointsOfInterest(std::string name, float distance);
    62             void manageWaypoints();
    6354
    6455        protected:
     
    7061                        bool bHasTargetOrientation_;
    7162                        Quaternion targetOrientation_;
    72                         void setTargetPosition(const Vector3& target);
     63                        FormationMode formationMode_;
     64                       
     65                        /*void setTargetPosition(const Vector3& target);
    7366                        void searchRandomTargetPosition();
    7467
     
    7871                        virtual void positionReached() {}
    7972
    80                         static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
    8173
    8274
     
    109101                    void spinInit();
    110102                    void spin();
    111                 void turn180();
     103                void turn180();*/
    112104
    113                 //WAYPOINT DATA
    114                 std::vector<WeakPtr<WorldEntity> > waypoints_;
    115                 size_t currentWaypoint_;
    116                 float squaredaccuracy_;
    117                 WorldEntity* defaultWaypoint_;
     105                LeaderController* leader_;
     106               
     107
    118108           
    119109        private:
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10678 r10709  
    3535    RegisterClass(FleetController);
    3636
    37     FleetController::FleetController(Context* context) : Controller(context)
     37    FleetController::FleetController(Context* context) : FormationController(context)
    3838    {
    3939        RegisterObject(FleetController);
     
    4343        this->goalTarget_ = NULL;
    4444        this->goalProtect_ = NULL;
     45        this->nTicks_ = 0;
     46        this->bTicked_ = false;
     47        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
    4548    }
    4649
     
    5255        }
    5356    }
    54    
     57    void FleetController::action()
     58    {
     59
     60
     61    }
     62    void FleetController::tick(float dt)
     63    {
     64
     65         if (nTicks_ == 30)
     66         {
     67            std::vector<WeakPtr<WingmanController> > wingmen;
     68            std::vector<WeakPtr<LeaderController> > leaders;
     69
     70            //--------------------------Put all WingmanController's in a vector--------------------------
     71            for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it)
     72            {
     73
     74               
     75                if ((*it)->getTeam() == this->getTeam())
     76                {
     77                    orxout(internal_error) << "ANOTHER SUCKER" << endl;
     78                    wingmen.push_back(*it);
     79                }
     80               
     81            }
     82            //--------------------------Substitute half of WingmanController's with LeaderController--------------------------
     83
     84            bool nowLeader = true;
     85            LeaderController* leader;
     86
     87            for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it)
     88            {
     89                if (nowLeader)
     90                {
     91                    leader = new LeaderController(this->getContext());
     92                    leader->setTeam(this->team_);
     93
     94                    (*it)->getControllableEntity()->setController(leader);
     95                    leaders.push_back(leader);
     96                    nowLeader = !nowLeader;
     97                    orxout(internal_error) << "NEW SUCKER" << endl;
     98
     99                }
     100                else
     101                {
     102                    if (leader)
     103                    {
     104                        leader->setWingman(*it);
     105                        nowLeader = !nowLeader;
     106                        orxout(internal_error) << "I OWN THE SUCKER" << endl;
     107
     108                    }
     109                }
     110            }
     111
     112            //--------------------------Substitute half of LeaderController's with DivisionController--------------------------
     113            bool nowDivision = true;
     114            DivisionController* division;
     115
     116            for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it)
     117            {
     118                if (nowDivision)
     119                {
     120                    division = new DivisionController(this->getContext());
     121                    division->setTeam(this->team_);
     122
     123                    (*it)->getControllableEntity()->setController(division);
     124
     125                    divisions_.push_back(division);
     126
     127                    nowDivision = !nowDivision;
     128                }
     129                else
     130                {
     131                    if (division)
     132                    {
     133                        division->setLeader(*it);
     134                        nowDivision = !nowDivision;
     135                    }
     136                }
     137            }
     138            bTicked_ = true;
     139            nTicks_ += 1;
     140         }
     141         else if (!bTicked_)
     142         {
     143            nTicks_ += 1;
     144
     145         }
     146        SUPER(FleetController, tick, dt);
     147
     148    }
    55149    void FleetController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    56150    {
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.h

    r10681 r10709  
    2929#ifndef _FleetController_H__
    3030#define _FleetController_H__
     31#include "controllers/FormationController.h"
    3132
    3233#include "controllers/Controller.h"
     34#include "controllers/DivisionController.h"
     35#include "controllers/LeaderController.h"
     36#include "controllers/WingmanController.h"
    3337
    3438#include "OrxonoxPrereqs.h"
    3539#include "core/class/Super.h"
    3640#include "core/CoreIncludes.h"
    37 #include "core/XMLPort.h"
    38 #include "core/command/ConsoleCommandIncludes.h"
    39 #include "core/command/Executor.h"
     41
    4042
    4143#include <vector>
     
    5153#include "worldentities/pawns/TeamBaseMatchBase.h"
    5254
    53 #include "gametypes/TeamDeathmatch.h"
    54 #include "gametypes/Dynamicmatch.h"
    55 #include "gametypes/Mission.h"
    56 #include "gametypes/Gametype.h"
    57 
    58 #include "controllers/WaypointPatrolController.h"
    59 #include "controllers/NewHumanController.h"
    60 #include "controllers/DroneController.h"
    6155
    6256
     
    6458{   
    6559
    66     class _OrxonoxExport FleetController : public Controller
     60    class _OrxonoxExport FleetController : public FormationController, public Tickable
    6761    {
    6862        public:
     
    7064          virtual ~FleetController();
    7165
     66          virtual void tick(float dt); //<! Carrying out the targets set in action().
    7267
    7368          virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    8075          enum GameGoal {DOMINATE, MOVE, DESTROY, PROTECT};
    8176         
    82           /*void setGameGoal(GameGoal gameGoal)
    83              { this->gameGoal_ = gameGoal; }
    84           GameGoal getGameGoal() const
    85              { return this->gameGoal_; }
    8677         
    87           void setGoalPosition(Vector3* goalPosition)
    88              { this->goalPosition_ = goalPosition; }
    89           Vector3* getGoalPosition() const
    90              { return this->goalPosition_; }
    91          
    92           void setGoalTarget(Pawn* goalTarget)
    93              { this->goalTarget_ = goalTarget; }
    94           Pawn* getGoalTarget() const
    95              { return this->goalTarget_; }
    96          
    97           void setGoalProtect(Pawn* goalProtect)
    98              { this->goalProtect_ = goalProtect; }
    99           Pawn* getGoalProtect() const
    100              { return this->goalProtect_; }*/
    101 
    10278
    10379
     
    11086            WeakPtr<Pawn> goalProtect_;
    11187
     88            virtual void action();
     89        private:
     90            int nTicks_;
     91            bool bTicked_;
     92
     93            std::vector<WeakPtr<DivisionController> > divisions_;
     94            //Timer actionTimer_; //<! Regularly calls action().
    11295
    11396    };
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc

    r10682 r10709  
    3333namespace orxonox
    3434{
    35     const float LeaderController::ACTION_INTERVAL = 1.0f;
    3635
    3736    RegisterClass(LeaderController);
    3837
    39     LeaderController::LeaderController(Context* context) : SectionController(context)
     38    LeaderController::LeaderController(Context* context) : WingmanController(context)
    4039    {
     40
    4141        RegisterObject(LeaderController);
    42         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
     42        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
    4343    }
     44
    4445
    4546    LeaderController::~LeaderController()
     
    4950    void LeaderController::action()
    5051    {
    51        
     52        //this->target_ = this->sectionTarget_;       
    5253    }
    5354    /*
     
    6667    */
    6768    void LeaderController::tick(float dt)
    68     {
     69    {/*
    6970        if (!this->isActive())
    7071            return;
    7172       
    7273        //--------------------------Stay in division--------------------------
    73         this->keepDivisionTick();
     74        this->keepDivisionTick();*/
    7475        /*keepDivisionTick(){
    7576            if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
     
    8081        }
    8182        */
    82         //If ordered to attack -> follow target and shoot
     83        /*//If ordered to attack -> follow target and shoot
    8384        if (this->bAttackOrder_)
    8485        {
    85 
     86 
    8687        }
    8788        //If ordered to move -> move to a target Point
    88         else if (this->bMoveOrder_)
    89         {
    90 
    91         }
    92         else
     89       
    9390        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
    9491        //(Section shoots same target, Boss's section shoots another target)
    9592        {
    9693
    97         }
     94        }*/
    9895
    99 
     96        orxout(internal_error) << "my Wingman is " << this->wingman_ << endl;
     97       
    10098        SUPER(LeaderController, tick, dt);
     99    }
     100    void LeaderController::setWingman(WingmanController* wingman)
     101    {
     102        this->wingman_ = wingman;
    101103    }
    102104//**********************************************NEW
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10682 r10709  
    3030#define _LeaderController_H__
    3131
    32 #include "SectionController.h"
     32#include "controllers/WingmanController.h"
     33
     34
    3335
    3436
    3537namespace orxonox
    3638{
    37     class _OrxonoxExport LeaderController : public SectionController, public Tickable
     39    class _OrxonoxExport LeaderController : public WingmanController
    3840    {
    3941        public:
     
    4143            LeaderController(Context* context);
    4244            virtual ~LeaderController();
    43 
     45            virtual void setWingman(WingmanController* wingman);
    4446            virtual void tick(float dt); //<! Carrying out the targets set in action().
    4547
    4648        protected:
    4749           
    48             enum Mode {KEEPFORMATION, ROCKET, KILLENEMY};
    49             Mode mode_;
     50           
    5051
    5152            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    5253            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.   
     54         
     55        private:
    5356           
     57            WeakPtr<Pawn> target_;
     58           
     59            WingmanController* wingman_;
    5460
    55             //WEAPONSYSTEM DATA
    56             std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
    57             //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
    58             float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
    59             void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
    60             bool bSetupWorked; //<! If false, setupWeapons() is called.
    61             int getFiremode(std::string name);
    62 
    63             void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
    64 
    65         private:
    66             static const float ACTION_INTERVAL;
    67 
    68             Timer actionTimer_; //<! Regularly calls action().
     61            //Timer actionTimer_; //<! Regularly calls action().
    6962               
    7063    };
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10682 r10709  
    3232namespace orxonox
    3333{
    34     const float WingmanController::ACTION_INTERVAL = 1.0f;
    3534
    3635    RegisterClass(WingmanController);
    3736
    38     WingmanController::WingmanController(Context* context) : SectionController(context)
     37    WingmanController::WingmanController(Context* context) : Controller(context)
    3938    {
    4039        RegisterObject(WingmanController);
    41         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
     40        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4241    }
    4342
     
    5554    void WingmanController::action()
    5655    {
    57         //--------------------------Cover Leader's rear--------------------------
    58         //check for enemies in Leader's rear that can attack him and if they are visible, meaning there are no other Leader's between Leader and enemies.
    59         //if there are enemies, set target_ to the nearest one and set bFollowLeader_ to false,
    60         //otherwise set bFollowLeader_ to true and target_ to sectionTarget_
    61         this->coverAllyRear(this->sectionLeader_);
     56        //this->target_ = this->sectionTarget_;
    6257    }
    6358
    6459    void WingmanController::tick(float dt)
    65     {
     60    {/*
    6661        if (!this->isActive())
    6762            return;
     
    6964        if (bFollowLeader_)
    7065        {
    71             this->keepSectionTick();
     66            this->keepSectionTick();*/
    7267            /*keepSectionTick(){
    7368                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
     
    7873            }
    7974            */
    80            
     75          /* 
    8176            //--------------------------Attack same target as the Leader--------------------------
    82            
     77
    8378            if (this->target_)
    8479            {
     
    8681                this->doFire();
    8782            }
    88         }
    89         //--------------------------Protect Leader by killing target_--------------------------
    90 
    91         else
    92         {
    93             if (this->target_)
    94             {
    95                 //--------------------------Don't attack if not visible--------------------------               
    96                 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
    97                 {
    98                     this->forgetTarget();
    99                     //this->bFollowLeader_ = true;
    100                 }
    101                 //--------------------------Otherwise destroy it--------------------------
    102                 else
    103                 {
    104                     this->aimAtTarget();
    105                     this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
    106                 }
    107                 if (this->bHasTargetPosition_)
    108                 {
    109                     this->moveToTargetPosition();
    110                 }
    111                 this->doFire();
    112             }
    113             //--------------------------no target? do nothing until next action() -> either new target appears or bFollowLeader_ set to true--------------------------
    114             else
    115             {
    116 
    117             }           
    118 
    119         }
     83        }*/
     84         //orxout(internal_error) << "I am " << this << endl;
     85       
    12086        SUPER(WingmanController, tick, dt);
    12187    }
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10681 r10709  
    3131
    3232
    33 #include "LeaderController.h"
     33#include "controllers/Controller.h"
     34
     35
     36#include "OrxonoxPrereqs.h"
     37#include "core/class/Super.h"
     38#include "core/CoreIncludes.h"
     39#include "core/XMLPort.h"
     40#include "core/command/ConsoleCommandIncludes.h"
     41#include "core/command/Executor.h"
     42
     43#include <vector>
     44#include "util/Math.h"
     45#include <climits>
     46
     47#include "tools/Timer.h"
     48#include "tools/interfaces/Tickable.h"
     49
     50#include "worldentities/ControllableEntity.h"
     51#include "worldentities/pawns/SpaceShip.h"
     52#include "worldentities/pawns/Pawn.h"
     53#include "worldentities/pawns/TeamBaseMatchBase.h"
     54
     55#include "gametypes/TeamDeathmatch.h"
     56#include "gametypes/Dynamicmatch.h"
     57#include "gametypes/Mission.h"
     58#include "gametypes/Gametype.h"
     59
    3460
    3561
    3662namespace orxonox
    3763{
    38     class _OrxonoxExport WingmanController : public LeaderController
     64    class _OrxonoxExport WingmanController : public Controller, public Tickable
    3965    {
    4066        public:
     
    5177                     
    5278        private:
    53             static const float ACTION_INTERVAL;
     79            //const float ACTION_INTERVAL;
     80           
     81            WeakPtr<Pawn> target_;
     82           
     83            //LeaderController* leader_;
    5484
    55             Timer actionTimer_; //<! Regularly calls action().
     85            //Timer actionTimer_; //<! Regularly calls action().
    5686           
    5787    };
Note: See TracChangeset for help on using the changeset viewer.