Changeset 8763 for code/branches/ai2/src/orxonox
- Timestamp:
- Jul 18, 2011, 10:59:35 PM (13 years ago)
- Location:
- code/branches/ai2/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
r8762 r8763 91 91 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); 92 92 this->bSetupWorked = false; 93 this->numberOfWeapons = 0;94 93 this->botlevel_ = 0.5f; 95 94 this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT); … … 102 101 {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end()); 103 102 this->removeFromFormation(); 104 103 this->weaponModes_.clear(); 105 104 for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it) 106 105 { … … 317 316 this->removeFromFormation(); 318 317 this->bSetupWorked = false; // reset weapon information 319 this->numberOfWeapons = 0;320 318 this->setupWeapons(); 321 319 } … … 1043 1041 { 1044 1042 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; 1050 1047 float random = rnd(1);// 1051 if (this->isCloseAtTarget(130) && ( weaponModes[1]>-1))1048 if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun"))>-1 ) 1052 1049 {//LENSFLARE: short range weapon 1053 this->getControllableEntity()->fire( weaponModes[1]); //ai uses lens flare if they're close enough to the target1054 } 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)) 1056 1053 {//ROCKET: mid range weapon 1057 1054 this->mode_ = ROCKET; //Vector-implementation: mode_.push_back(ROCKET); 1058 this->getControllableEntity()->fire( weaponModes[3]); //launch rocket1055 this->getControllableEntity()->fire(firemode); //launch rocket 1059 1056 if(this->getControllableEntity() && this->target_) //after fire(3) is called, getControllableEntity() refers to the rocket! 1060 1057 { … … 1066 1063 else 1067 1064 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); 1072 1068 } 1073 1069 } … … 1078 1074 void ArtificialController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions) 1079 1075 { 1076 this->bSetupWorked = false; 1080 1077 if(this->getControllableEntity()) 1081 1078 { … … 1083 1080 if(pawn) 1084 1081 { 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++) 1090 1085 { 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++) 1094 1088 { 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(); 1108 1092 } 1109 1093 } 1110 if( numberOfWeapons>0)1094 if(weaponModes_.size())//at least one weapon detected 1111 1095 this->bSetupWorked = true; 1112 1096 }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); … … 1146 1130 } 1147 1131 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 1148 1142 } -
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
r8762 r8763 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include < vector>34 #include <map> 35 35 36 36 #include "util/Math.h" … … 149 149 bool bShooting_; 150 150 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() 154 153 float botlevel_; //<! Makes the level of a bot configurable. 155 154 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) … … 160 159 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 161 160 bool bSetupWorked; //<! If false, setupWeapons() is called. 161 int getFiremode(std::string name); 162 162 }; 163 163 }
Note: See TracChangeset
for help on using the changeset viewer.