Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8786 for code/branches/ai2


Ignore:
Timestamp:
Jul 25, 2011, 11:18:20 PM (13 years ago)
Author:
jo
Message:

Bots can fetch pickups. Waypointmanagement is unstable yet.

Location:
code/branches/ai2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai2/data/levels/missionOne.oxw

    r8773 r8786  
    5656      </collisionShapes>
    5757  </Pawn>
    58   <Pawn health=30 position="20,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
     58  <Pawn health=30 position="70,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
    5959      <attached>
    6060        <Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
     
    6464      </collisionShapes>
    6565  </Pawn>
    66   <Pawn health=30 position="40,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
     66  <Pawn health=30 position="140,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
    6767      <attached>
    6868        <Model position="0,0,0" mesh="crate.mesh" scale3D="5,5,5" />
     
    7272      </collisionShapes>
    7373  </Pawn>
    74   <Pawn health=30 position="60,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
     74  <Pawn health=30 position="210,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
    7575      <attached>
    7676        <Model position="0,0,0" mesh="crate.mesh" scale3D="5,5,5" />
  • code/branches/ai2/src/orxonox/controllers/AIController.cc

    r8769 r8786  
    114114                this->bShooting_ = false;
    115115
     116            // boost
     117            random = rnd(maxrand);
     118            if (random < botlevel_*100 )
     119                this->boostControl();
     120
     121            // update Checkpoints
     122            random = rnd(maxrand);
     123            if (this->defaultWaypoint_ && random > (maxrand-10))
     124                this->manageWaypoints();
     125            else //if(random > maxrand-10) //CHECK USABILITY!!
     126                this->manageWaypoints();
     127
    116128        }
    117129
     
    196208                    this->bShooting_ = false;
    197209
    198                 //boost
     210                // boost
    199211                random = rnd(maxrand);
    200212                if (random < botlevel_*100 )
    201                     this->boostControl(); //TEST
     213                    this->boostControl();
     214
     215                // update Checkpoints
     216                random = rnd(maxrand);
     217                if (this->defaultWaypoint_ && random > (maxrand-10))
     218                    this->manageWaypoints();
     219                else //if(random > maxrand-10) //CHECK USABILITY!!
     220                    this->manageWaypoints();
    202221            }
    203222        }
     
    212231        float random;
    213232        float maxrand = 100.0f / ACTION_INTERVAL;
    214         if (this->waypoints_.size() > 0 && this->getControllableEntity() && this->mode_ == DEFAULT) //Waypoint functionality.
     233        ControllableEntity* controllable = this->getControllableEntity();
     234
     235        if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
    215236        {
    216             if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_)
    217                 this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size();
    218 
    219             this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition());
     237            if (this->waypoints_.size() > 0 ) //Waypoint functionality.
     238            {
     239                if (this->waypoints_[this->waypoints_.size()-1]->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_)
     240                    this->waypoints_.pop_back(); // if goal is reached, remove it from the list
     241                if(this->waypoints_.size() > 0 )
     242                    this->moveToPosition(this->waypoints_[this->waypoints_.size()-1]->getWorldPosition());
     243            }
     244            else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length()  > 200.0f))
     245            {
     246                this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_
     247                random = rnd(maxrand);
     248            }
    220249        }
    221250        if(this->mode_ == DEFAULT)
     
    283312        else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
    284313        {   //Vector-implementation: mode_.back() == ROCKET;
    285             ControllableEntity *controllable = this->getControllableEntity();
    286314            if(controllable)
    287315            {
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8773 r8786  
    9696        this->timeout_ = 0;
    9797        this->currentWaypoint_ = 0;
    98         this->setAccuracy(100);
     98        this->setAccuracy(9);
     99        this->defaultWaypoint_ = NULL;
    99100    }
    100101
     
    11251126    }
    11261127
     1128    /**
     1129        @brief Manages boost. Switches between boost usage and boost safe mode.
     1130    */
    11271131    void ArtificialController::boostControl()
    11281132    {
     
    11581162    }
    11591163
    1160     void ArtificialController::updatePointsOfInterest(std::string name, float distance)
     1164    /**
     1165        @brief Adds first waypoint of type name to the waypoint stack, which is within the searchDistance
     1166        @param name object-name of a point of interest (e.g. "PickupSpawner", "ForceField")
     1167    */
     1168    void ArtificialController::updatePointsOfInterest(std::string name, float searchDistance)
    11611169    {
    11621170        WorldEntity* waypoint = NULL;
    1163         if(name == "Pickup")
    1164         {
    1165             for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
    1166             {
    1167                 //get POI by string: Possible POIs are PICKUPSPAWNER, FORCEFIELDS (!analyse!), ...
    1168                 //distance to POI decides wether it is added (neither too close nor too far away)
    1169                 //How should POI's be managed? (e.g. Look for POIs if there are no real targets to move to or if they can be taken "en passant".)
    1170                    waypoint = *it;
    1171                    if(waypoint->getIdentifier() == ClassByString(name))
    1172                    {
    1173                        ControllableEntity* controllable = this->getControllableEntity();
    1174                        if(!controllable) continue;
    1175                        float distance = ( waypoint->getPosition() - controllable->getPosition() ).length();
    1176                        if(distance > 50.0f || distance < 5.0f) continue;
    1177                        if(name == "PickupSpawner") // PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance
    1178                        {
    1179                            squaredaccuracy_ = waypoint->getTriggerDistance() * waypoint->getTriggerDistance();
    1180                        }
    1181                        else if(name == "ForceField") // ForceField: analyze is angle between forcefield boost and own flying direction is acceptable
    1182                        {
    1183 
    1184                        }
    1185 
    1186 
    1187                        break;
    1188                    }
    1189 
    1190                 /*const Vector3 realDistance = it->getPosition() - this->getControllableEntity()->getPosition();
    1191                 if( realDistance.length() < distance)
     1171        for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
     1172        {
     1173            if((*it)->getIdentifier() == ClassByString(name))
     1174            {
     1175                ControllableEntity* controllable = this->getControllableEntity();
     1176                if(!controllable) continue;
     1177                float actualDistance = ( (*it)->getPosition() - controllable->getPosition() ).length();
     1178                if(actualDistance > searchDistance || actualDistance < 5.0f) continue;
     1179                    // TODO: PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance
     1180                    // TODO: ForceField: analyze is angle between forcefield boost and own flying direction is acceptable
     1181                else
    11921182                {
    1193                     float minDistance = it->getTriggerDistance().length()*it->getTriggerDistance().length();
    1194                     if(this->squaredaccuracy_ > minDistance)
    1195                         this->squaredaccuracy_ = minDistance;
    1196                     //waypoint = static_cast<WorldEntity*>(it);
     1183                    waypoint = *it;
    11971184                    break;
    1198                // }*/
     1185                }
    11991186            }
    12001187        }
     
    12031190    }
    12041191
     1192    /**
     1193        @brief Adds point of interest depending on context
     1194    */
     1195    void ArtificialController::manageWaypoints()
     1196    {
     1197        if(!defaultWaypoint_)
     1198            this->updatePointsOfInterest("PickupSpawner", 60.0f); // long search radius if there is no default goal
     1199        else
     1200            this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint
     1201    }
     1202
    12051203}
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8769 r8786  
    9393                { return sqrt(this->squaredaccuracy_); }
    9494            void updatePointsOfInterest(std::string name, float distance);
     95            void manageWaypoints();
    9596
    9697        protected:
     
    175176            size_t currentWaypoint_;
    176177            float squaredaccuracy_;
     178            WorldEntity* defaultWaypoint_;
    177179    };
    178180}
  • code/branches/ai2/src/orxonox/controllers/WaypointController.cc

    r8769 r8786  
    4040    {
    4141        RegisterObject(WaypointController);
     42        this->setAccuracy(100);
    4243    }
    4344
Note: See TracChangeset for help on using the changeset viewer.