Changeset 10737 for code/branches/AI_HS15
- Timestamp:
- Nov 1, 2015, 9:10:08 AM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
r10717 r10737 82 82 void ArtificialController::changedControllableEntity() 83 83 { 84 FormationController::changedControllableEntity(); // super 85 84 86 if (!this->getControllableEntity()) 85 87 this->removeFromFormation(); -
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 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10731 r10737 33 33 #include "controllers/Controller.h" 34 34 #include "worldentities/ControllableEntity.h" 35 #include "worldentities/pawns/Pawn.h"36 35 /*#include "worldentities/pawns/Pawn.h" 36 */ 37 37 38 38 namespace orxonox … … 81 81 void moveToPosition(const Vector3& target); 82 82 void moveToTargetPosition(); 83 //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes 83 84 84 85 //Mode mode_; 85 86 void copyOrientation(const Quaternion& orient); 86 87 void copyTargetOrientation(); 87 88 89 /* bool isCloseAtTarget(float distance) const; 88 90 void doFire(); 89 91 void aimAtTarget(); 90 92 bool isLookingAtTarget(float angle) const; 93 94 95 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() 96 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 97 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) 98 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 99 bool bSetupWorked; //<! If false, setupWeapons() is called. 100 int getFiremode(std::string name); 101 */ 91 102 92 103 bool bHasTargetPosition_; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10731 r10737 60 60 if (this->target_) 61 61 { 62 this->aimAtTarget(); 63 this->doFire(); 62 //this->aimAtTarget(); 63 //this->doFire(); 64 //this->bShooting_ = true; 64 65 } 65 66 … … 76 77 setTargetPositionOfFollower(); 77 78 setTargetPositionOfWingman(); 78 79 /* 79 80 for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) 80 81 { … … 85 86 break; 86 87 } 87 } 88 }*/ 88 89 89 90 -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
r10719 r10737 1087 1087 } 1088 1088 1089 void FormationController::changedControllableEntity() 1090 { 1091 Controller::changedControllableEntity(); // super 1092 1093 // when changing the controllable entity, ensure that the controller does not use the new entity as target 1094 if (this->target_ && this->getControllableEntity() == static_cast<ControllableEntity*>(this->target_)) 1095 this->forgetTarget(); 1096 } 1089 1097 } -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
r10717 r10737 99 99 FormationController* getSlave( void ) { return this->slaves_.back(); } 100 100 101 virtual void changedControllableEntity(); 102 101 103 protected: 102 104 bool formationFlight_;
Note: See TracChangeset
for help on using the changeset viewer.