Changeset 8757 for code/branches/ai2/src/orxonox
- Timestamp:
- Jul 13, 2011, 9:42:03 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
r8736 r8757 33 33 34 34 #include "util/Math.h" 35 #include "util/Convert.h" 35 36 #include "core/CoreIncludes.h" 36 37 #include "core/XMLPort.h" … … 1047 1048 float random = rnd(1);// 1048 1049 if (this->isCloseAtTarget(130) && weapons[1] ) 1049 {//LENSFLARE: short range weapon 1050 {//LENSFLARE: short range weapon 1050 1051 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target 1051 1052 } … … 1080 1081 if(pawn) 1081 1082 { 1083 this->analyseWeapons(pawn); 1082 1084 for(unsigned int i=0; i < WeaponSystem::MAX_WEAPON_MODES; i++) 1083 1085 { 1084 const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.1086 //const std::string wpn = getWeaponname(i, 0, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info. 1085 1087 /*if(wpn=="") //future, more generic implementation; until now, only LaserMunition works. Is this a bug?? 1086 1088 weapons[i]=false; … … 1110 1112 } 1111 1113 1112 const std::string & ArtificialController::getWeaponname(int i, Pawn* pawn)1114 const std::string ArtificialController::getWeaponname(int i, int u, Pawn* pawn)//Search through all wPacks, 1113 1115 {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions? 1114 if(!pawn) return " ";1115 WeaponPack* wPack = pawn->getWeaponPack( i);1116 if(!wPack) return " ";1116 if(!pawn) return "a"; 1117 WeaponPack* wPack = pawn->getWeaponPack(u); 1118 if(!wPack) return "b"; 1117 1119 Weapon* wpn = wPack->getWeapon(i); 1118 if(!wpn) return ""; 1119 WeaponMode* wMode = wpn->getWeaponmode(i); 1120 if(!wMode) return ""; 1121 return wMode->getMunitionName(); 1120 if(!wpn && u<10 && i>0) 1121 { 1122 return this->getWeaponname(i, u+1, pawn); 1123 } 1124 else if(!wpn) 1125 return "c"; 1126 //return wpn->getName(); 1127 WeaponMode* wMode = wpn->getWeaponmode(0); 1128 if(!wMode) return "d"; 1129 return wMode->getMunitionName();//getName(); 1122 1130 }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName() 1123 1124 1131 /** 1132 @brief Display how a spaceship is equiped with weapons. TODO: why are only 3 out of 8 weapons displayed?? 1133 */ 1134 void ArtificialController::analyseWeapons(Pawn* pawn) 1135 { 1136 int max=10, i=0, j=0, k=0; 1137 if(!pawn) {COUT(0)<<"NO PAWN"<<std::endl; return;} 1138 while(i<max) 1139 { 1140 WeaponPack* wPack = pawn->getWeaponPack(i); //WeaponSet* wSet = pawn->getWeaponSet(i); 1141 i++; 1142 if(wPack==NULL) continue; 1143 while(j<max) 1144 { 1145 Weapon* wpn = wPack->getWeapon(j); 1146 j++; 1147 if(wpn==NULL) continue; 1148 while(k<max) 1149 { 1150 WeaponMode* wMode = wpn->getWeaponmode(k); 1151 k++; 1152 if(wMode==NULL) continue; 1153 COUT(0)<<wMode->getName()<<": weaponpack "+multi_cast<std::string>(i-1)<<", weapon "<<multi_cast<std::string>(j-1)<<", weaponmode "<<multi_cast<std::string>(k-1)<<std::endl; 1154 } 1155 } 1156 } 1157 } 1158 1159 1125 1160 void ArtificialController::setBotLevel(float level) 1126 1161 { 1127 1162 if (level < 0.0f) 1128 this->botlevel_ = 0.0f; 1163 this->botlevel_ = 0.0f; 1129 1164 else if (level > 1.0f) 1130 1165 this->botlevel_ = 1.0f; … … 1132 1167 this->botlevel_ = level; 1133 1168 } 1134 1169 1135 1170 void ArtificialController::setAllBotLevel(float level) 1136 1171 { … … 1143 1178 this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back(); 1144 1179 } 1145 1180 1146 1181 void ArtificialController::boostControl() 1147 1182 { -
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
r8741 r8757 80 80 81 81 virtual void doFire(); 82 83 82 void setBotLevel(float level=1.0f); 83 inline float getBotLevel() const 84 84 { return this->botlevel_; } 85 85 static void setAllBotLevel(float level); … … 157 157 enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes 158 158 Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_; 159 void setPreviousMode(); 159 void setPreviousMode(); 160 160 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 161 const std::string& getWeaponname(int i, Pawn* pawn); //<! Function that links a weapon's firemode to its name. 161 const std::string getWeaponname(int i, int u, Pawn* pawn); //<! Function that links a weapon's firemode to its name. 162 void analyseWeapons(Pawn* pawn); 162 163 bool bSetupWorked; //<! If false, setupWeapons() is called. 163 164 };
Note: See TracChangeset
for help on using the changeset viewer.