Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6958


Ignore:
Timestamp:
May 21, 2010, 3:19:42 PM (14 years ago)
Author:
solex
Message:

ai: introduced masteraction and console commands

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

Legend:

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

    r6919 r6958  
    3838#include "controllers/DroneController.h"
    3939#include "util/Math.h"
     40#include "core/ConsoleCommand.h"
    4041
    4142namespace orxonox
    4243{
     44    SetConsoleCommand(ArtificialController, formationflight, true);//.defaultValues(0, true);
     45    SetConsoleCommand(ArtificialController, masteraction, true);
    4346
    4447    static const unsigned int MAX_FORMATION_SIZE = 7;
     
    5659
    5760        this->target_ = 0;
    58         this->formationFlight_  = true;
     61        this->formationFlight_ = true;
    5962        this->myMaster_ = 0;
    6063        this->freedomCount_ = 0;
     
    7982
    8083        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
    81 //         XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true);
     84        XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true);
     85    }
     86
     87    //activate/deactivate formationflight
     88    void ArtificialController::formationflight(bool form)
     89    {
     90        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     91        {
     92            if (!it->getController())
     93                continue;
     94
     95            ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     96
     97            if(aiController)
     98            {
     99                aiController->formationFlight_ = form;
     100            }
     101        }
     102    }
     103    //get all masters to do this action
     104    void ArtificialController::masteraction(int action)
     105    {
     106        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     107        {
     108            if (!it->getController())
     109                continue;
     110
     111            ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
     112
     113            if(aiController || aiController->state_ == MASTER)
     114            {
     115                aiController->specificMasterAction_ = TURN180;
     116            }
     117        }
    82118    }
    83119
     
    125161            if (this->target_ || distance > 10)
    126162            {
     163                if (this->specificMasterAction_ == NONE)
     164                {
    127165                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    128166                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     167                } else if (this->specificMasterAction_ == TURN180)
     168                {
     169                this->getControllableEntity()->rotateYaw(-1.0f * sgn(coord.x) * coord.x*coord.x);
     170                this->getControllableEntity()->rotatePitch(sgn(coord.y) * coord.y*coord.y);
     171                }
    129172
    130173            }
     
    143186           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    144187           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
    145 
    146 
    147 
    148 
    149188
    150189            if (distance < 300)
     
    177216            if( it != myMaster_->slaves_.end() )
    178217                myMaster_->slaves_.erase(it);
    179 // COUT(0) << "~unregister slave" << std::endl;
    180218        }
    181219    }
     
    345383    void ArtificialController::specificMasterActionHold()
    346384    {
    347         if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE;
     385        if (specificMasterActionHoldCount_ == 0)
     386         {
     387            this->specificMasterAction_ = NONE;
     388            this->searchNewTarget();
     389            COUT(0) << "~action end" << std::endl;
     390         }
    348391        else specificMasterActionHoldCount_--;
    349392    }
     
    351394    void ArtificialController::turn180()
    352395    {
    353         this->specificMasterAction_  =  NONE;
     396        COUT(0) << "~turn" << std::endl;
     397
     398        Quaternion orient = this->getControllableEntity()->getOrientation();
     399
     400        this->setTargetPosition(this->getControllableEntity()->getPosition() + 500.0f*orient*WorldEntity::BACK);
     401        this->specificMasterActionHoldCount_ = 2;
     402        this->specificMasterAction_  =  HOLD;
    354403    }
    355404
     
    382431    void ArtificialController::searchNewTarget()
    383432    {
    384 COUT(0) << "search new target - start" << std::endl;
    385433        if (!this->getControllableEntity())
    386434            return;
     
    407455            }
    408456        }
    409 COUT(0) << "search new target - end: " << this->target_ << std::endl;
    410457    }
    411458
     
    544591        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
    545592            return true;
    546            
     593
    547594        return (team1 == team2 && team1 != -1);
    548595    }
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6919 r6958  
    5959            virtual void changedControllableEntity();
    6060
     61            static void formationflight(bool form);
     62            static void masteraction(int action);
    6163
    6264        protected:
Note: See TracChangeset for help on using the changeset viewer.