Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2015, 12:14:43 PM (8 years ago)
Author:
gania
Message:

improved dodging

File:
1 edited

Legend:

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

    r10885 r10886  
    4545    FightingController::FightingController( Context* context ): FlyingController( context )
    4646    {
    47         this->attackRange_ = 3000;
     47        this->attackRange_ = 2500;
    4848        this->stopLookingAtTarget();
    4949        this->bSetupWorked = false;
     
    126126        float diffLength = diffVector.length();
    127127        Vector3 diffUnit = diffVector/diffLength;
    128         bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f);
    129        
     128        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/15.0f)
     129            || this->deltaHp < 0;
     130
    130131        //too far? well, come closer then
    131132        if (diffLength > this->attackRange_)
    132133        {
    133             this->spread_ = 300;
    134             this->formationMode_ = FormationMode::WALL;
     134            this->spread_ = 400;
     135            this->formationMode_ = FormationMode::DIAMOND;
    135136            this->bKeepFormation_ = true;
    136137           
    137             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     138            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    138139        }
    139140        //too close? How do u expect to dodge anything? Just attack!
    140         else if (diffLength < 500)
     141        else if (diffLength < 400)
    141142        {   
    142143            this->bKeepFormation_ = false;
    143144
    144145            //at this point, just look and shoot
    145             if (diffLength < 250)
     146            if (diffLength < 200)
    146147            {
    147148                this->stopMoving();
     
    150151            else
    151152            {
    152                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     153                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    153154            }
    154155        }
     
    157158        {
    158159            this->bKeepFormation_ = false;
    159             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     160            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    160161        }
    161162        //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
     
    165166            if (maneuverCounter_ == 0)
    166167            {
    167                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);   
     168                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 50.0f);   
    168169                return;
    169170            }
     
    176177        //d.x*x + d.y*y + d.z*z == 0
    177178        //z = 1/d.z * (-d.y*y - d.x * x)
    178         float x = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    179         float y = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     179        float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     180        float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    180181        float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    181         this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);
     182        this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f));
    182183        this->boostControl();
    183184
     
    195196            this->setPositionOfTarget(newPositionOfTarget);
    196197        }
     198
    197199        return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
    198200    }
     
    270272            return;
    271273        }
     274
    272275        Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity());
    273276        if (pawn)
    274277            pawn->setAimPosition (this->positionOfTarget_);
    275 
     278        // if (pawn->getHealth() < 100)
     279        //     orxout(internal_error) << "not full, hp = " << pawn->getHealth() << endl;
    276280        int firemode;
    277281        float distance = CommonController::distance (this->getControllableEntity(), this->target_);
     
    281285        //                                                      : getFiremode("HsW01")) :
    282286        //                                                      (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01"));
    283         if (distance < 800)
    284         {
    285             if (this->rocketsLeft_ > 0)
    286             {
    287                 firemode = getFiremode ("SimpleRocketFire");
     287        if (distance < 1500)
     288        {
     289            if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
     290            {
     291                firemode = getFiremode ("RocketFire");
    288292            }
    289293            else
    290294            {
    291                 if (distance > 450)
     295                if (distance > 800)
     296                    firemode = getFiremode ("HsW01");
     297                else
    292298                    firemode = getFiremode ("LightningGun");
    293                 else
    294                     firemode = getFiremode ("HsW01");
    295299            }
    296300
    297301        }
    298         else if (distance < 1200)
    299         {
    300             if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
    301             {
    302                 firemode = getFiremode ("RocketFire");
    303             }
    304             else
    305             {
    306                 firemode = getFiremode ("HsW01");
    307             }
    308         }
    309         else if (distance < 1500)
     302        // else if (distance < 1000)
     303        // {
     304        //     if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
     305        //     {
     306        //         firemode = getFiremode ("RocketFire");
     307        //     }
     308        //     else
     309        //     {
     310        //         firemode = getFiremode ("HsW01");
     311        //     }
     312        // }
     313        else if (distance < 2000)
     314        {
     315            firemode = getFiremode ("HsW01");
     316        }
     317        else
    310318        {
    311319            firemode = getFiremode ("LightningGun");
    312320        }
    313         else
    314         {
    315             firemode = getFiremode ("HsW01");
    316         }
    317321        if (firemode < 0)
    318322        {
    319             firemode = getFiremode ("HsW01");
     323            //assuming there is always some weapon with index 0
     324            firemode = 0;
    320325        }
    321326        if (firemode == getFiremode("RocketFire"))
    322327        {
    323             this->timeout_ = 1.0f;
     328            this->timeout_ = 0.5f;
    324329            this->rocketsLeft_--;
    325330            this->bFiredRocket_ = true;
Note: See TracChangeset for help on using the changeset viewer.