Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6978 for code/branches/ai/src


Ignore:
Timestamp:
May 27, 2010, 6:39:59 PM (15 years ago)
Author:
solex
Message:

consle commands

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

Legend:

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

    r6919 r6978  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    6161            if (this->formationFlight_)
    6262            {
    63             // return to Master after being forced free
     63                // return to Master after being forced free
    6464                if (this->freedomCount_ == 1)
    6565                {
     
    103103                this->searchRandomTargetPosition();
    104104
    105 /*
    106             random = rnd(maxrand);
    107             if (random < 75 && (this->target_ && !this->bShooting_))
     105            // shoot
     106            random = rnd(maxrand);
     107            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
    108108                this->bShooting_ = true;
    109109
     
    111111            random = rnd(maxrand);
    112112            if (random < 25 && (this->bShooting_))
    113                 this->bShooting_ = false; */
     113                this->bShooting_ = false;
    114114
    115115        }
     
    120120        }
    121121
    122         if (this->state_ == MASTER)//MASTER
     122        if (this->state_ == MASTER)
    123123        {
    124124
     
    136136                if (this->specificMasterAction_ == SPIN)
    137137                    this->spin();
     138
     139//                 if (this->specificMasterAction_ == FOLLOWHUMAN)
     140//                     this->followHuman(this->HumanToFollow_, false);
    138141            }
    139142
     
    188191                // shoot
    189192                random = rnd(maxrand);
    190                 if (random < 5 && (this->target_ && !this->bShooting_))
     193                if (!(this->passive_) && random < 15 && (this->target_ && !this->bShooting_))
    191194                {
    192195                this->bShooting_ = true;
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r6958 r6978  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    2929#include "ArtificialController.h"
    3030
     31#include <vector>
    3132#include "core/CoreIncludes.h"
    3233#include "core/XMLPort.h"
     
    3637#include "gametypes/TeamDeathmatch.h"
    3738#include "controllers/WaypointPatrolController.h"
     39#include "controllers/NewHumanController.h"
    3840#include "controllers/DroneController.h"
    3941#include "util/Math.h"
     
    4244namespace orxonox
    4345{
    44     SetConsoleCommand(ArtificialController, formationflight, true);//.defaultValues(0, true);
     46    SetConsoleCommand(ArtificialController, formationflight, true);
    4547    SetConsoleCommand(ArtificialController, masteraction, true);
     48    SetConsoleCommand(ArtificialController, followme, true);
     49    SetConsoleCommand(ArtificialController, passivbehaviour, true);
    4650
    4751    static const unsigned int MAX_FORMATION_SIZE = 7;
     
    5357    static const float SPEED_FREE = 0.8f;
    5458    static const float ROTATEFACTOR_FREE = 0.8f;
     59    static const int SECONDS_TO_FOLLOW_HUMAN = 10;
    5560
    5661    ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
     
    6065        this->target_ = 0;
    6166        this->formationFlight_ = true;
     67        this->passive_ = false;
    6268        this->myMaster_ = 0;
    6369        this->freedomCount_ = 0;
     
    6975        this->bHasTargetPosition_ = false;
    7076        this->targetPosition_ = Vector3::ZERO;
     77        this->humanToFollow_ = NULL;
    7178
    7279        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     
    8592    }
    8693
    87     //activate/deactivate formationflight
     94// Documentation only here to get a faster overview for creating a useful documentation, what you're reading here not intended for an actual documentation...
     95
     96    /**
     97        @brief Activates / deactivates formationflight behaviour
     98        @param form activate formflight if form is true
     99    */
    88100    void ArtificialController::formationflight(bool form)
    89101    {
     
    101113        }
    102114    }
    103     //get all masters to do this action
     115
     116    /**
     117        @brief Get all masters to do a specific action
     118        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
     119    */
    104120    void ArtificialController::masteraction(int action)
    105121    {
     
    118134    }
    119135
    120 // gets called when Bot dies
     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.
     138    */
     139    void ArtificialController::followme()
     140    {
     141
     142        Pawn *humanPawn = NULL;
     143        NewHumanController *currentHumanController = NULL;
     144        std::vector<ArtificialController*> allMasters;
     145
     146        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     147        {
     148            if (!it->getController())
     149                continue;
     150
     151            currentHumanController = static_cast<NewHumanController*>(it->getController());
     152
     153            if(currentHumanController) humanPawn = *it;
     154
     155            ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     156
     157            if(aiController || aiController->state_ == MASTER)
     158                allMasters.push_back(aiController);
     159
     160        }
     161        /*if((humanPawn != NULL) && (allMasters.size != 0))
     162        {
     163
     164                float posHuman = humanPawn->getPosition().length();
     165                float distance = 0.0f;
     166                float minDistance = posHuman - allMasters.back()->getControllableEntity()->getPosition().length();
     167                int index = 0;
     168                int i = 0;
     169
     170                for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++)
     171                    {
     172                        distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
     173                        if(distance < minDistance) index = i;
     174                    }
     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.
     184    */
     185    void ArtificialController::passivebehaviour(bool passive)
     186    {
     187        this->passive_ = passive;
     188    }
     189
     190    /**
     191        @brief Gets called if ControllableEntity is changed. Resets the bot when it dies.
     192    */
    121193    void ArtificialController::changedControllableEntity()
    122194    {
     
    130202        }
    131203    }
     204
    132205
    133206    void ArtificialController::moveToPosition(const Vector3& target)
     
    210283    }
    211284
     285    /**
     286        @brief Unregisters a slave from its master. Called by a slave.
     287    */
    212288    void ArtificialController::unregisterSlave() {
    213289        if(myMaster_)
     
    272348                break;
    273349            }
    274         }//for
    275         //hasn't encountered any masters in range? -> become a master
    276         if (state_ != SLAVE  && teamSize != 0) state_ = MASTER;//master encounters master? ->done
    277 
    278     }
    279 
    280     void ArtificialController::commandSlaves() {
     350        }
     351
     352        if (state_ != SLAVE  && teamSize != 0) state_ = MASTER;
     353
     354    }
     355
     356    /**
     357        @brief Commands the slaves of a master into a formation. Called by a master.
     358    */
     359    void ArtificialController::commandSlaves()
     360    {
     361        if(this->state_ != MASTER) return;
    281362
    282363        Quaternion orient = this->getControllableEntity()->getOrientation();
     
    315396    }
    316397
    317     // binds slaves to new Master within formation
     398    /**
     399        @brief Sets a new master within the formation. Called by a master.
     400    */
    318401    void ArtificialController::setNewMasterWithinFormation()
    319402    {
     403        if(this->state_ != MASTER) return;
    320404
    321405        if (this->slaves_.empty())
     
    340424    }
    341425
     426    /**
     427        @brief Frees all slaves form a master. Called by a master.
     428    */
    342429    void ArtificialController::freeSlaves()
    343430    {
     431        if(this->state_ != MASTER) return;
     432
    344433        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    345434        {
     
    349438    }
    350439
     440    /**
     441        @brief Master sets its slaves free for \var FREEDOM_COUNT seconds.
     442    */
    351443    void ArtificialController::forceFreeSlaves()
    352444    {
     445        if(this->state_ != MASTER) return;
     446
    353447        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    354448        {
     
    367461    }
    368462
     463
    369464    void ArtificialController::forceFreedom()
    370465    {
     
    372467    }
    373468
     469    /**
     470        @brief Checks wether caller has been forced free, decrements time to stay forced free.
     471        @return true if forced free.
     472    */
    374473    bool ArtificialController::forcedFree()
    375474    {
     
    381480    }
    382481
     482    /**
     483        @brief Used to continue a "specific master action" for a certain time.
     484    */
    383485    void ArtificialController::specificMasterActionHold()
    384486    {
     487        if(this->state_ != MASTER) return;
     488
    385489        if (specificMasterActionHoldCount_ == 0)
    386490         {
    387491            this->specificMasterAction_ = NONE;
    388492            this->searchNewTarget();
    389             COUT(0) << "~action end" << std::endl;
    390493         }
    391494        else specificMasterActionHoldCount_--;
    392495    }
    393496
     497    /**
     498        @brief Master engages a 180 degree turn. Is a "specific master action".
     499    */
    394500    void ArtificialController::turn180()
    395501    {
     502        if(this->state_ != MASTER) return;
     503
    396504        COUT(0) << "~turn" << std::endl;
    397505
     
    403511    }
    404512
     513    /**
     514        @brief Master spins around looking directions axis. Is a "specific master action".
     515    */
    405516    void ArtificialController::spin()
    406517    {
     518        if(this->state_ != MASTER) return;
     519
    407520        this->specificMasterAction_  =  NONE;
     521    }
     522
     523    /**
     524        @brief Master begins to follow a human player. Is a "specific master action".
     525        @param humanController human to follow.
     526        @param alaways follows human forever if true - yet only inplemented for false.
     527    */
     528    void ArtificialController::followHuman(Pawn* human, bool always)
     529    {
     530        if (human == NULL)
     531        {
     532            this->specificMasterAction_ = NONE;
     533            return;
     534        }
     535        if (!always)
     536        {
     537            this->setTarget(human);
     538            this->specificMasterActionHoldCount_ = SECONDS_TO_FOLLOW_HUMAN;
     539            this->specificMasterAction_  =  HOLD;
     540        }
     541
    408542    }
    409543
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6958 r6978  
    3636#include "util/Math.h"
    3737#include "Controller.h"
     38#include "controllers/NewHumanController.h"
    3839
    3940namespace orxonox
     
    6162            static void formationflight(bool form);
    6263            static void masteraction(int action);
     64            static void followme();
    6365
    6466        protected:
     
    7173            std::vector<ArtificialController*> slaves_;
    7274            ArtificialController *myMaster_;
    73             enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180};
     75            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOWHUMAN};
    7476            SpecificMasterAction specificMasterAction_;
    7577            int specificMasterActionHoldCount_;
     78            Pawn* humanToFollow_;
    7679
    7780            void targetDied();
     
    8689            void commandSlaves();
    8790            void setNewMasterWithinFormation();
     91
    8892            void freeSlaves();
    8993            void forceFreeSlaves();
     
    9195            void forceFreedom();
    9296            bool forcedFree();
     97
    9398            void specificMasterActionHold();
    9499            void turn180();
    95100            void spin();
     101            void followHuman(Pawn* humanController, bool always);
    96102
    97103            void setTargetPosition(const Vector3& target);
Note: See TracChangeset for help on using the changeset viewer.