Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 28, 2015, 11:46:05 AM (8 years ago)
Author:
gania
Message:

ships spread before fight

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10881 r10883  
    124124        else if (myDivisionLeader_)
    125125        {
    126             switch (myDivisionLeader_->getAction())
    127             {
    128                 case Action::FIGHT:
    129                 {
    130                     if (!this->hasTarget())
    131                     {
    132                         this->chooseTarget();
    133                     }
    134                     break;
    135                 }
    136                 case Action::FIGHTALL:
    137                 {
    138                     if (!this->hasTarget())
    139                     {
    140                         this->chooseTarget();
    141                     }
    142                     break;
    143                 }
    144                 case Action::ATTACK:
    145                 {
    146                     if (!this->hasTarget())
    147                     {
    148                         this->chooseTarget();
    149                     }
    150                     break;
    151                 }
    152                 default:
    153                 {
    154                     //formation flight is executed in tick
    155                     ControllableEntity* myEntity = this->getControllableEntity();
    156             Vector3 myPosition = myEntity->getWorldPosition();
    157             if (!this->myDivisionLeader_)
    158             {
    159                 return;
    160             }
    161             ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
    162             Quaternion orient = leaderEntity->getWorldOrientation();
    163             Vector3 leaderPosition = leaderEntity->getWorldPosition();
    164 
    165             Vector3 targetRelativePosition = getFormationPosition();
    166             if (!this->myDivisionLeader_)
    167             {
    168                 return;
    169             }
    170             Vector3 targetAbsolutePosition =
    171                 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    172                  + (orient* (targetRelativePosition)));
    173             //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    174             if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
    175                 this->setAction (Action::FLY, targetAbsolutePosition, orient);
     126            if (this->myDivisionLeader_->bKeepFormation_ || !(this->myDivisionLeader_->getAction() == Action::FIGHT
     127                || this->myDivisionLeader_->getAction() == Action::FIGHTALL
     128                || this->myDivisionLeader_->getAction() == Action::ATTACK))
     129            {
     130                ControllableEntity* myEntity = this->getControllableEntity();
     131                Vector3 myPosition = myEntity->getWorldPosition();
     132                if (!this->myDivisionLeader_)
     133                {
     134                    return;
     135                }
     136                ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
     137                Quaternion orient = leaderEntity->getWorldOrientation();
     138                Vector3 leaderPosition = leaderEntity->getWorldPosition();
     139
     140                Vector3 targetRelativePosition = getFormationPosition();
     141                if (!this->myDivisionLeader_)
     142                {
     143                    return;
     144                }
     145                Vector3 targetAbsolutePosition =
     146                    (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
     147                     + (orient* (targetRelativePosition)));
     148                //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
     149                if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
     150                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
     151                else
     152                    this->setAction (Action::FLY, targetAbsolutePosition);
     153
     154                if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
     155                {
     156                    this->boostControl();
     157                }
     158                else
     159                {
     160                   this->getControllableEntity()->boost(false);
     161                }
     162            }
    176163            else
    177                 this->setAction (Action::FLY, targetAbsolutePosition);
    178 
    179             if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    180             {
    181                 this->boostControl();
    182             }
    183             else
    184             {
    185                this->getControllableEntity()->boost(false);
    186             }
    187                 }
    188             }
    189             if (this->hasTarget())
    190             {
    191                 //----choose where to go----
    192                 this->maneuver();
    193                 //----fire if you can----
    194                 this->bShooting_ = this->canFire();               
    195             }
     164            {
     165                switch (myDivisionLeader_->getAction())
     166                {
     167                    case Action::FIGHT:
     168                    {
     169                        if (!this->hasTarget())
     170                        {
     171                            this->chooseTarget();
     172                        }
     173                        break;
     174                    }
     175                    case Action::FIGHTALL:
     176                    {
     177                        if (!this->hasTarget())
     178                        {
     179                            this->chooseTarget();
     180                        }
     181                        break;
     182                    }
     183                    case Action::ATTACK:
     184                    {
     185                        if (!this->hasTarget())
     186                        {
     187                            this->chooseTarget();
     188                        }
     189                        break;
     190                    }
     191                    default:
     192                    {
     193                        //formation flight is executed in tick
     194                    }
     195                }
     196                if (this->hasTarget())
     197                {
     198                    //----choose where to go----
     199                    this->maneuver();
     200                    //----fire if you can----
     201                    this->bShooting_ = this->canFire();               
     202                }
     203            }
     204           
     205           
    196206        }
    197207        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     
    263273    {
    264274        this->setFormationMode( this->myDivisionLeader_->getFormationMode() );
     275        this->spread_ = this->myDivisionLeader_->getSpread();
    265276        Vector3* targetRelativePosition;
    266277        switch (this->formationMode_){
Note: See TracChangeset for help on using the changeset viewer.