Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2011, 8:36:41 PM (12 years ago)
Author:
jo
Message:

Merged Formation branch. There are still some bugs (just have a look at the tutorial level)

Location:
code/branches/presentation2011
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2011

  • code/branches/presentation2011/src/orxonox/controllers/HumanController.cc

    r8980 r8992  
    5050    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
    5151    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
     52    SetConsoleCommand("HumanController", "toggleFormationFlight",  &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
     53    SetConsoleCommand("HumanController", "FFChangeMode",  &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
    5254    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5355    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
     
    6971    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
    7072
    71     HumanController::HumanController(BaseObject* creator) : Controller(creator)
     73    HumanController::HumanController(BaseObject* creator) : FormationController(creator)
    7274    {
    7375        RegisterObject(HumanController);
     
    7678        this->boosting_ = false;
    7779        this->boosting_ = false;
    78 
     80        this->tempMaster=NULL;
    7981        HumanController::localController_s = this;
    8082        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
    8183        this->boostingTimeout_.stopTimer();
     84        this->state_=FREE;
    8285    }
    8386
    8487    HumanController::~HumanController()
    8588    {
     89        if (HumanController::localController_s)
     90        {
     91            HumanController::localController_s->removeFromFormation();
     92        }
    8693        HumanController::localController_s = 0;
    8794    }
     
    95102                orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl;
    96103        }
     104
     105        // commandslaves when Master of a formation
     106        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     107        {
     108            if (HumanController::localController_s->formationMode_ != ATTACK)
     109                HumanController::localController_s->commandSlaves();
     110        }
    97111    }
    98112
     
    160174    {
    161175        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     176        {
    162177            HumanController::localController_s->controllableEntity_->fire(firemode);
     178            //if human fires, set slaves free. See FormationController::forceFreeSlaves()
     179            if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL)
     180            {
     181                HumanController::localController_s->forceFreeSlaves();
     182            }
     183        }
    163184    }
    164185
     
    262283    }
    263284
     285    /**
     286    @brief
     287       toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_)
     288    */
     289    void HumanController::toggleFormationFlight()
     290    {
     291        if (HumanController::localController_s)
     292        {
     293            if (!HumanController::localController_s->formationFlight_)
     294            {
     295                return; //dont use when formationFlight is disabled
     296            }
     297            if (HumanController::localController_s->state_==MASTER)
     298            {
     299                HumanController::localController_s->loseMasterState();
     300                orxout(message) <<"FormationFlight disabled "<< endl;
     301            } else //SLAVE or FREE
     302            {
     303                HumanController::localController_s->takeLeadOfFormation();
     304                orxout(message) <<"FormationFlight enabled "<< endl;
     305            }
     306           
     307        }
     308
     309    }
     310
     311    /**
     312    @brief
     313       Switch through the different Modes of formationflight. You must be a master of a formation to use.
     314    */
     315    void HumanController::FFChangeMode()
     316    {
     317        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     318        {
     319            switch (HumanController::localController_s->getFormationMode()) {
     320                case NORMAL:
     321                    HumanController::localController_s->setFormationMode(DEFEND);
     322                    orxout(message) <<"Mode: DEFEND "<< endl;
     323                    break;
     324                case DEFEND:
     325                    HumanController::localController_s->setFormationMode(ATTACK);
     326                    orxout(message) <<"Mode: ATTACK "<< endl;
     327                    break;
     328                case ATTACK:
     329                    HumanController::localController_s->setFormationMode(NORMAL);
     330                    orxout(message) <<"Mode: NORMAL "<< endl;
     331                    break;
     332            }
     333        }
     334    }
     335
     336
     337    //used, when slaves are in DEFEND mode.
     338    void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     339    {
     340        if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return;
     341            this->masterAttacked(originator);
     342    }
     343
    264344    void HumanController::addBots(unsigned int amount)
    265345    {
Note: See TracChangeset for help on using the changeset viewer.