mining.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "pch.h"
  2. /*-------------------------------------------------------------------------
  3. * Function: MiningDrone::GetNewDefaultGoal
  4. *-------------------------------------------------------------------------
  5. * Purpose:
  6. * When the mining drone needs to figure out what to do, he should either
  7. * mine or unload depending on how full he is already
  8. */
  9. Goal* MiningDrone::GetNewDefaultGoal(void)
  10. {
  11. if (fMiningTime*2 < fMiningTimeLimit)
  12. {
  13. ImodelIGC* pmodel = FindTarget(m_pShip,
  14. c_ttNeutral | c_ttAsteroid | c_ttNearest | c_ttAnyCluster,
  15. NULL, NULL, NULL, NULL,
  16. c_aabmMineHe3);
  17. if (pmodel)
  18. {
  19. Verbose("I don't have much Helium 3, I'd better go mine");
  20. return new MineGoal(this, pmodel);
  21. }
  22. }
  23. //Either no place to mine or mostly full ... try to unload if there's anything to unload
  24. if (fMiningTime != 0.0f)
  25. {
  26. IstationIGC* pstation = (IstationIGC*)GetUnloadStation();
  27. if (pstation)
  28. {
  29. Verbose("OK, I'm at least half full, so I'll go unload");
  30. return new UnloadGoal(this, pstation);
  31. }
  32. }
  33. return NULL;
  34. };
  35. /*-------------------------------------------------------------------------
  36. * Function: UnloadGoal::Update
  37. *-------------------------------------------------------------------------
  38. * Purpose:
  39. * If we don't have a target station, then find one. Otherwise just goto
  40. * it. We could make this use the goto function, probably.
  41. */
  42. void UnloadGoal::Update(Time now, float dt)
  43. {
  44. assert (m_pTarget);
  45. NewGotoGoal::Update(now, dt);
  46. }
  47. /*-------------------------------------------------------------------------
  48. * Function: MineGoal::Update
  49. *-------------------------------------------------------------------------
  50. * Purpose:
  51. * If we don't have a target asteroid, then find one. Given a target, we
  52. * want to move up right next to it, and start rotating (for lack of a better
  53. * effect). Also have to increment the MiningTime value
  54. *
  55. * Notes:
  56. * Right now, when the miners are actually at their target and mining, then they
  57. * are not dodging incoming projectiles. Rob has expressed interest in something
  58. * like this: If the miner is getting injured (maybe save the current hitpoints
  59. * when we start mining and compare to that??), then he should stop mining, send a
  60. * chat message saying "I'm under attack, please help", and then just start orbitting
  61. * the asteroid with a very small radius for defense.
  62. */
  63. void MineGoal::Update(Time now, float dt)
  64. {
  65. assert (m_pTarget);
  66. if (m_pTarget->GetCluster() == m_pShip->GetCluster())
  67. {
  68. // Are we close enough to our target to mine it ... distance < 50.0f
  69. Vector dp = m_pTarget->GetPosition() - m_pShip->GetPosition();
  70. float distance2 = dp.LengthSquared();
  71. float radius = m_pTarget->GetRadius() + m_pShip->GetRadius() + 60.0f;
  72. if (distance2 < radius * radius)
  73. {
  74. // We are close enough to mine ... do it.
  75. // Keep facing the target, and add a little roll for effect
  76. ControlData controls;
  77. float deltaAngle = turnToFace(dp, dt, m_pShip, &controls, m_pDrone->GetMoveSkill());
  78. controls.jsValues[c_axisRoll] = 1.0f;
  79. controls.jsValues[c_axisThrottle] = -1.0f;
  80. // Zero the motion & weapon bits
  81. m_pShip->SetStateBits(now, weaponsMaskIGC | buttonsMaskIGC, miningMaskIGC);
  82. m_pShip->SetControls(controls);
  83. // Increment the amount of time that we have been mining appropriately
  84. MiningDrone* pDrone;
  85. CastTo(pDrone, m_pDrone);
  86. assert (m_pTarget->GetObjectType() == OT_asteroid);
  87. pDrone->fMiningTime += ((IasteroidIGC*)((ImodelIGC*)m_pTarget))->MineOre(dt * m_pShip->GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaMiningRate));
  88. return;
  89. }
  90. }
  91. NewGotoGoal::Update(now, dt);
  92. }