Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2015, 12:14:43 PM (9 years ago)
Author:
gania
Message:

improved dodging

File:
1 edited

Legend:

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

    r10885 r10886  
    5959    {
    6060        SUPER(WingmanController, XMLPort, xmlelement, mode);
    61 
    62         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    6361    }
    6462   
     
    6765    {   
    6866        if (!this->isActive())
    69             return;
    70         if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() !=
    71             Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK)
    72         {
    73         }   
     67            return;
    7468       
    7569        SUPER(WingmanController, tick, dt);
     
    108102                || this->myLeader_->getAction() == Action::ATTACK))
    109103            {
    110                 ControllableEntity* myEntity = this->getControllableEntity();
    111                 Vector3 myPosition = myEntity->getWorldPosition();
    112                 if (!this->myLeader_)
    113                 {
    114                     return;
    115                 }
    116                 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
    117                 Quaternion orient = leaderEntity->getWorldOrientation();
    118                 Vector3 leaderPosition = leaderEntity->getWorldPosition();
    119                 Vector3 targetRelativePosition = getFormationPosition();
    120                 if (!this->myLeader_)
    121                 {
    122                     return;
    123                 }
    124                 Vector3 targetAbsolutePosition =
    125                     (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    126                      + (orient* (targetRelativePosition)));
    127                 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    128                 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
    129                     this->setAction (Action::FLY, targetAbsolutePosition, orient);
    130                 else
    131                     this->setAction (Action::FLY, targetAbsolutePosition);
    132                 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    133                 {
    134                     this->boostControl();
    135                 }
    136                 else
    137                 {
    138                    this->getControllableEntity()->boost(false);
    139                 }
    140             }
    141             else
    142             {
    143                 switch (this->myLeader_->getAction())
    144                 {
    145                     case Action::FIGHT:
    146                     {
    147                         if (!this->hasTarget())
    148                         {
    149                             this->setTarget(this->myLeader_->getTarget());
    150                         }
    151                         break;
    152                     }
    153                     case Action::FIGHTALL:
    154                     {
    155                         if (!this->hasTarget())
    156                         {
    157                             this->setTarget(this->myLeader_->getTarget());
    158                         }
    159                         break;
    160                     }
    161                     case Action::ATTACK:
    162                     {
    163                         if (!this->hasTarget())
    164                         {
    165                             this->setTarget(this->myLeader_->getTarget());
    166                         }
    167                         break;
    168                     }
    169                     default:
    170                     {
    171                    
    172                     }
     104                this->keepFormation();
     105            }
     106            else if (!this->myLeader_->bKeepFormation_)
     107            {
     108                if (!this->hasTarget())
     109                {
     110                    this->setTarget(this->myLeader_->getTarget());
    173111                }
    174112                if (this->hasTarget())
     
    180118                }
    181119            }
    182            
    183            
    184120        }
    185121        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     
    236172        delete targetRelativePosition;
    237173        return result;
     174    }
     175    void WingmanController::keepFormation()
     176    {
     177        this->bKeepFormation_ = true;
     178        ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
     179        Vector3 targetRelativePosition = this->getFormationPosition();
     180        if (!leaderEntity)
     181            return;
     182        FlyingController::keepFormation (leaderEntity, targetRelativePosition);
    238183    }
    239184    //----POST: closest leader that is ready to take a new wingman is returned----
     
    268213                minDistance = distance;
    269214            }
    270            
    271215        }
    272216        if (closestLeader)
     
    277221                return closestLeader;
    278222            }
    279 
    280         }
    281 
     223        }
    282224        return 0;
    283225    }
    284226
    285 
    286 
    287 
    288227}
Note: See TracChangeset for help on using the changeset viewer.