Changeset 7832
- Timestamp:
- Jan 27, 2011, 3:58:04 PM (14 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r7284 r7832 220 220 this->moveToTargetPosition(); 221 221 222 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 223 this->getControllableEntity()->fire(0); 222 this->doFire(); 224 223 } 225 224 … … 241 240 } 242 241 243 242 if (this->state_ == FREE) 244 243 { 245 244 if (this->target_) … … 253 252 this->moveToTargetPosition(); 254 253 255 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 256 this->getControllableEntity()->fire(0); 254 this->doFire(); 257 255 } 258 256 -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r7401 r7832 84 84 85 85 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); 86 this->bSetupWorked = false; 87 this->numberOfWeapons = 0; 86 88 } 87 89 … … 1016 1018 return (team1 == team2 && team1 != -1); 1017 1019 } 1020 1021 void ArtificialController::doFire() 1022 { 1023 if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 1024 { 1025 this->setupWeapons(); 1026 if(numberOfWeapons>0) 1027 bSetupWorked=true; 1028 } 1029 else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 1030 { 1031 if (this->isCloseAtTarget(140) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) ) 1032 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target 1033 1034 //default fire (laser) 1035 else if ((weapons[0]==0)) 1036 this->getControllableEntity()->fire(0); 1037 } 1038 } 1039 void ArtificialController::setupWeapons() 1040 { 1041 if(this->getControllableEntity()) 1042 { 1043 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 1044 if(pawn) 1045 { 1046 for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++) 1047 { 1048 if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment! 1049 { 1050 weapons[i]=i; 1051 numberOfWeapons++; 1052 } 1053 else 1054 weapons[i]=-1; 1055 } 1056 } 1057 } 1058 } 1018 1059 } -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r7163 r7832 37 37 #include "Controller.h" 38 38 #include "controllers/NewHumanController.h" 39 #include "weaponsystem/WeaponSystem.h" 39 40 40 41 namespace orxonox … … 77 78 static void passivebehaviour(const bool passive); 78 79 static void formationsize(const int size); 80 81 virtual void doFire(); 79 82 80 83 protected: … … 138 141 WeakPtr<Pawn> target_; 139 142 bool bShooting_; 143 144 int numberOfWeapons; 145 int weapons[WeaponSystem::MAX_WEAPON_MODES]; 140 146 141 147 private: 148 void setupWeapons(); 149 bool bSetupWorked; 142 150 }; 143 151 }
Note: See TracChangeset
for help on using the changeset viewer.