Changeset 8762
- Timestamp:
- Jul 17, 2011, 11:43:20 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
r8761 r8762 318 318 this->bSetupWorked = false; // reset weapon information 319 319 this->numberOfWeapons = 0; 320 COUT(0)<<"ArtificialController::changedControllableEntity()"<<endl; //why is this function called more than once ??320 this->setupWeapons(); 321 321 } 322 322 … … 1040 1040 void ArtificialController::doFire() 1041 1041 { 1042 if(! bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...1042 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 1043 1043 { 1044 1044 this->setupWeapons(); 1045 1045 if(numberOfWeapons > 0) 1046 bSetupWorked = true;1046 this->bSetupWorked = true; 1047 1047 } 1048 1048 else if(this->getControllableEntity() && (numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 1049 1049 { 1050 1050 float random = rnd(1);// 1051 if (this->isCloseAtTarget(130) && weapons[1])1051 if (this->isCloseAtTarget(130) && (weaponModes[1]>-1) ) 1052 1052 {//LENSFLARE: short range weapon 1053 this->getControllableEntity()->fire( 1); //ai uses lens flare if they're close enough to the target1054 } 1055 else if( weapons[3]&& this->isCloseAtTarget(400) && (projectiles[3] > 0) && (random < this->botlevel_) )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_) ) 1056 1056 {//ROCKET: mid range weapon 1057 1057 this->mode_ = ROCKET; //Vector-implementation: mode_.push_back(ROCKET); 1058 this->getControllableEntity()->fire( 3); //launch rocket1058 this->getControllableEntity()->fire(weaponModes[3]); //launch rocket 1059 1059 if(this->getControllableEntity() && this->target_) //after fire(3) is called, getControllableEntity() refers to the rocket! 1060 1060 { … … 1068 1068 this->projectiles[3] -= 1; //decrease ammo 1069 1069 } 1070 else if (weapon s[0])//LASER: default weapon1071 this->getControllableEntity()->fire( 0);1070 else if (weaponModes[0]>-1) //LASER: default weapon 1071 this->getControllableEntity()->fire(weaponModes[0]); 1072 1072 } 1073 1073 } … … 1083 1083 if(pawn) 1084 1084 { 1085 this->analyseWeapons(pawn); 1086 for(unsigned int i=0; i < WeaponSystem::MAX_WEAPON_MODES; i++) 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++) 1087 1090 { 1088 //const std::string wpn = getWeaponname(i, 0, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info. 1089 /*if(wpn=="") //future, more generic implementation; until now, only LaserMunition works. Is this a bug?? 1090 weapons[i]=false; 1091 else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-( 1092 weapons[0]=true; 1093 else if(wpn=="FusionMunition") 1094 weapons[1]=true; 1095 else if(wpn=="TargetSeeking Rockets") 1096 weapons[2]=true; 1097 else if(wpn=="RocketMunition") 1098 weapons[3]=true; 1099 else 1100 COUT(1)<< wpn << + << " has to be added in ArtificialController.cc as new weapon." << std::endl; 1101 */ 1102 if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment! 1091 WeaponSlot* wSlot = pawn->getWeaponSlot(l); 1092 if(wSlot==NULL) continue; 1093 for(int i=0; i<max; i++) 1103 1094 { 1104 weapons[i] = true; 1105 projectiles[i] = 10; //TODO: how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user) 1106 numberOfWeapons++; 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; 1107 1108 } 1108 else1109 weapons[i] = false;1110 1109 } 1111 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); 1112 } 1113 } 1114 } 1115 1116 const std::string ArtificialController::getWeaponname(int i, int u, Pawn* pawn)//Search through all wPacks, 1117 {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions? 1118 if(!pawn) return "a"; 1119 WeaponPack* wPack = pawn->getWeaponPack(u); 1120 if(!wPack) return "b"; 1121 Weapon* wpn = wPack->getWeapon(i); 1122 if(!wpn && u<10 && i>0) 1123 { 1124 return this->getWeaponname(i, u+1, pawn); 1125 } 1126 else if(!wpn) 1127 return "c"; 1128 //return wpn->getName(); 1129 WeaponMode* wMode = wpn->getWeaponmode(0); 1130 if(!wMode) return "d"; 1131 return wMode->getMunitionName();//getName(); 1132 }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName() 1133 /** 1134 @brief Display how a spaceship is equiped with weapons. TODO: why are only 3 out of 8 weapons displayed?? 1135 */ 1136 void ArtificialController::analyseWeapons(Pawn* pawn) 1137 { 1138 int max = 10; 1139 if(!pawn) return; 1140 for(int l=0; l<max ;l++) 1141 { 1142 WeaponSlot* wSlot = pawn->getWeaponSlot(l); 1143 if(wSlot==NULL) continue;//{COUT(0)<<"WEAPONSLOT "<<l<< " failed"<<endl; continue;} 1144 for(int i=0; i<max; i++) 1145 { 1146 WeaponMode* wMode = wSlot->getWeapon()->getWeaponmode(i); 1147 if(wMode==NULL) continue;//{COUT(0)<<"WEAPONMODE "<<i<< " failed"<<endl;} 1148 COUT(0)<<wMode->getIdentifier()->getName()<< " using mode:"<<i<<endl; 1149 } 1110 if(numberOfWeapons>0) 1111 this->bSetupWorked = true; 1112 }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); 1150 1113 } 1151 1114 } … … 1177 1140 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 1178 1141 if(ship == NULL) return; 1179 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost1142 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost 1180 1143 this->getControllableEntity()->boost(true); 1181 else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost1144 else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost 1182 1145 this->getControllableEntity()->boost(false); 1183 1146 } -
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
r8757 r8762 150 150 151 151 int numberOfWeapons; //<! Used for weapon init function. Displayes number of weapons available for a bot. 152 bool weapons[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays if a weapon is available- managed by setupWeapons()152 int weaponModes[WeaponSystem::MAX_WEAPON_MODES]; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons() 153 153 int projectiles[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 154 154 float botlevel_; //<! Makes the level of a bot configurable. … … 159 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, int u, Pawn* pawn); //<! Function that links a weapon's firemode to its name.162 void analyseWeapons(Pawn* pawn);163 161 bool bSetupWorked; //<! If false, setupWeapons() is called. 164 162 };
Note: See TracChangeset
for help on using the changeset viewer.