Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8719 for code/branches


Ignore:
Timestamp:
Jun 30, 2011, 5:20:39 PM (13 years ago)
Author:
jo
Message:

Trying to find a way to identify a weapon by its munition name. The result is not satisfactory though, since a munition name seems to be rarely defined.

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

Legend:

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

    r8711 r8719  
    4444#include "controllers/NewHumanController.h"
    4545#include "controllers/DroneController.h"
     46#include "weaponsystem/WeaponMode.h"
     47#include "weaponsystem/WeaponPack.h"
     48#include "weaponsystem/Weapon.h"
    4649
    4750namespace orxonox
     
    8588
    8689        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
    87         this->bSetupWorked = false;
    88         this->numberOfWeapons = 0;
    89         this->botlevel_ = 1.0f;
    90         this->mode_ = DEFAULT;
     90        this->bSetupWorked = false;
     91        this->numberOfWeapons = 0;
     92        this->botlevel_ = 1.0f;
     93        this->mode_ = DEFAULT;
    9194        this->timeout_=0;
    9295    }
     
    10711074            if(pawn)
    10721075            {
    1073                  for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++)
    1074                  {
    1075                       if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
    1076                       {
    1077                           weapons[i]=i;
    1078                           projectiles[i]=1;//TODO: how to express infinite ammo? how to get data??
     1076                for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++)
     1077                {
     1078                    const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
     1079                    /*if(wpn=="")
     1080                        weapons[i]=-1;
     1081                    else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-(
     1082                        weapons[0]=0;
     1083                    else if(wpn=="LENSFLARE")//TODO: insert right munition name
     1084                        weapons[1]=1;
     1085                    else if(wpn=="SIMPLEROCKET")//TODO: insert right munition name
     1086                        weapons[2]=2;
     1087                    else if(wpn=="ROCKET")//TODO: insert right munition name
     1088                        weapons[3]=3;
     1089                    */
     1090                    if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
     1091                    {
     1092                        weapons[i]=i;
     1093                        projectiles[i]=1;//TODO: how to express infinite ammo? how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)
    10791094                          numberOfWeapons++;
    1080                       }
    1081                       else
    1082                           weapons[i]=-1;
    1083                  }
     1095                    }
     1096                    else
     1097                        weapons[i]=-1;
     1098                }
    10841099                 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
    10851100            }
    10861101        }
    10871102    }
     1103
     1104    const std::string& ArtificialController::getWeaponname(int i, Pawn* pawn)
     1105    {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions?
     1106        if(!pawn) return "";
     1107        WeaponPack* wPack = pawn->getWeaponPack(i);
     1108        if(!wPack) return "";
     1109        Weapon* wpn = wPack->getWeapon(i);
     1110        if(!wpn) return "";
     1111        WeaponMode* wMode = wpn->getWeaponmode(i);
     1112        if(!wMode) return "";
     1113        return wMode->getMunitionName();
     1114    }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName()
    10881115
    10891116   
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r8711 r8719  
    158158        private:
    159159            void setupWeapons();
     160            const std::string& getWeaponname(int i, Pawn* pawn);
    160161            bool bSetupWorked;
    161162    };
Note: See TracChangeset for help on using the changeset viewer.