Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. //In the same cluster as the target ... we dodge, turn to face the aim point and fire if close enough
  2.  
  3. Vector vecLeadPosition;
  4. float t = solveForLead(this, m_commandTargets[c_cmdPlan], m_mountedWeapons[0], &vecLeadPosition);
  5. float lifespan = m_mountedWeapons[0]->GetLifespan();
  6. bool bIisInRange = false;
  7.  
  8. if (t <= lifespan)
  9. bIisInRange = true;
  10.  
  11. // get needed qualities of the shooter
  12. Vector shipPosition = this->GetPosition();
  13. Vector shipAimDirection = this->GetOrientation().GetForward();
  14.  
  15. // get needed qualities of the shooter weapon
  16. IprojectileTypeIGC* pt = m_mountedWeapons[0]->GetProjectileType();
  17. float fProjectileSpeed = pt->GetSpeed();
  18.  
  19. // get needed qualities of the shootee
  20. Vector targetPosition = m_commandTargets[c_cmdPlan]->GetPosition();
  21. float fTargetRadius = m_commandTargets[c_cmdPlan]->GetRadius();
  22.  
  23. // compute the distance between the ships
  24. float fDistanceBetweenShips = (targetPosition - shipPosition).Length();
  25.  
  26. // compute the distance at which a hit could occur
  27. float fLengthAlongTargetVector = t * fProjectileSpeed;
  28.  
  29. // compute values needed for determining weapon in-range
  30. float fCosAngle = vecLeadPosition * shipAimDirection;
  31. float fA = fLengthAlongTargetVector;
  32. float fH = fA / fCosAngle;
  33. float fHASquared = (fH * fH) - (fA * fA);
  34. float fRadiusSquared = fTargetRadius * fTargetRadius;
  35. bool bWillHit = (fHASquared <= fRadiusSquared) ? true : false;
  36.  
  37. // project a tracking point at the target range
  38. Vector trackingRelativeToShip = shipAimDirection * fDistanceBetweenShips;
  39. Vector trackingPosition = shipPosition + trackingRelativeToShip;
  40.  
  41. float fShootSkill = m_fShootSkill; //imago 10/14 made these adjustable
  42. float fTurnSkill = m_fTurnSkill;
  43. int state = 0;
  44. bool bDodge = Dodge(this, NULL, &state);
  45. float da = turnToFace(vecLeadPosition, dT, this, &m_controls, fTurnSkill);
  46.  
  47.  
  48. m_controls.jsValues[c_axisThrottle] = 0.5f + ((pi - da) / (2.0f * pi));
  49.  
  50. const float c_fMaxOffAngle = 0.90f; //TODO skillz
  51. //float lifespan = m_mountedWeapons[0]->GetLifespan();
  52.  
  53. // commenting this to get strafe behavior from the drones BSW 10/28/1999
  54. //imago 10/14
  55. //if ((!bDodge) && (t <= lifespan * 0.25f) && fTurnSkill > 0.75f)
  56.  
  57. if (bWillHit = true)
  58. {
  59. //We are close and not dodging anything so ...
  60. //strafe
  61. state |= leftButtonIGC; //todo skillz - add randomness
  62. if (da < pi * 0.5f)
  63. {
  64. if (da > c_fMaxOffAngle)
  65. {
  66. //too close ... back off
  67. state |= backwardButtonIGC;
  68.  
  69. }
  70. else
  71. state |= forwardButtonIGC;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement