Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

formationflight as good as finished for now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.