- Timestamp:
- Nov 2, 2015, 4:48:27 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10737 r10759 27 27 */ 28 28 #include "controllers/CommonController.h" 29 /* 29 #include "core/XMLPort.h" 30 30 31 #include "weaponsystem/WeaponMode.h" 31 32 #include "weaponsystem/WeaponPack.h" … … 34 35 #include "weaponsystem/WeaponSlot.h" 35 36 #include "worldentities/pawns/SpaceShip.h" 36 */ 37 37 38 38 39 namespace orxonox … … 40 41 41 42 RegisterClass(CommonController); 42 static const float SPEED = 0.6f;43 static const float ROTATEFACTOR = 0.2f;43 float SPEED = 0.7f; 44 float ROTATEFACTOR = 0.3f; 44 45 45 46 CommonController::CommonController(Context* context) : Controller(context) 46 47 { 47 //this->bSetupWorked = false;48 this->bSetupWorked = false; 48 49 49 50 RegisterObject(CommonController); … … 55 56 } 56 57 57 58 58 void CommonController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 59 { 60 SUPER(CommonController, XMLPort, xmlelement, mode); 61 XMLPortParam(CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode); 62 63 } 64 void CommonController::setFormationModeXML(std::string val) 65 { 66 const std::string valUpper = getUppercase(val); 67 FormationMode::Value value; 68 if (valUpper == "VEE") 69 value = FormationMode::VEE; 70 else if (valUpper == "WALL") 71 value = FormationMode::WALL; 72 else if (valUpper == "FINGER4") 73 value = FormationMode::FINGER4; 74 else if (valUpper == "DIAMOND") 75 value = FormationMode::DIAMOND; 76 else 77 ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'."); 78 this->setFormationMode(value); 79 80 } 81 std::string CommonController::getFormationModeXML() 82 { 83 switch (this->formationMode_) 84 { 85 case FormationMode::VEE: 86 { 87 return "VEE"; 88 break; 89 } 90 case FormationMode::WALL: 91 { 92 return "WALL"; 93 break; 94 } 95 case FormationMode::FINGER4: 96 { 97 return "FINGER4"; 98 break; 99 } 100 case FormationMode::DIAMOND: 101 { 102 return "DIAMOND"; 103 break; 104 } 105 default: 106 return "DIAMOND"; 107 break; 108 109 } 110 } 59 111 60 112 bool CommonController::setWingman (CommonController* wingman) … … 67 119 return true; 68 120 } 69 121 void CommonController::setTarget(ControllableEntity* target) 122 { 123 this->target_ = target; 124 orxout (internal_error) << " TARGET SET " << endl; 125 if (target) 126 this->targetPosition_ = target->getPosition(); 127 } 70 128 71 129 … … 113 171 while(diff>math::twoPi) diff-=math::twoPi; 114 172 while(diff<-math::twoPi) diff+=math::twoPi; 115 this->getControllableEntity()->rotateRoll( -diff);173 this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR); 116 174 } 117 175 void CommonController::copyTargetOrientation() … … 134 192 if (!this->getControllableEntity()) 135 193 return; 194 if (this->rank_ == Rank::DIVISIONLEADER) 195 SPEED *= 0.8; 196 if (this->rank_ == Rank::SECTIONLEADER) 197 SPEED *= 0.9; 136 198 137 199 //100 is (so far) the smallest tolerance (empirically found) that can be reached, 138 200 //with smaller distance spaceships can't reach position and go circles around it instead 139 int tolerance = 100;201 int tolerance = 60; 140 202 141 203 ControllableEntity* entity = this->getControllableEntity(); … … 160 222 161 223 //300 works, maybe less is better 162 if (distance < 300)224 if (distance < 400) 163 225 { 164 226 //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory … … 180 242 } 181 243 182 /* 244 183 245 int CommonController::getFiremode(std::string name) 184 246 { … … 227 289 void CommonController::doFire() 228 290 { 229 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...291 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 230 292 { 231 293 this->setupWeapons(); 232 294 } 233 else if(this->getControllableEntity() && 234 weaponModes_.size()&& 235 this->bShooting_ && 236 this->isCloseAtTarget((3)*1000) && 237 this->isLookingAtTarget(math::pi / 20.0f)) 295 else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ && 296 this->isCloseAtTarget((1 + 2)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 238 297 { 239 298 int firemode; … … 246 305 else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon 247 306 this->getControllableEntity()->fire(firemode); 307 248 308 } 249 309 } … … 269 329 if (pawn) 270 330 pawn->setAimPosition(aimPosition); 271 } */331 } 272 332 273 333
Note: See TracChangeset
for help on using the changeset viewer.