Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8769 for code/branches


Ignore:
Timestamp:
Jul 21, 2011, 5:36:37 PM (13 years ago)
Author:
jo
Message:

Moved intern waypoint functionallity from the waypointController to its base class ArtificialController. Further usage of this is planned.

Location:
code/branches/ai2/src/orxonox/controllers
Files:
5 edited

Legend:

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

    r8766 r8769  
    212212        float random;
    213213        float maxrand = 100.0f / ACTION_INTERVAL;
     214        if (this->waypoints_.size() > 0 && this->getControllableEntity() && this->mode_ == DEFAULT) //Waypoint functionality.
     215        {
     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());
     220        }
    214221        if(this->mode_ == DEFAULT)
    215222            {
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8764 r8769  
    4949#include "weaponsystem/Weapon.h"
    5050#include "weaponsystem/WeaponSlot.h"
     51#include "weaponsystem/WeaponSlot.h"
    5152
    5253namespace orxonox
     
    9394        this->botlevel_ = 0.5f;
    9495        this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
    95         this->timeout_=0;
     96        this->timeout_ = 0;
     97        this->currentWaypoint_ = 0;
     98        this->setAccuracy(100);
    9699    }
    97100
     
    100103        if (this->isInitialized())
    101104        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
     105            for (size_t i = 0; i < this->waypoints_.size(); ++i)
     106                this->waypoints_[i]->destroy();
    102107            this->removeFromFormation();
    103108            this->weaponModes_.clear();
     
    11401145    }
    11411146
     1147    void ArtificialController::addWaypoint(WorldEntity* waypoint)
     1148    {
     1149        this->waypoints_.push_back(waypoint);
     1150    }
     1151
     1152    WorldEntity* ArtificialController::getWaypoint(unsigned int index) const
     1153    {
     1154        if (index < this->waypoints_.size())
     1155            return this->waypoints_[index];
     1156        else
     1157            return 0;
     1158    }
     1159
     1160    void ArtificialController::updatePointsOfInterest(std::string name, float distance)
     1161    {
     1162        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                //if(it->isA(Pickupable)) //distance to POI decides wether it is added (neither too close nor too far away)
     1169                //To Think: how should POI's be managed? (e.g. if there are no real moving target or if the can be taken "en passant".)
     1170                   waypoint = *it;
     1171                /*const Vector3 realDistance = it->getPosition() - this->getControllableEntity()->getPosition();
     1172                if( realDistance.length() < distance)
     1173                {
     1174                    float minDistance = it->getTriggerDistance().length()*it->getTriggerDistance().length();
     1175                    if(this->squaredaccuracy_ > minDistance)
     1176                        this->squaredaccuracy_ = minDistance;
     1177                    //waypoint = static_cast<WorldEntity*>(it);
     1178                    break;
     1179               // }*/
     1180            }
     1181        }
     1182        if(waypoint)
     1183            this->waypoints_.push_back(waypoint);
     1184    }
     1185
    11421186}
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8763 r8769  
    8484                { return this->botlevel_; }
    8585            static void setAllBotLevel(float level);
     86            //WAYPOINT FUNCTIONS
     87            void addWaypoint(WorldEntity* waypoint);
     88            WorldEntity* getWaypoint(unsigned int index) const;
     89
     90            inline void setAccuracy(float accuracy)
     91                { this->squaredaccuracy_ = accuracy*accuracy; }
     92            inline float getAccuracy() const
     93                { return sqrt(this->squaredaccuracy_); }
     94            void updatePointsOfInterest(std::string name, float distance);
    8695
    8796        protected:
     
    149158            bool bShooting_;
    150159
    151             std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
    152             //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
    153160            float botlevel_; //<! Makes the level of a bot configurable.
    154             float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
    155 
    156161            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
    157162            Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
    158163            void setPreviousMode();
     164
     165            //WEAPONSYSTEM DATA
     166            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
     167            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
     168            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
    159169            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
    160170            bool bSetupWorked; //<! If false, setupWeapons() is called.
    161171            int getFiremode(std::string name);
     172
     173            //WAYPOINT DATA
     174            std::vector<WorldEntity*> waypoints_;
     175            size_t currentWaypoint_;
     176            float squaredaccuracy_;
    162177    };
    163178}
  • code/branches/ai2/src/orxonox/controllers/WaypointController.cc

    r5929 r8769  
    4040    {
    4141        RegisterObject(WaypointController);
    42 
    43         this->currentWaypoint_ = 0;
    44         this->setAccuracy(100);
    4542    }
    4643
    4744    WaypointController::~WaypointController()
    4845    {
    49         if (this->isInitialized())
    50         {
    51             for (size_t i = 0; i < this->waypoints_.size(); ++i)
    52                 this->waypoints_[i]->destroy();
    53         }
    5446    }
    5547
     
    5850        SUPER(WaypointController, XMLPort, xmlelement, mode);
    5951
    60         XMLPortParam(WaypointController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
    61         XMLPortObject(WaypointController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
     52        XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
     53        XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
    6254    }
    6355
     
    7668    }
    7769
    78     void WaypointController::addWaypoint(WorldEntity* waypoint)
    79     {
    80         this->waypoints_.push_back(waypoint);
    81     }
    82 
    83     WorldEntity* WaypointController::getWaypoint(unsigned int index) const
    84     {
    85         if (index < this->waypoints_.size())
    86             return this->waypoints_[index];
    87         else
    88             return 0;
    89     }
    9070}
  • code/branches/ai2/src/orxonox/controllers/WaypointController.h

    r5781 r8769  
    4747            virtual void tick(float dt);
    4848
    49             void addWaypoint(WorldEntity* waypoint);
    50             WorldEntity* getWaypoint(unsigned int index) const;
     49        protected:
    5150
    52             inline void setAccuracy(float accuracy)
    53                 { this->squaredaccuracy_ = accuracy*accuracy; }
    54             inline float getAccuracy() const
    55                 { return sqrt(this->squaredaccuracy_); }
    56 
    57         protected:
    58             std::vector<WorldEntity*> waypoints_;
    59             size_t currentWaypoint_;
    60             float squaredaccuracy_;
    6151    };
    6252}
Note: See TracChangeset for help on using the changeset viewer.