Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 15, 2012, 11:51:58 PM (12 years ago)
Author:
jo
Message:

Merging presentation2011 branch to trunk. Please check for possible bugs.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/controllers/HumanController.cc

    r8858 r9016  
    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 
    7980        HumanController::localController_s = this;
    8081        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
     
    8485    HumanController::~HumanController()
    8586    {
     87        if (HumanController::localController_s)
     88        {
     89            HumanController::localController_s->removeFromFormation();
     90        }
    8691        HumanController::localController_s = 0;
    8792    }
     
    95100                orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl;
    96101        }
     102
     103        // commandslaves when Master of a formation
     104        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     105        {
     106            if (HumanController::localController_s->formationMode_ != ATTACK)
     107                HumanController::localController_s->commandSlaves();
     108        }
    97109    }
    98110
     
    160172    {
    161173        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     174        {
    162175            HumanController::localController_s->controllableEntity_->fire(firemode);
     176            //if human fires, set slaves free. See FormationController::forceFreeSlaves()
     177            if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL)
     178            {
     179                HumanController::localController_s->forceFreeSlaves();
     180            }
     181        }
    163182    }
    164183
     
    195214            this->boosting_ = true;
    196215            this->boostingTimeout_.startTimer();
    197            
    198             this->controllableEntity_->boost(this->boosting_);
     216            if(this->controllableEntity_)
     217                this->controllableEntity_->boost(this->boosting_);
    199218//            orxout() << "Start boosting" << endl;
    200219        }
     
    209228        this->boosting_ = false;
    210229        this->boostingTimeout_.stopTimer();
    211 
    212         this->controllableEntity_->boost(this->boosting_);
     230        if(this->controllableEntity_)
     231            this->controllableEntity_->boost(this->boosting_);
    213232//        orxout() << "Stop boosting" << endl;
    214233    }
     
    262281    }
    263282
     283    /**
     284    @brief
     285       toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_)
     286    */
     287    void HumanController::toggleFormationFlight()
     288    {
     289        if (HumanController::localController_s)
     290        {
     291            if (!HumanController::localController_s->formationFlight_)
     292            {
     293                return; //dont use when formationFlight is disabled
     294            }
     295            if (HumanController::localController_s->state_==MASTER)
     296            {
     297                HumanController::localController_s->loseMasterState();
     298                orxout(message) <<"FormationFlight disabled "<< endl;
     299            } else //SLAVE or FREE
     300            {
     301                HumanController::localController_s->takeLeadOfFormation();
     302                orxout(message) <<"FormationFlight enabled "<< endl;
     303            }
     304           
     305        }
     306
     307    }
     308
     309    /**
     310    @brief
     311       Switch through the different Modes of formationflight. You must be a master of a formation to use.
     312    */
     313    void HumanController::FFChangeMode()
     314    {
     315        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     316        {
     317            switch (HumanController::localController_s->getFormationMode()) {
     318                case NORMAL:
     319                    HumanController::localController_s->setFormationMode(DEFEND);
     320                    orxout(message) <<"Mode: DEFEND "<< endl;
     321                    break;
     322                case DEFEND:
     323                    HumanController::localController_s->setFormationMode(ATTACK);
     324                    orxout(message) <<"Mode: ATTACK "<< endl;
     325                    break;
     326                case ATTACK:
     327                    HumanController::localController_s->setFormationMode(NORMAL);
     328                    orxout(message) <<"Mode: NORMAL "<< endl;
     329                    break;
     330            }
     331        }
     332    }
     333
     334
     335    //used, when slaves are in DEFEND mode.
     336    void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     337    {
     338        if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return;
     339            this->masterAttacked(originator);
     340    }
     341
    264342    void HumanController::addBots(unsigned int amount)
    265343    {
Note: See TracChangeset for help on using the changeset viewer.