Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

consle commands

File:
1 edited

Legend:

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