Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8763 for code/branches/ai2/src


Ignore:
Timestamp:
Jul 18, 2011, 10:59:35 PM (13 years ago)
Author:
jo
Message:

New implementation. New bug. Bots use only yellow energy munition (LightningGun).

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

Legend:

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

    r8762 r8763  
    9191        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
    9292        this->bSetupWorked = false;
    93         this->numberOfWeapons = 0;
    9493        this->botlevel_ = 0.5f;
    9594        this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
     
    102101        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
    103102            this->removeFromFormation();
    104 
     103            this->weaponModes_.clear();
    105104            for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
    106105            {
     
    317316            this->removeFromFormation();
    318317        this->bSetupWorked = false;        // reset weapon information
    319         this->numberOfWeapons = 0;
    320318        this->setupWeapons();
    321319    }
     
    10431041        {
    10441042            this->setupWeapons();
    1045             if(numberOfWeapons > 0)
    1046                 this->bSetupWorked = true;
    1047         }
    1048         else if(this->getControllableEntity() && (numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
    1049         {
     1043        }
     1044        else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
     1045        {
     1046            int firemode;
    10501047            float random = rnd(1);//
    1051             if (this->isCloseAtTarget(130) && (weaponModes[1]>-1) )
     1048            if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun"))>-1 )
    10521049            {//LENSFLARE: short range weapon
    1053                 this->getControllableEntity()->fire(weaponModes[1]); //ai uses lens flare if they're close enough to the target
    1054             }
    1055             else if( (weaponModes[3]>-1) && this->isCloseAtTarget(400) && (projectiles[3] > 0) && (random < this->botlevel_) )
     1050                this->getControllableEntity()->fire(firemode); //ai uses lens flare if they're close enough to the target
     1051            }
     1052            else if( this->isCloseAtTarget(400) && (random < this->botlevel_) && (firemode = getFiremode("RocketFire")>-1))
    10561053            {//ROCKET: mid range weapon
    10571054                this->mode_ = ROCKET; //Vector-implementation: mode_.push_back(ROCKET);
    1058                 this->getControllableEntity()->fire(weaponModes[3]); //launch rocket
     1055                this->getControllableEntity()->fire(firemode); //launch rocket
    10591056                if(this->getControllableEntity() && this->target_) //after fire(3) is called, getControllableEntity() refers to the rocket!
    10601057                {
     
    10661063                else
    10671064                    this->timeout_ = 4.0f; //TODO: find better default value
    1068                 this->projectiles[3] -= 1; //decrease ammo
    1069             }
    1070             else if (weaponModes[0]>-1) //LASER: default weapon
    1071                 this->getControllableEntity()->fire(weaponModes[0]);
     1065            }
     1066            else if ((firemode = getFiremode("HsW01")>-1)) //LASER: default weapon
     1067                this->getControllableEntity()->fire(firemode);
    10721068        }
    10731069    }
     
    10781074    void ArtificialController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
    10791075    {
     1076        this->bSetupWorked = false;
    10801077        if(this->getControllableEntity())
    10811078        {
     
    10831080            if(pawn)
    10841081            {
    1085                 int max = WeaponSystem::MAX_WEAPON_MODES; // assumption: there are only so many weaponmodes possible
    1086                 for(int x=0; x<max ;x++)
    1087                     weaponModes[x] = -1; // reset previous weapon information
    1088                 this->numberOfWeapons = 0;
    1089                 for(int l=0; l<max ;l++)
     1082                this->weaponModes_.clear(); // reset previous weapon information
     1083                WeaponSlot* wSlot = 0;
     1084                for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
    10901085                {
    1091                     WeaponSlot* wSlot = pawn->getWeaponSlot(l);
    1092                     if(wSlot==NULL) continue;
    1093                     for(int i=0; i<max; i++)
     1086                    WeaponMode* wMode = 0;
     1087                    for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
    10941088                    {
    1095                         WeaponMode* wMode = wSlot->getWeapon()->getWeaponmode(i);
    1096                         if(wMode == NULL) continue;
    1097                         this->numberOfWeapons++;
    1098                         if(wMode->getIdentifier()->getName() == "HsW01") // red laser <-> 0
    1099                             weaponModes[0] = wMode->getMode();
    1100                         else if(wMode->getIdentifier()->getName() == "LightningGun") // yellow energy  <-> 1
    1101                             weaponModes[1] = wMode->getMode();
    1102                         else if(wMode->getIdentifier()->getName() == "SimpleRocketFire") // target seeking rocktes <-> 2
    1103                             weaponModes[2] = wMode->getMode(); // not relevant jet, since doFire() doesn't support simple rockets
    1104                         else if(wMode->getIdentifier()->getName() == "RocketFire") // manual rockets <-> 3
    1105                             weaponModes[3] = wMode->getMode();
    1106                         else
    1107                             COUT(1)<< wMode->getIdentifier()->getName() << " has to be added in ArtificialController.cc as new weapon." << std::endl;
     1089                        std::string wName = wMode->getIdentifier()->getName();
     1090                        if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
     1091                            weaponModes_[wName] = wMode->getMode();
    11081092                    }
    11091093                }
    1110                 if(numberOfWeapons>0)
     1094                if(weaponModes_.size())//at least one weapon detected
    11111095                    this->bSetupWorked = true;
    11121096            }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
     
    11461130    }
    11471131
     1132    int ArtificialController::getFiremode(std::string name)
     1133    {
     1134        for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
     1135        {
     1136            if (it->first == name)
     1137                return it->second;
     1138        }
     1139        return -1;
     1140    }
     1141
    11481142}
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8762 r8763  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include <vector>
     34#include <map>
    3535
    3636#include "util/Math.h"
     
    149149            bool bShooting_;
    150150
    151             int numberOfWeapons; //<! Used for weapon init function. Displayes number of weapons available for a bot.
    152             int weaponModes[WeaponSystem::MAX_WEAPON_MODES]; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
    153             int projectiles[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
     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()
    154153            float botlevel_; //<! Makes the level of a bot configurable.
    155154            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
     
    160159            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
    161160            bool bSetupWorked; //<! If false, setupWeapons() is called.
     161            int getFiremode(std::string name);
    162162    };
    163163}
Note: See TracChangeset for help on using the changeset viewer.