Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2015, 8:34:20 AM (8 years ago)
Author:
gania
Message:

check in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10906 r10923  
    6363    void FightingController::lookAtTarget(float dt)
    6464    {
     65        if (!this || !this->getControllableEntity())
     66            return;
    6567        ControllableEntity* entity = this->getControllableEntity();
    6668        if ( !entity )
     
    126128        float diffLength = diffVector.length();
    127129        Vector3 diffUnit = diffVector/diffLength;
    128         bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
    129             || this->deltaHp < 0;
     130
     131        if (!this || !this->getControllableEntity())
     132            return;
    130133
    131134        //too far? well, come closer then
     
    139142        }
    140143        else
    141         {
     144        {   
     145            bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
     146                || this->deltaHp < 0;
    142147            this->bKeepFormation_ = false;
     148
     149            if (!this || !this->getControllableEntity())
     150                return;
    143151            // if (this->actionCounter_ % 3 == 0)
    144152            if (maneuverCounter_ <= 1.2)
     
    173181            }
    174182        }
    175         /*//too close? How do u expect to dodge anything? Just attack!
    176         else if (diffLength < 1000)
    177         {   
    178             this->bKeepFormation_ = false;
    179 
    180             //at this point, just look and shoot
    181             if (diffLength < 1000)
    182             {
    183                 this->stopMoving();
    184                 this->startLookingAtTarget();
    185 
    186             }
    187             else
    188             {
    189                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f);
    190             }
    191         }
    192         //Good distance? Check if target looks at us. It doesn't? Go hunt!
    193         else if (!bTargetIsLookingAtThis)
    194         {
    195             this->bKeepFormation_ = false;
    196             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);
    197         }
    198         //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
    199         else
    200         {   
    201             this->bKeepFormation_ = false;
    202             if (maneuverCounter_ == 0)
    203             {
    204                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);   
    205                 return;
    206             }
    207             if (this->actionCounter_ % 3 == 0)
    208                 dodge(thisPosition, diffLength, diffUnit);
    209         }*/
    210     }
    211     void FightingController::dodgeTowards (Vector3& position)
    212     {
    213         Vector3 thisPosition = this->getControllableEntity()->getPosition();
    214         Vector3 diff = (position - thisPosition);
    215         float diffLength = diff.length();
    216         Vector3 diffUnit = diff/diffLength;
    217         float factor = 300.0f;
    218         if (diffLength < 300)
    219         {
    220             this->setTargetPosition(position);
    221             return;   
    222         }
    223         else if (diffLength < 600)
    224             factor = 400.0f;
    225         else if (diffLength < 1000)
    226             factor = 700.0f;
    227         else
    228             factor = 1000.0f;
    229         float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    230         float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    231         float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    232         this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor);
    233         // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z)  << endl;
    234         this->boostControl();
    235     }
     183    }
     184   
    236185    void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit)
    237186    {
     
    257206    {
    258207        //no target? why fire?
    259         if (!this->target_)
     208        if (!this->target_ || !this->getControllableEntity())
    260209            return false;
    261210        Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
     
    274223    float FightingController::squaredDistanceToTarget()  const
    275224    {
    276         if (!this->getControllableEntity())
     225        if (!this || !this->getControllableEntity())
    277226            return 0;
    278227        if (!this->target_ || !this->getControllableEntity())
     
    294243    Pawn* FightingController::closestTarget() const
    295244    {
    296         if (!this->getControllableEntity())
     245        if (!this || !this->getControllableEntity())
    297246            return 0;
    298247
Note: See TracChangeset for help on using the changeset viewer.