Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8238


Ignore:
Timestamp:
Apr 12, 2011, 9:41:33 PM (13 years ago)
Author:
jo
Message:

Drone (almost) doesn't shoot at it's owner anymore.

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

Legend:

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

    r7843 r8238  
    6666                if (this->freedomCount_ == 1)
    6767                {
    68                 this->state_ = SLAVE;
    69                 this->freedomCount_ = 0;
     68                    this->state_ = SLAVE;
     69                    this->freedomCount_ = 0;
    7070                }
    7171
     
    8282            // forget enemy
    8383            random = rnd(maxrand);
    84             if (random < ((1-botlevel_)*5) && (this->target_))
     84            if (random < ((1-botlevel_)*6) && (this->target_))
    8585                this->forgetTarget();
    8686
    8787            // next enemy
    8888            random = rnd(maxrand);
    89             if (random < ((1-botlevel_)*10) && (this->target_))
     89            if (random < (botlevel_*20) && (this->target_))
    9090                this->searchNewTarget();
    9191
     
    220220                    {
    221221                        this->aimAtTarget();
    222                         random = rnd(maxrand);
    223                         if(this->botlevel_*100 > random)
     222                        random = rnd(maxrand);
     223                        if(this->botlevel_*100 > random)
    224224                            this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
    225225                    }
     
    254254                    this->forgetTarget();
    255255                else
    256                 {
    257                     this->aimAtTarget();
    258                     random = rnd(maxrand);
    259                     if(this->botlevel_*100 > random)
     256                {
     257                    this->aimAtTarget();
     258                    random = rnd(maxrand);
     259                    if(this->botlevel_*100 > random)
    260260                        this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
    261                 }
     261                 }
    262262            }
    263263
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r7843 r8238  
    10261026    void ArtificialController::doFire()
    10271027    {
     1028        if(ArtificialController::friendlyFire()) return;//catch if the bot would do friendlyFire
    10281029        if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
    10291030        {
     
    10651066        }
    10661067    }
     1068
    10671069   
    10681070    void ArtificialController::setBotLevel(float level)
  • code/branches/ai/src/orxonox/controllers/DroneController.cc

    r7284 r8238  
    103103                    this->isShooting_ = true;
    104104                    this->aimAtTarget();
    105                     this->getDrone()->fire(0);
     105                    if(!this->friendlyFire())
     106                        this->getDrone()->fire(0);
    106107                }
    107108            }
     
    147148            this->destroy();
    148149    }
     150   
     151    bool DroneController::friendlyFire()
     152    {   ControllableEntity* droneEntity_ = this->getControllableEntity();
     153        if (!droneEntity_) return false;
     154        if(!owner_) return false;
     155        if(this->bHasTargetPosition_)
     156        {
     157            Vector3 ownerPosition_ = owner_->getPosition();
     158            Vector3 toOwner_ = owner_->getPosition() - droneEntity_->getPosition();
     159            Vector3 toTarget_ = targetPosition_ - droneEntity_->getPosition();
     160            if(toTarget_.length() < toOwner_.length()) return false; //owner is far away = in safty
     161            float angleToOwner = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, ownerPosition_);
     162            float angleToTarget = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, targetPosition_);
     163            float angle = angleToOwner - angleToTarget;//angle between target and owner, observed by the drone
     164            if(std::sin(angle)*toOwner_.length() < 5.0f)//calculate owner's distance to shooting line
     165            return true;
     166        }
     167        return false;//Default return value: Usually there is no friendlyFire
     168    }
    149169}
  • code/branches/ai/src/orxonox/controllers/DroneController.h

    r7163 r8238  
    6666            virtual void action();
    6767            void ownerDied();
     68            bool friendlyFire(); //< returns true if the owner_ would be hit.
    6869            bool isShooting_;
    6970
Note: See TracChangeset for help on using the changeset viewer.