PolygonTrigger.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // PolygonTrigger.h
  24. // Class to encapsulate polygon triggers for maps.
  25. // Note - Polygons are used for two reasons - one is area triggers for
  26. // scripts, so units can be tested for entering or exiting areas, and
  27. // second to specify areas that are filled with water in the map.
  28. // See the m_isWaterArea to differentiate.
  29. // Author: John Ahlquist, November 2001
  30. #pragma once
  31. #ifndef PolygonTrigger_H
  32. #define PolygonTrigger_H
  33. #include "Common/GameMemory.h"
  34. #include "Common/Snapshot.h"
  35. #include "Common/STLTypedefs.h"
  36. class DataChunkInput;
  37. class DataChunkOutput;
  38. struct DataChunkInfo;
  39. class PolygonTrigger;
  40. class Xfer;
  41. // ------------------------------------------------------------------------------------------------
  42. /** Water handles are used to represent instances of areas of water, no matter which type
  43. * of implementation the water is (grid, trigger area, etc) */
  44. // ------------------------------------------------------------------------------------------------
  45. class WaterHandle
  46. {
  47. public:
  48. WaterHandle( void ) { m_polygon = NULL; }
  49. ///@todo we need to formalize the water systems
  50. PolygonTrigger *m_polygon; ///< valid when water is a polygon area, NULL if water is a grid
  51. };
  52. // ------------------------------------------------------------------------------------------------
  53. // ------------------------------------------------------------------------------------------------
  54. class PolygonTrigger : public MemoryPoolObject,
  55. public Snapshot
  56. {
  57. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(PolygonTrigger, "PolygonTrigger")
  58. protected:
  59. PolygonTrigger* m_nextPolygonTrigger; ///< linked list.
  60. AsciiString m_triggerName; ///< The name of this polygon area.
  61. Int m_triggerID; ///< Unique int id for the trigger.
  62. WaterHandle m_waterHandle; ///< handle to use this polygon as a water table
  63. ICoord3D* m_points; ///< Points that are the polygon.
  64. Int m_numPoints; ///< Num points in m_points.
  65. Int m_sizePoints; ///< Space allocated for m_points.
  66. mutable IRegion2D m_bounds; ///< 2D bounding box for quick checks.
  67. mutable Real m_radius;
  68. Int m_riverStart; ///< Identifies the start point of the river.
  69. mutable Bool m_boundsNeedsUpdate;
  70. Bool m_exportWithScripts;
  71. Bool m_isWaterArea; ///< Used to specify water areas in the map.
  72. Bool m_isRiver; ///< Used to specify that a water area is a river.
  73. static PolygonTrigger* ThePolygonTriggerListPtr;
  74. static Int s_currentID; ///< Current id for new triggers.
  75. protected:
  76. void reallocate(void);
  77. void updateBounds(void) const;
  78. // snapshot methods
  79. virtual void crc( Xfer *xfer );
  80. virtual void xfer( Xfer *xfer );
  81. virtual void loadPostProcess( void );
  82. public:
  83. PolygonTrigger(Int initialAllocation);
  84. //~PolygonTrigger(void); ///< Note that deleting the head of a list deletes all linked objects in the list.
  85. public:
  86. static PolygonTrigger *getFirstPolygonTrigger(void) {return ThePolygonTriggerListPtr;}
  87. static PolygonTrigger *getPolygonTriggerByID(Int triggerID);
  88. static Bool ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData);
  89. /// Writes Triggers Info
  90. static void WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter);
  91. static void deleteTriggers(void);
  92. public:
  93. static void addPolygonTrigger(PolygonTrigger *pTrigger);
  94. static void removePolygonTrigger(PolygonTrigger *pTrigger);
  95. void setNextPoly(PolygonTrigger *nextPoly) {m_nextPolygonTrigger = nextPoly;} ///< Link the next map object.
  96. void addPoint(const ICoord3D &point);
  97. void setPoint(const ICoord3D &point, Int ndx);
  98. void insertPoint(const ICoord3D &point, Int ndx);
  99. void deletePoint(Int ndx);
  100. void setTriggerName(AsciiString name) {m_triggerName = name;};
  101. void getCenterPoint(Coord3D* pOutCoord) const;
  102. Real getRadius(void) const;
  103. public:
  104. const ICoord3D *getPoint(Int ndx) const {if (ndx<0) ndx=0; if (ndx>=m_numPoints) ndx=m_numPoints-1; return m_points+ndx;} ///< Get a point.
  105. Int getNumPoints(void) const {return m_numPoints;}
  106. Int getID(void) const {return m_triggerID;}
  107. PolygonTrigger *getNext(void) {return m_nextPolygonTrigger;}
  108. const PolygonTrigger *getNext(void) const {return m_nextPolygonTrigger;}
  109. AsciiString getTriggerName(void) const {return m_triggerName;} ///< Gets the trigger name.
  110. Bool pointInTrigger(ICoord3D &point) const;
  111. Bool doExportWithScripts(void) const {return m_exportWithScripts;}
  112. void setDoExportWithScripts(Bool val) {m_exportWithScripts = val;}
  113. Bool isWaterArea(void) const {return m_isWaterArea;}
  114. void setWaterArea(Bool val) {m_isWaterArea = val;}
  115. Bool isRiver(void) const {return m_isRiver;}
  116. void setRiver(Bool val) {m_isRiver = val;}
  117. Int getRiverStart(void) const {return m_riverStart;}
  118. void setRiverStart(Int val) {m_riverStart = val;}
  119. const WaterHandle* getWaterHandle(void) const;
  120. Bool isValid(void) const;
  121. };
  122. #endif