PolygonTrigger.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. AsciiString m_layerName; ///< Used to specify the layer in the World Builder.
  74. Bool m_shouldRender;
  75. Bool m_selected;
  76. static PolygonTrigger* ThePolygonTriggerListPtr;
  77. static Int s_currentID; ///< Current id for new triggers.
  78. protected:
  79. void reallocate(void);
  80. void updateBounds(void) const;
  81. // snapshot methods
  82. virtual void crc( Xfer *xfer );
  83. virtual void xfer( Xfer *xfer );
  84. virtual void loadPostProcess( void );
  85. public:
  86. PolygonTrigger(Int initialAllocation);
  87. //~PolygonTrigger(void); ///< Note that deleting the head of a list deletes all linked objects in the list.
  88. public:
  89. static PolygonTrigger *getFirstPolygonTrigger(void) {return ThePolygonTriggerListPtr;}
  90. static PolygonTrigger *getPolygonTriggerByID(Int triggerID);
  91. static Bool ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData);
  92. /// Writes Triggers Info
  93. static void WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter);
  94. static void deleteTriggers(void);
  95. public:
  96. static void addPolygonTrigger(PolygonTrigger *pTrigger);
  97. static void removePolygonTrigger(PolygonTrigger *pTrigger);
  98. void setNextPoly(PolygonTrigger *nextPoly) {m_nextPolygonTrigger = nextPoly;} ///< Link the next map object.
  99. void addPoint(const ICoord3D &point);
  100. void setPoint(const ICoord3D &point, Int ndx);
  101. void insertPoint(const ICoord3D &point, Int ndx);
  102. void deletePoint(Int ndx);
  103. void setTriggerName(AsciiString name) {m_triggerName = name;};
  104. void setLayerName(AsciiString name) {m_layerName = name;};
  105. AsciiString getLayerName(void) const {return m_layerName;}
  106. void setShouldRender(Bool toggle) {m_shouldRender = toggle;}
  107. Bool getShouldRender() {return m_shouldRender;}
  108. void setSelected(Bool toggle) {m_selected = toggle;}
  109. Bool getSelected() {return m_selected;}
  110. void getCenterPoint(Coord3D* pOutCoord) const;
  111. Real getRadius(void) const;
  112. public:
  113. 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.
  114. Int getNumPoints(void) const {return m_numPoints;}
  115. Int getID(void) const {return m_triggerID;}
  116. PolygonTrigger *getNext(void) {return m_nextPolygonTrigger;}
  117. const PolygonTrigger *getNext(void) const {return m_nextPolygonTrigger;}
  118. AsciiString getTriggerName(void) const {return m_triggerName;} ///< Gets the trigger name.
  119. Bool pointInTrigger(ICoord3D &point) const;
  120. Bool doExportWithScripts(void) const {return m_exportWithScripts;}
  121. void setDoExportWithScripts(Bool val) {m_exportWithScripts = val;}
  122. Bool isWaterArea(void) const {return m_isWaterArea;}
  123. void setWaterArea(Bool val) {m_isWaterArea = val;}
  124. Bool isRiver(void) const {return m_isRiver;}
  125. void setRiver(Bool val) {m_isRiver = val;}
  126. Int getRiverStart(void) const {return m_riverStart;}
  127. void setRiverStart(Int val) {m_riverStart = val;}
  128. const WaterHandle* getWaterHandle(void) const;
  129. Bool isValid(void) const;
  130. };
  131. #endif