cctwatersurface.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. class CCTWaterSurface : CCTBase
  2. {
  3. protected const int HEIGHT_DIFF_LIMIT_METERS = 1.0;
  4. protected float m_MaximalActionDistanceSq;
  5. protected string m_SurfaceType; //!DEPRECATED
  6. protected ref array<string> m_AllowedSurfaceList;
  7. void CCTWaterSurface(float maximal_target_distance = UAMaxDistances.DEFAULT, string surfaceType = "")
  8. {
  9. m_MaximalActionDistanceSq = maximal_target_distance * maximal_target_distance;
  10. m_SurfaceType = surfaceType;
  11. m_AllowedSurfaceList = new array<string>();
  12. surfaceType.Split("|", m_AllowedSurfaceList);
  13. }
  14. override bool Can(PlayerBase player, ActionTarget target)
  15. {
  16. if (!target || (target && target.GetObject()))
  17. return false;
  18. //! use hit position from ActionTarget otherwise player's position
  19. vector hitPosition = target.GetCursorHitPos();
  20. string surfaceType;
  21. float waterLevel = player.GetCurrentWaterLevel();
  22. g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1] + waterLevel, hitPosition[2], surfaceType);
  23. if (waterLevel > 0.0)
  24. return Surface.AllowedWaterSurface(hitPosition[1] + waterLevel, surfaceType, m_AllowedSurfaceList);
  25. float surfaceHeight = g_Game.SurfaceY(hitPosition[0], hitPosition[2]);
  26. //! special handling for sea
  27. if (!surfaceType)
  28. {
  29. surfaceHeight = hitPosition[1];
  30. }
  31. float heightDiff = Math.AbsFloat(hitPosition[1] - surfaceHeight);
  32. if (surfaceType != "" && heightDiff > HEIGHT_DIFF_LIMIT_METERS)
  33. return false;
  34. float distSq = vector.DistanceSq(player.GetPosition(), hitPosition);
  35. if (distSq > m_MaximalActionDistanceSq)
  36. return false;
  37. return Surface.AllowedWaterSurface(hitPosition[1], surfaceType, m_AllowedSurfaceList);
  38. }
  39. override bool CanContinue(PlayerBase player, ActionTarget target)
  40. {
  41. return true;
  42. }
  43. }
  44. class CCTWaterSurfaceEx : CCTBase
  45. {
  46. protected float m_MaximalActionDistanceSq;
  47. protected int m_AllowedLiquidSource;
  48. void CCTWaterSurfaceEx(float maximal_target_distance, int allowedLiquidSource)
  49. {
  50. m_MaximalActionDistanceSq = maximal_target_distance * maximal_target_distance;
  51. m_AllowedLiquidSource = allowedLiquidSource;
  52. }
  53. override bool Can(PlayerBase player, ActionTarget target)
  54. {
  55. if (!target || (target && target.GetObject()))
  56. return false;
  57. vector hitPosition = target.GetCursorHitPos();
  58. string surfaceType;
  59. g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1], hitPosition[2], surfaceType);
  60. float distSq = vector.DistanceSq(player.GetPosition(), hitPosition);
  61. if (distSq > m_MaximalActionDistanceSq)
  62. return false;
  63. return Surface.CheckLiquidSource(hitPosition[1], surfaceType, m_AllowedLiquidSource);
  64. }
  65. override bool CanContinue(PlayerBase player, ActionTarget target)
  66. {
  67. return true;
  68. }
  69. }