- Timestamp:
- Jul 7, 2011, 7:17:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
r8735 r8736 39 39 #include "worldentities/pawns/Pawn.h" 40 40 #include "worldentities/pawns/TeamBaseMatchBase.h" 41 #include "worldentities/pawns/SpaceShip.h" 41 42 #include "gametypes/TeamDeathmatch.h" 42 43 #include "gametypes/Dynamicmatch.h" … … 47 48 #include "weaponsystem/WeaponPack.h" 48 49 #include "weaponsystem/Weapon.h" 50 49 51 50 52 namespace orxonox … … 1038 1040 { 1039 1041 this->setupWeapons(); 1040 if(numberOfWeapons>0) 1041 bSetupWorked=true; 1042 } 1043 else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 1044 { 1045 if (this->isCloseAtTarget(130) &&weapons[1] ) 1042 if(numberOfWeapons > 0) 1043 bSetupWorked = true; 1044 } 1045 else if(this->getControllableEntity() && (numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 1046 { 1047 float random = rnd(1);// 1048 if (this->isCloseAtTarget(130) && weapons[1] ) 1046 1049 {//LENSFLARE: short range weapon 1047 1050 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target 1048 1051 } 1049 else if(weapons[3] && this->isCloseAtTarget(400) /*&&projectiles[3]*/)1052 else if(weapons[3] && this->isCloseAtTarget(400) && (projectiles[3] > 0) && (random < this->botlevel_) ) 1050 1053 {//ROCKET: mid range weapon 1051 //TODO: How many rockets are available? 1052 this->mode_ = ROCKET;//Vector-implementation: mode_.push_back(ROCKET); 1053 this->getControllableEntity()->fire(3);//launch rocket 1054 if(this->getControllableEntity()&&this->target_)//after fire(3) getControllableEntity() refers to the rocket! 1054 this->mode_ = ROCKET; //Vector-implementation: mode_.push_back(ROCKET); 1055 this->getControllableEntity()->fire(3); //launch rocket 1056 if(this->getControllableEntity() && this->target_) //after fire(3) is called, getControllableEntity() refers to the rocket! 1055 1057 { 1056 1058 float speed = this->getControllableEntity()->getVelocity().length() - target_->getVelocity().length(); 1057 1059 if(!speed) speed = 0.1f; 1058 1060 float distance = target_->getPosition().length() - this->getControllableEntity()->getPosition().length(); 1059 this->timeout_= distance/speed*sgn(speed*distance) + 1.8f; //predicted time of target hit (+ tolerance)1061 this->timeout_= distance/speed*sgn(speed*distance) + 1.8f; //predicted time of target hit (+ tolerance) 1060 1062 } 1061 1063 else 1062 this->timeout_ = 4.0f;//TODO: find better default value 1063 1064 this->projectiles[3]-=1;//decrease ammo !! 1064 this->timeout_ = 4.0f; //TODO: find better default value 1065 this->projectiles[3] -= 1; //decrease ammo 1065 1066 } 1066 1067 else if (weapons[0])//LASER: default weapon … … 1079 1080 if(pawn) 1080 1081 { 1081 for(unsigned int i=0; i <WeaponSystem::MAX_WEAPON_MODES; i++)1082 for(unsigned int i=0; i < WeaponSystem::MAX_WEAPON_MODES; i++) 1082 1083 { 1083 //const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.1084 /*if(wpn=="") 1084 const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info. 1085 /*if(wpn=="") //future, more generic implementation; until now, only LaserMunition works. Is this a bug?? 1085 1086 weapons[i]=false; 1086 1087 else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-( … … 1097 1098 if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment! 1098 1099 { 1099 weapons[i] =true;1100 projectiles[i] =1;//TODO: how to express infinite ammo?how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)1100 weapons[i] = true; 1101 projectiles[i] = 10; //TODO: how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user) 1101 1102 numberOfWeapons++; 1102 1103 } 1103 1104 else 1104 weapons[i] =-false;1105 weapons[i] = false; 1105 1106 } 1106 1107 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); … … 1143 1144 } 1144 1145 1146 void ArtificialController::boostControl() 1147 { 1148 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 1149 if(ship == NULL) return; 1150 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() )//upper limit ->boost 1151 this->getControllableEntity()->boost(true); 1152 else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower())//lower limit ->do not boost 1153 this->getControllableEntity()->boost(false); 1154 } 1155 1145 1156 }
Note: See TracChangeset
for help on using the changeset viewer.