Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10793


Ignore:
Timestamp:
Nov 10, 2015, 4:37:34 PM (8 years ago)
Author:
gania
Message:

added choose maneuver type functionality

Location:
code/branches/AI_HS15/src/orxonox/controllers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10789 r10793  
    5555        this->executingMoveToPoint_ = false;
    5656
     57        this->maneuverType_ = ManeuverType::NONE;
    5758        RegisterObject(CommonController);
    5859    }
     
    116117        }
    117118    }
    118 
     119    void CommonController::chooseManeuverType()
     120    {
     121
     122        if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
     123        {
     124            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
     125            Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
     126            float myDotProduct = diffVector.dotProduct(myForwardVector);
     127
     128            Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
     129            float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);           
     130
     131
     132            switch ((myDotProduct > 0) - (myDotProduct < 0))
     133            {
     134                case 1:
     135                {
     136                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
     137                    {
     138                        case 1:
     139                        {
     140                            this->maneuverType_ = ManeuverType::OFFENSIVE;
     141                            break;
     142                        }
     143                        case 0:
     144                        {
     145                            this->maneuverType_ = ManeuverType::OFFENSIVE;
     146                            break;
     147                        }
     148                        case -1:
     149                        {
     150                            this->maneuverType_ = ManeuverType::NEUTRAL;
     151                            break;
     152                        }
     153                    }
     154                    break;
     155                }
     156                case 0:
     157                {
     158                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
     159                    {
     160                        case 1:
     161                        {
     162                            this->maneuverType_ = ManeuverType::OFFENSIVE;
     163                            break;
     164                        }
     165                        case 0:
     166                        {
     167                            this->maneuverType_ = ManeuverType::NEUTRAL;
     168                            break;
     169                        }
     170                        case -1:
     171                        {
     172                            this->maneuverType_ = ManeuverType::DEFENCIVE;
     173                            break;
     174                        }
     175                    }
     176
     177                    break;
     178                }
     179                case -1:
     180                {
     181                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
     182                    {
     183                        case 1:
     184                        {
     185                            this->maneuverType_ = ManeuverType::NEUTRAL;
     186                            break;
     187                        }
     188                        case 0:
     189                        {
     190                            this->maneuverType_ = ManeuverType::DEFENCIVE;
     191                            break;
     192                        }
     193                        case -1:
     194                        {
     195                            this->maneuverType_ = ManeuverType::DEFENCIVE;
     196                            break;
     197                        }
     198                    }
     199                    break;
     200                }
     201            }
     202        }
     203        if (this->getControllableEntity() && !this->target_)
     204        {
     205            this->maneuverType_ = ManeuverType::NONE;
     206        }
     207        orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
     208    }
    119209    bool CommonController::setWingman (CommonController* wingman)
    120210    {
     
    130220        this->target_ = target;
    131221        orxout (internal_error) << " TARGET SET " << endl;
    132         if (target)
    133             this->targetPosition_ = target->getPosition();
    134     }
    135 
    136 
     222       
     223        if (this->target_ )
     224        {
     225            this->setPositionOfTarget(target_->getWorldPosition());
     226
     227        }
     228    }
     229    bool CommonController::hasTarget()
     230    {
     231        if (this->target_)
     232            return true;
     233        return false;
     234    }
     235    void CommonController::setPositionOfTarget(const Vector3& target)
     236    {
     237        this->positionOfTarget_ = target;
     238        this->bHasPositionOfTarget_ = true;
     239    }
     240    void CommonController::setOrientationOfTarget(const Quaternion& orient)
     241    {
     242        this->orientationOfTarget_=orient;
     243        this->bHasOrientationOfTarget_=true;
     244    }
    137245
    138246    void CommonController::setTargetPosition(const Vector3& target)
     
    370478
    371479        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     480
    372481        if (pawn)
    373             pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
     482            //pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
     483            pawn->setAimPosition(this->targetPosition_);
    374484   
    375485        this->getControllableEntity()->fire(0);
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10789 r10793  
    111111
    112112            void setTarget(ControllableEntity* target);
    113            
     113            bool hasTarget();
    114114            void setTargetOrientation(const Quaternion& orient);
    115115            void setTargetOrientation(ControllableEntity* target);
     
    153153            Quaternion targetOrientation_;
    154154
    155 
     155            void setPositionOfTarget(const Vector3& target);
     156            void setOrientationOfTarget(const Quaternion& orient);
    156157            bool bHasPositionOfTarget_;
    157158            Vector3 positionOfTarget_;
     
    165166
    166167
     168            void chooseManeuverType();
    167169
    168170            FormationMode::Value formationMode_;
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10789 r10793  
    5757    void DivisionController::tick(float dt)
    5858    {
     59        if (this->target_ )
     60        {
     61            this->setPositionOfTarget(target_->getWorldPosition());
     62
     63        }
    5964        /*if (this->target_)
    6065        {
     
    8287        Vector3* pos = new Vector3(4000,1000,2000);
    8388        this->setTargetPosition(*pos);*/
    84 
    85         setTargetPositionOfFollower();
    86         setTargetPositionOfWingman();
     89       
     90/*        if (!this->target_)
     91        {
     92
     93            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     94            {
     95                if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*it)->getTeam())
     96                    continue;
     97
     98               
     99
     100                if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
     101                {
     102                    this->setTarget(*it);
     103                }
     104            }
     105        }*/
     106        this->chooseManeuverType();
     107        switch (this->maneuverType_)
     108        {
     109            case ManeuverType::NONE:
     110            {
     111                setTargetPositionOfFollower();
     112                setTargetPositionOfWingman();
     113                break;
     114            }
     115            case ManeuverType::DEFENSIVE:
     116            {
     117                this->gunsD();
     118            }
     119            case ManeuverType::OFFENSIVE:
     120            {
     121                this->attack();
     122            }
     123        }
     124       
    87125        if (!executingMoveToPoint_)
    88126        {
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10789 r10793  
    8080            }
    8181        }*/
     82        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     83        {
     84            if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     85                continue;           
     86
     87            for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it)
     88            {
     89                if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget())
     90                {
     91                    (*it)->setTarget(*itP);
     92                }
     93               
     94            }   
     95           
     96        }
    8297
    8398    }
Note: See TracChangeset for help on using the changeset viewer.