Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6997


Ignore:
Timestamp:
May 27, 2010, 10:47:23 PM (14 years ago)
Author:
solex
Message:

formationflight as good as finished for now

Location:
code/branches/ai/src/orxonox/controllers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai/src/orxonox/controllers/AIController.cc

    r6978 r6997  
    128128            if  (this->specificMasterAction_ != NONE)
    129129            {
    130                 if (this->specificMasterAction_  == HOLD)
    131130                    this->specificMasterActionHold();
    132131
    133                 if (this->specificMasterAction_  == TURN180)
    134                     this->turn180();
    135 
    136                 if (this->specificMasterAction_ == SPIN)
    137                     this->spin();
     132//                 if (this->specificMasterAction_  == TURN180)
     133//                     this->turn180Init();
     134
     135//                 if (this->specificMasterAction_ == SPIN)
     136//                     this->spinInit();
    138137
    139138//                 if (this->specificMasterAction_ == FOLLOWHUMAN)
     
    144143
    145144                 // make 180 degree turn - a specific Master Action
    146                 random = rnd(maxrand);
     145                random = rnd(1000.0f);
    147146                if (random < 5)
    148                    this->specificMasterAction_ = TURN180;
     147                   this->turn180Init();
    149148
    150149                // spin around - a specific Master Action
    151                 random = rnd(maxrand);
     150                random = rnd(1000.0f);
    152151                if (random < 5)
    153                    this->specificMasterAction_ = SPIN;
     152                   this->spinInit();
    154153
    155154                 // lose master status (only if less than 4 slaves in formation)
     
    191190                // shoot
    192191                random = rnd(maxrand);
    193                 if (!(this->passive_) && random < 15 && (this->target_ && !this->bShooting_))
     192                if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
    194193                {
    195194                this->bShooting_ = true;
     
    214213        if (this->state_ == MASTER)
    215214        {
     215            if (this->specificMasterAction_ ==  NONE)
     216            {
     217                if (this->target_)
     218                    this->aimAtTarget();
     219
     220                if (this->bHasTargetPosition_)
     221                    this->moveToTargetPosition();
     222
     223                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     224                    this->getControllableEntity()->fire(0);
     225            }
     226
     227            if (this->specificMasterAction_  == TURN180)
     228                    this->turn180();
     229
     230            if (this->specificMasterAction_ == SPIN)
     231                    this->spin();
     232        }
     233
     234        if (this->state_ == SLAVE)
     235        {
     236
     237            if (this->bHasTargetPosition_)
     238                this->moveToTargetPosition();
     239
     240        }
     241
     242         if (this->state_ == FREE)
     243        {
    216244            if (this->target_)
    217245                this->aimAtTarget();
     
    219247            if (this->bHasTargetPosition_)
    220248                this->moveToTargetPosition();
    221             if (this->specificMasterAction_ ==  NONE)
    222             {
    223                 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    224                     this->getControllableEntity()->fire(0);
    225             }
    226         }
    227 
    228         if (this->state_ == SLAVE)
    229         {
    230 
    231             if (this->bHasTargetPosition_)
    232                 this->moveToTargetPosition();
    233 
    234         }
    235 
    236          if (this->state_ == FREE)
    237         {
    238             if (this->target_)
    239                 this->aimAtTarget();
    240 
    241             if (this->bHasTargetPosition_)
    242                 this->moveToTargetPosition();
    243249
    244250            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r6991 r6997  
    5151
    5252    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
    53     static const int FORMATION_LENGTH =  10;
     53    static const int FORMATION_LENGTH =  130;
    5454    static const int FORMATION_WIDTH =  110;
    5555    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     
    112112            {
    113113                aiController->formationFlight_ = form;
     114                if(!form)
     115                {
     116                    if(aiController->state_ == MASTER) aiController->freeSlaves();
     117                    aiController->state_ = FREE;
     118                }
    114119            }
    115120        }
     
    120125        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
    121126    */
    122     void ArtificialController::masteraction(int action) 
     127    void ArtificialController::masteraction(int action)
    123128    {
    124129        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     
    129134            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
    130135
    131             if(aiController || aiController->state_ == MASTER)
     136            if(aiController && aiController->state_ == MASTER)
    132137            {
    133138                if (action == 1)
    134                     aiController->specificMasterAction_ = TURN180;
     139                    aiController->spinInit();
    135140                if (action == 2)
    136                     aiController->specificMasterAction_ = SPIN;
     141                    aiController->turn180Init();
    137142            }
    138143        }
     
    271276            if (this->target_ || distance > 10)
    272277            {
    273                 if (this->specificMasterAction_ == NONE)
    274                 {
    275278                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    276279                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
    277                 } else if (this->specificMasterAction_ == TURN180)
    278                 {
    279                 this->getControllableEntity()->rotateYaw(-1.0f * sgn(coord.x) * coord.x*coord.x);
    280                 this->getControllableEntity()->rotatePitch(sgn(coord.y) * coord.y*coord.y);
    281                 }
    282 
    283280            }
    284281
     
    416413            {
    417414                pos = Vector3::ZERO;
    418                 if (i <= 1) pos += dest  + FORMATION_WIDTH*WorldEntity::LEFT;
    419                 if (i == 2) pos += dest  + FORMATION_WIDTH*WorldEntity::RIGHT;
    420                 if (i == 3) pos += dest  + FORMATION_WIDTH*WorldEntity::UP;
     415                if (i <= 1) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::LEFT);
     416                if (i == 2) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
     417                if (i == 3) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::UP);
    421418                if (i >= 4)
    422419                {
    423                     pos += dest  + FORMATION_WIDTH*WorldEntity::DOWN;
     420                    pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::DOWN);
    424421                    i = 1;
    425                     dest += FORMATION_LENGTH*orient*WorldEntity::BACK;
     422                    dest += FORMATION_LENGTH*(orient*WorldEntity::BACK);
    426423                    (*it)->setTargetPosition(pos);
    427424                    continue;
     
    518515
    519516    /**
    520         @brief Used to continue a "specific master action" for a certain time.
     517        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
    521518    */
    522519    void ArtificialController::specificMasterActionHold()
     
    533530
    534531    /**
    535         @brief Master engages a 180 degree turn. Is a "specific master action".
     532        @brief Master initializes a 180 degree turn. Leads to a "specific master action".
     533    */
     534    void ArtificialController::turn180Init()
     535    {
     536        COUT(0) << "~turnInit" << std::endl;
     537        if(this->state_ != MASTER) return;
     538
     539        Quaternion orient = this->getControllableEntity()->getOrientation();
     540
     541        this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
     542
     543        this->specificMasterActionHoldCount_ = 4;
     544
     545        this->specificMasterAction_ = TURN180;
     546    }
     547
     548    /**
     549        @brief Execute the 180 degree turn. Called within tick.
    536550    */
    537551    void ArtificialController::turn180()
    538552    {
     553            Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     554
     555            this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     556            this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     557
     558            this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     559    }
     560
     561    /**
     562        @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action". Not yet implemented.
     563    */
     564    void ArtificialController::spinInit()
     565    {
     566         COUT(0) << "~spinInit" << std::endl;
    539567        if(this->state_ != MASTER) return;
    540 
    541         COUT(0) << "~turn" << std::endl;
    542 
    543         Quaternion orient = this->getControllableEntity()->getOrientation();
    544 
    545         this->setTargetPosition(this->getControllableEntity()->getPosition() + 500.0f*orient*WorldEntity::BACK);
    546         this->specificMasterActionHoldCount_ = 2;
    547         this->specificMasterAction_  =  HOLD;
    548     }
    549 
    550     /**
    551         @brief Master spins around its looking direction axis. Is a "specific master action". Not yet implemented.
     568        this->specificMasterAction_ = SPIN;
     569        this->specificMasterActionHoldCount_ = 10;
     570    }
     571
     572    /**
     573        @brief Execute the spin. Called within tick.
    552574    */
    553575    void ArtificialController::spin()
    554576    {
    555         if(this->state_ != MASTER) return;
    556 
    557         this->specificMasterAction_  =  NONE;
     577            this->moveToTargetPosition();
     578            this->getControllableEntity()->rotateRoll(0.8f);
    558579    }
    559580
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6986 r6997  
    7171            bool formationFlight_;
    7272            bool passive_;
    73             int maxFormationSize_;
     73            unsigned int maxFormationSize_;
    7474            int freedomCount_;
    7575            enum State {SLAVE, MASTER, FREE};
     
    101101
    102102            void specificMasterActionHold();
     103            void turn180Init();
    103104            void turn180();
     105            void spinInit();
    104106            void spin();
    105107            void followHuman(Pawn* humanController, bool always);
Note: See TracChangeset for help on using the changeset viewer.