Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6986 for code/branches/ai


Ignore:
Timestamp:
May 27, 2010, 7:52:28 PM (14 years ago)
Author:
solex
Message:

nearly finished formationflight

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

Legend:

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

    r6978 r6986  
    4747    SetConsoleCommand(ArtificialController, masteraction, true);
    4848    SetConsoleCommand(ArtificialController, followme, true);
    49     SetConsoleCommand(ArtificialController, passivbehaviour, true);
    50 
    51     static const unsigned int MAX_FORMATION_SIZE = 7;
     49    SetConsoleCommand(ArtificialController, passivebehaviour, true);
     50    SetConsoleCommand(ArtificialController, formationsize, true);
     51
     52    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
    5253    static const int FORMATION_LENGTH =  10;
    5354    static const int FORMATION_WIDTH =  110;
     
    5758    static const float SPEED_FREE = 0.8f;
    5859    static const float ROTATEFACTOR_FREE = 0.8f;
    59     static const int SECONDS_TO_FOLLOW_HUMAN = 10;
     60    static const int SECONDS_TO_FOLLOW_HUMAN = 100;
    6061
    6162    ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
     
    6667        this->formationFlight_ = true;
    6768        this->passive_ = false;
     69        this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
    6870        this->myMaster_ = 0;
    6971        this->freedomCount_ = 0;
     
    105107                continue;
    106108
    107             ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     109            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
    108110
    109111            if(aiController)
     
    115117
    116118    /**
    117         @brief Get all masters to do a specific action
     119        @brief Get all masters to do a "specific master action"
    118120        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
    119121    */
     
    125127                continue;
    126128
    127             ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     129            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
    128130
    129131            if(aiController || aiController->state_ == MASTER)
    130132            {
    131                 aiController->specificMasterAction_ = TURN180;
    132             }
    133         }
    134     }
    135 
    136     /**
    137         @brief A human player gets followed by its nearest master. Initiated by console command, only for demonstration puproses. Does not work at the moment.
     133                if (action == 1)
     134                    aiController->specificMasterAction_ = TURN180;
     135                if (action == 2)
     136                    aiController->specificMasterAction_ = SPIN;
     137            }
     138        }
     139    }
     140
     141    /**
     142        @brief A human player gets followed by its nearest master. Initiated by console command, intended for demonstration puproses. Does not work at the moment.
    138143    */
    139144    void ArtificialController::followme()
     
    149154                continue;
    150155
    151             currentHumanController = static_cast<NewHumanController*>(it->getController());
     156            currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
    152157
    153158            if(currentHumanController) humanPawn = *it;
    154159
    155             ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     160            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
    156161
    157162            if(aiController || aiController->state_ == MASTER)
     
    159164
    160165        }
    161         /*if((humanPawn != NULL) && (allMasters.size != 0))
    162         {
    163 
     166
     167        if((humanPawn != NULL) && (allMasters.size() != 0))
     168        {
    164169                float posHuman = humanPawn->getPosition().length();
    165170                float distance = 0.0f;
    166                 float minDistance = posHuman - allMasters.back()->getControllableEntity()->getPosition().length();
     171                float minDistance = FLT_MAX;
    167172                int index = 0;
    168173                int i = 0;
     
    173178                        if(distance < minDistance) index = i;
    174179                    }
    175                 allMasters[index].humanToFollow_ = humanPawn;
    176                 allMasters[index].followHuman(humanPawn, false);
    177             }*/
    178 
    179     }
    180 
    181     /**
    182         @brief Sets shootingbehaviour of pawns.
    183         @param passive if true, pawns won't shoot.
     180                allMasters[index]->humanToFollow_ = humanPawn;
     181                allMasters[index]->followHuman(humanPawn, false);
     182            }
     183
     184    }
     185
     186    /**
     187        @brief Sets shooting behaviour of pawns.
     188        @param passive if true, bots won't shoot.
    184189    */
    185190    void ArtificialController::passivebehaviour(bool passive)
    186191    {
    187         this->passive_ = passive;
     192        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     193        {
     194            if (!it->getController())
     195                continue;
     196
     197            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
     198
     199            if(aiController)
     200            {
     201                aiController->passive_ = passive;
     202            }
     203        }
     204    }
     205
     206
     207    /**
     208        @brief Sets maximal formation size
     209        @param size maximal formation size.
     210    */
     211    void ArtificialController::formationsize(int size)
     212    {
     213        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     214        {
     215            if (!it->getController())
     216                continue;
     217
     218            ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController());
     219
     220            if(aiController)
     221            {
     222                aiController->maxFormationSize_ = size;
     223            }
     224        }
    188225    }
    189226
     
    317354
    318355            //is pawn oneself?
    319             if (static_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     356            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
    320357                continue;
    321358
    322359            teamSize++;
    323360
    324             ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());
     361            ArtificialController *newMaster = orxonox_cast<ArtificialController*>(it->getController());
    325362
    326363            //is it a master?
     
    333370            if (distance < 5000)
    334371            {
    335                 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue;
     372                if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
    336373
    337374                for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
     
    451488            (*it)->targetPosition_ = this->targetPosition_;
    452489            (*it)->bShooting_ = true;
    453             (*it)->getControllableEntity()->fire(0);// fire once for fun
     490//             (*it)->getControllableEntity()->fire(0);// fire once for fun
    454491        }
    455492    }
     
    512549
    513550    /**
    514         @brief Master spins around looking directions axis. Is a "specific master action".
     551        @brief Master spins around its looking direction axis. Is a "specific master action". Not yet implemented.
    515552    */
    516553    void ArtificialController::spin()
     
    524561        @brief Master begins to follow a human player. Is a "specific master action".
    525562        @param humanController human to follow.
    526         @param alaways follows human forever if true - yet only inplemented for false.
     563        @param alaways follows human forever if true - only inplemented for false yet.
    527564    */
    528565    void ArtificialController::followHuman(Pawn* human, bool always)
     
    607644        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    608645
    609         Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());
     646        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    610647        if (pawn)
    611648            pawn->setAimPosition(this->targetPosition_);
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6978 r6986  
    6363            static void masteraction(int action);
    6464            static void followme();
     65            static void passivebehaviour(bool passive);
     66            static void formationsize(int size);
    6567
    6668        protected:
     
    6870            int team_;
    6971            bool formationFlight_;
     72            bool passive_;
     73            int maxFormationSize_;
    7074            int freedomCount_;
    7175            enum State {SLAVE, MASTER, FREE};
  • code/branches/ai/src/orxonox/controllers/NewHumanController.cc

    r6502 r6986  
    298298            //y is down positive
    299299            relativeHit.normalise();
    300 
     300COUT(0) << (int)this->showDamageOverlay_ << " / " << this->damageOverlayLeft_ << " / " << this->damageOverlayRight_ << std::endl;
    301301            float threshold = 0.3f;
    302302            if (relativeHit.x > threshold) // Left
Note: See TracChangeset for help on using the changeset viewer.