Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8953


Ignore:
Timestamp:
Nov 30, 2011, 4:09:25 PM (12 years ago)
Author:
willis
Message:

added different Modes, debugging

Location:
code/branches/formation
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/formation/data/defaultConfig/keybindings.ini

    r8943 r8953  
    7272KeyNumRow0=
    7373KeyNumRow1="toggleFormationFlight"
    74 KeyNumRow2=
     74KeyNumRow2="FFChangeMode"
    7575KeyNumRow3=
    7676KeyNumRow4=
  • code/branches/formation/src/orxonox/controllers/AIController.cc

    r8729 r8953  
    116116        }
    117117
    118         if (this->state_ == SLAVE)
    119         {
     118        if (this->state_ == SLAVE && this->mode_==ATTACK)
     119        {
     120            if (!this->target_)
     121            {
     122               this->searchNewTarget();
     123            }
     124
     125            // shoot
     126            random = rnd(maxrand);
     127            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
     128                this->bShooting_ = true;
     129
     130            // stop shooting
     131            random = rnd(maxrand);
     132            if (random < 25 && (this->bShooting_))
     133                this->bShooting_ = false;
    120134
    121135        }
     
    142156                   this->spinInit();
    143157
    144                 // follow a randomly chosen human - a specific Master Action
     158                /*// follow a randomly chosen human - a specific Master Action
    145159                random = rnd(1000.0f);
    146160                if (random < 1)
    147161                   this->followRandomHumanInit();
    148 
     162*/
    149163                 // lose master status (only if less than 4 slaves in formation)
    150164                random = rnd(maxrand);
     
    233247        }
    234248
    235         if (this->state_ == SLAVE)
     249        if (this->state_ == SLAVE && this->mode_!=ATTACK)
    236250        {
    237251
     
    241255        }
    242256
    243          if (this->state_ == FREE)
     257         if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
    244258        {
    245259            if (this->target_)
  • code/branches/formation/src/orxonox/controllers/ArtificialController.cc

    r8939 r8953  
    2828
    2929#include "ArtificialController.h"
    30 
    31 #include <vector>
    32 
    33 
    34 #include "util/Math.h"
    3530#include "core/CoreIncludes.h"
    36 #include "core/XMLPort.h"
    37 #include "core/command/ConsoleCommand.h"
    38 #include "worldentities/ControllableEntity.h"
    3931#include "worldentities/pawns/Pawn.h"
    40 #include "worldentities/pawns/TeamBaseMatchBase.h"
    41 #include "gametypes/TeamDeathmatch.h"
    42 #include "gametypes/Dynamicmatch.h"
    4332
    4433
  • code/branches/formation/src/orxonox/controllers/ArtificialController.h

    r8939 r8953  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <vector>
    35 
    36 #include "util/Math.h"
    37 #include "Controller.h"
    38 #include "controllers/NewHumanController.h"
    3933#include "controllers/Masterable.h"
    4034
  • code/branches/formation/src/orxonox/controllers/HumanController.cc

    r8948 r8953  
    5151    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
    5252    SetConsoleCommand("HumanController", "toggleFormationFlight",  &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
     53    SetConsoleCommand("HumanController", "FFChangeMode",  &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
    5354    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5455    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
     
    105106        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
    106107        {
    107             HumanController::localController_s->commandSlaves();
     108            if (HumanController::localController_s->mode_!=ATTACK)
     109                HumanController::localController_s->commandSlaves();
    108110        }
    109111    }
     
    274276    }
    275277
     278    /**
     279    @brief
     280       toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_)
     281    */
    276282    void HumanController::toggleFormationFlight()
    277283    {
    278        
    279         if (HumanController::localController_s)
    280         {
     284        if (HumanController::localController_s)
     285        {
     286            if (!HumanController::localController_s->formationFlight_)
     287            {
     288                return; //dont use when formationFlight is disabled
     289            }
    281290            if (HumanController::localController_s->state_==MASTER)
    282291            {
    283                 HumanController::localController_s->freeSlaves();
    284                 HumanController::localController_s->state_=FREE;
     292                HumanController::localController_s->loseMasterState();
    285293                orxout(message) <<"FormationFlight disabled "<< endl;
    286294            } else //SLAVE or FREE
     
    294302    }
    295303
     304    /**
     305    @brief
     306       Switch through the different Modes of formationflight. You must be a master of a formation to use.
     307    */
     308    void HumanController::FFChangeMode()
     309    {
     310        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     311        {
     312            switch (HumanController::localController_s->getMode()) {
     313              case NORMAL:
     314                HumanController::localController_s->setMode(DEFEND);
     315                orxout(message) <<"Mode: DEFEND "<< endl;
     316                break;
     317              case DEFEND:
     318                HumanController::localController_s->setMode(ATTACK);
     319                orxout(message) <<"Mode: ATTACK "<< endl;
     320                break;
     321              case ATTACK:
     322                HumanController::localController_s->setMode(NORMAL);
     323                orxout(message) <<"Mode: NORMAL "<< endl;
     324                break;
     325            }
     326            changedMode();
     327        }
     328    }
     329
     330    void HumanController::changedMode()
     331    {
     332
     333    }
     334   
    296335    void HumanController::addBots(unsigned int amount)
    297336    {
  • code/branches/formation/src/orxonox/controllers/HumanController.h

    r8948 r8953  
    7474            void keepBoosting(void);
    7575            void terminateBoosting(void);
    76            
     76                 
     77
    7778            static void greet();
    7879            static void switchCamera();
     
    8687
    8788            static void toggleFormationFlight();
     89            static void FFChangeMode();
     90            static void changedMode();
    8891
    8992            static void addBots(unsigned int amount);
  • code/branches/formation/src/orxonox/controllers/Masterable.cc

    r8948 r8953  
    5757
    5858
    59   static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
    60   static const int RADIUS_TO_SEARCH_FOR_MASTERS = 20000;
     59  static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
     60  static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
    6161  static const int FORMATION_LENGTH =  110;
    6262  static const int FORMATION_WIDTH =  110;
     
    7979
    8080        this->state_ = FREE;
     81        this->mode_ = NORMAL;
    8182        this->specificMasterAction_ = NONE;
    8283        this->specificMasterActionHoldCount_  = 0;
     
    444445            this->state_ = MASTER;
    445446            this->myMaster_ = 0;
    446             orxout(debug_output) << "search new master: no master found, but teammates"<< endl;
    447         }
     447            orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl;
     448        } else if (this->state_ != SLAVE)
     449            orxout(debug_output) << "search new master: no master found, no teammates..."<< endl;
    448450    }
    449451 /**
     
    589591        if (this->state_==FREE)
    590592        {
    591           /*
    592             float minDistance=(float)RADIUS_TO_SEARCH_FOR_MASTERS;
    593             Masterable* bestMaster=NULL;
    594 
    595             //search nearest Master, store in bestMaster
    596             for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    597             {
    598            
    599                 //same team?  (doesnt work with a HumanPlayer??!?) TODO
    600                 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
    601                     continue;
    602 
    603                 //get Controller
    604                 Controller* controller = 0;
    605 
    606                 if (it->getController())
    607                     controller = it->getController();
    608                 else if (it->getXMLController())
    609                     controller = it->getXMLController();
    610 
    611                 if (!controller)
    612                     continue;
    613 
    614                 //myself?
    615                 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
    616                     continue;
    617 
    618                 Masterable *newMaster = orxonox_cast<Masterable*>(controller);
    619                 if (!newMaster || newMaster->state_!=MASTER) continue;
    620                
    621                 float distance= (it->getPosition() - this->getControllableEntity()->getPosition()).length();
    622                
    623                 if (distance<minDistance)
    624                 {
    625                     minDistance=distance;
    626                     bestMaster=newMaster;
    627                 }
    628             }
    629 
    630             if (bestMaster!=NULL)
    631             {
    632                 //becom slave of formation
    633                 bestMaster->slaves_.push_back(this);
    634                 this->state_=SLAVE;
    635                 this->myMaster_=bestMaster;
    636             }
    637             else
    638             {
    639               //no formation found to lead, become master of empty formation
    640               this->state_=MASTER;
    641               this->slaves_.clear();
    642               this->myMaster_=0;
    643               orxout(debug_output) << this << "no formation found!, empty formation"<< endl;
    644               return;
    645             }
    646          */
    647593          searchNewMaster();
    648594        }
     
    681627
    682628    /**
     629      @brief Sets the new mode. If master, set it for all slaves.
     630    */
     631    void Masterable::setMode(Mode val)
     632    {
     633        this->mode_=val;
     634        if (this->state_==MASTER)
     635        {
     636            for(std::vector<Masterable*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     637            {
     638                 (*it)->mode_=val;
     639                 if (val==ATTACK)
     640                     (*it)->forgetTarget();
     641            }
     642        }
     643    }
     644
     645    /**
    683646        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
    684647    */
     
    935898    }
    936899
    937 
    938 
    939 
    940 
    941   void Masterable::setMode(Mode mode)
    942   {
    943      for (std::vector<Masterable*>::iterator it=slaves_.begin(); it != slaves_.end(); it++)
    944      {
    945         //(*it)->myMode_=mode;
    946      }
    947   }
    948 
    949   Masterable::Mode Masterable::getMode()
    950   {
    951     return Masterable::NORMAL;
    952   }
    953 
    954 
    955900  bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    956901    {
     
    992937            if (entity2->getPlayer())
    993938                team2 = tdm->getTeam(entity2->getPlayer());
     939            return (team1 == team2 && team1 != -1); //temp solution
    994940        }
    995941
  • code/branches/formation/src/orxonox/controllers/Masterable.h

    r8939 r8953  
    8888      */
    8989      enum Mode {NORMAL,DEFEND,ATTACK};
     90     
    9091      /**
    91         @brief set a mode in formation
    92       */
    93       void setMode(Mode mode);
    94        /**
    95         @brief get the current mode
     92        @brief Sets the new mode. If master, set it for all slaves.
    9693      */
    97       Mode getMode();
    98      
     94      void setMode(Mode val);
     95      inline Mode getMode() const
     96           { return this->mode_; }
     97
    9998    protected:
    10099      bool formationFlight_;
     
    104103      int freedomCount_;
    105104      enum State {SLAVE, MASTER, FREE};
     105     
    106106      State state_;
    107107      std::vector<Masterable*> slaves_;
    108108      Masterable* myMaster_;
     109
     110      Mode mode_;
    109111
    110112      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
Note: See TracChangeset for help on using the changeset viewer.