turret.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef TURRET_H_
  2. #define TURRET_H_
  3. /*-------------------------------------------------------------------------
  4. * Class: TurretDrone
  5. *-------------------------------------------------------------------------
  6. * Purpose:
  7. * Turrets are gun towers that are dangerous when deployed, but vulnerable
  8. * while moving. When they do move, they CANNOT shoot, and they HAVE NO SHIELDS.
  9. */
  10. class TurretDrone : public Drone
  11. {
  12. public:
  13. TurretDrone(IshipIGC* id) : // Constructor, start deployed
  14. Drone(id, c_dtTurret), // drone init
  15. moving(true) // set true so that we can prepare to fire
  16. {
  17. PrepareToFire();
  18. };
  19. void PrepareToMove(void); // Change to vulnerable moving state
  20. void PrepareToFire(void); // Deploy and prepare to attack
  21. protected:
  22. virtual void SetGoal(CommandType x, ImodelIGC* pTarget = NULL, bool reply = false);
  23. // Redefine Drone::SetGoal(CommandType, ImodelIGC*, bool)
  24. Goal* GetNewDefaultGoal(void); // Define the turret's default goal
  25. private:
  26. bool moving; // True = vulnerable, not shooting, False = no moving
  27. };
  28. /*-------------------------------------------------------------------------
  29. * Class: TurretAttackGoal
  30. *-------------------------------------------------------------------------
  31. * Purpose:
  32. * The turret attack consists of three basic elements:
  33. * 1) if we are not given any targets, then stay put and shoot at the closest
  34. * enemy.
  35. * 2) if we are given a static object as a target, and it is out of our range,
  36. * then redeploy so that we are in range, and start shooting at it.
  37. * 3) if we are given a dynamic object as a target, and it is out of range,
  38. * then don't move, just keep doing #1. Whenever that target is in range,
  39. * though, we will try to shoot at it.
  40. */
  41. class TurretAttackGoal : public TargetedGoal
  42. {
  43. public:
  44. TurretAttackGoal (Drone* pDrone, ImodelIGC* pTarget) :
  45. TargetedGoal(pDrone, pTarget, c_ctDestroy),
  46. m_pLastTarget(NULL)
  47. {};
  48. virtual void Update(Time now, float dt);
  49. virtual void Status()
  50. {
  51. if (m_pTarget)
  52. {
  53. if (m_pLastTarget == m_pTarget)
  54. Report("Attempting to destroy %s", GetModelName(m_pTarget));
  55. else
  56. Report("%s is out of range...", GetModelName(m_pTarget));
  57. }
  58. if (m_pLastTarget)
  59. Report("I'm currently attacking %s", GetModelName(m_pLastTarget));
  60. else
  61. Report("I'm on the lookout for enemy ships");
  62. };
  63. virtual bool Done(void)
  64. {
  65. return false; // Don't ever have to stop, this what turrets do.
  66. };
  67. private:
  68. TRef<ImodelIGC> m_pLastTarget; // This is really just for status info, remember the last thing I was shooting at
  69. };
  70. #endif