- Timestamp:
- Nov 1, 2015, 9:10:08 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10731 r10737 27 27 */ 28 28 #include "controllers/CommonController.h" 29 /* 30 #include "weaponsystem/WeaponMode.h" 31 #include "weaponsystem/WeaponPack.h" 32 #include "weaponsystem/Weapon.h" 33 #include "weaponsystem/WeaponSlot.h" 34 #include "weaponsystem/WeaponSlot.h" 35 #include "worldentities/pawns/SpaceShip.h" 36 */ 29 37 30 38 namespace orxonox … … 37 45 CommonController::CommonController(Context* context) : Controller(context) 38 46 { 47 //this->bSetupWorked = false; 39 48 40 49 RegisterObject(CommonController); … … 170 179 } 171 180 } 181 182 /* 183 int CommonController::getFiremode(std::string name) 184 { 185 for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it) 186 { 187 if (it->first == name) 188 return it->second; 189 } 190 return -1; 191 } 192 bool CommonController::isCloseAtTarget(float distance) const 193 { 194 if (!this->getControllableEntity()) 195 return false; 196 197 if (!this->target_) 198 return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 199 else 200 return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance); 201 } 202 void CommonController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions) 203 { 204 this->bSetupWorked = false; 205 if(this->getControllableEntity()) 206 { 207 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 208 if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip 209 { 210 this->weaponModes_.clear(); // reset previous weapon information 211 WeaponSlot* wSlot = 0; 212 for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++) 213 { 214 WeaponMode* wMode = 0; 215 for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++) 216 { 217 std::string wName = wMode->getIdentifier()->getName(); 218 if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new" 219 weaponModes_[wName] = wMode->getMode(); 220 } 221 } 222 if(weaponModes_.size())//at least one weapon detected 223 this->bSetupWorked = true; 224 }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); 225 } 226 } 172 227 void CommonController::doFire() 173 228 { 174 if (this->isLookingAtTarget(math::pi / 20.0f)) 175 this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target 229 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 230 { 231 this->setupWeapons(); 232 } 233 else if(this->getControllableEntity() && 234 weaponModes_.size()&& 235 this->bShooting_ && 236 this->isCloseAtTarget((3)*1000) && 237 this->isLookingAtTarget(math::pi / 20.0f)) 238 { 239 int firemode; 240 float random = rnd(1);// 241 if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun")) > -1 ) 242 {//LENSFLARE: short range weapon 243 this->getControllableEntity()->fire(firemode); //ai uses lens flare if they're close enough to the target 244 } 245 246 else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon 247 this->getControllableEntity()->fire(firemode); 248 } 176 249 } 177 250 bool CommonController::isLookingAtTarget(float angle) const … … 196 269 if (pawn) 197 270 pawn->setAimPosition(aimPosition); 198 } 271 }*/ 199 272 200 273
Note: See TracChangeset
for help on using the changeset viewer.