MapObject.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // MapObject.h
  24. // Class to encapsulate height map.
  25. // Author: John Ahlquist, April 2001
  26. #pragma once
  27. #ifndef MapObject_H
  28. #define MapObject_H
  29. #include "Common/Dict.h"
  30. #include "Common/GameMemory.h"
  31. #include "GameClient/TerrainRoads.h"
  32. class WorldHeightMapInterfaceClass
  33. {
  34. public:
  35. virtual Int getBorderSize() = 0;
  36. virtual Real getSeismicZVelocity(Int xIndex, Int yIndex) const = 0;
  37. virtual void setSeismicZVelocity(Int xIndex, Int yIndex, Real value) = 0;
  38. virtual Real getBilinearSampleSeismicZVelocity( Int x, Int y) = 0;
  39. };
  40. /** MapObject class
  41. Not ref counted. Do not store pointers to this class. */
  42. class WorldHeightMap;
  43. class RenderObjClass;
  44. class ThingTemplate;
  45. class Shadow;
  46. enum WaypointID;
  47. #define MAP_XY_FACTOR (10.0f) //How wide and tall each height map square is in world space.
  48. #define MAP_HEIGHT_SCALE (MAP_XY_FACTOR/16.0f) //divide all map heights by 8.
  49. // m_flags bit values.
  50. enum {
  51. FLAG_DRAWS_IN_MIRROR = 0x00000001, ///< If set, draws in water mirror.
  52. FLAG_ROAD_POINT1 = 0x00000002, ///< If set, is the first point in a road segment.
  53. FLAG_ROAD_POINT2 = 0x00000004, ///< If set, is the second point in a road segment.
  54. FLAG_ROAD_FLAGS = (FLAG_ROAD_POINT1|FLAG_ROAD_POINT2), ///< If nonzero, object is a road piece.
  55. FLAG_ROAD_CORNER_ANGLED = 0x00000008, ///< If set, the road corner is angled rather than curved.
  56. FLAG_BRIDGE_POINT1 = 0x00000010, ///< If set, is the first point in a bridge.
  57. FLAG_BRIDGE_POINT2 = 0x00000020, ///< If set, is the second point in a bridge.
  58. FLAG_BRIDGE_FLAGS = (FLAG_BRIDGE_POINT1|FLAG_BRIDGE_POINT2), ///< If nonzero, object is a bridge piece.
  59. FLAG_ROAD_CORNER_TIGHT = 0x00000040,
  60. FLAG_ROAD_JOIN = 0x00000080, ///< If set, this road end does a generic alpha join.
  61. FLAG_DONT_RENDER = 0x00000100 ///< If set, do not render this object. Only WB pays attention to this. (Right now, anyways)
  62. };
  63. class MapObject : public MemoryPoolObject
  64. {
  65. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(MapObject, "MapObject")
  66. // friend doesn't play well with MPO -- srj
  67. // friend class WorldHeightMap;
  68. // friend class WorldHeightMapEdit;
  69. // friend class AddObjectUndoable;
  70. // friend class DeleteInfo;
  71. enum
  72. {
  73. MO_SELECTED = 0x01,
  74. MO_LIGHT = 0x02,
  75. MO_WAYPOINT = 0x04,
  76. MO_SCORCH = 0x08
  77. };
  78. // This data is currently written out into the map data file.
  79. Coord3D m_location; ///< Location of the center of the object.
  80. AsciiString m_objectName; ///< The object name.
  81. const ThingTemplate* m_thingTemplate; ///< thing template for map object
  82. Real m_angle; ///< positive x is 0 degrees, angle is counterclockwise in degrees.
  83. MapObject* m_nextMapObject; ///< linked list.
  84. Int m_flags; ///< Bit flags.
  85. Dict m_properties; ///< general property sheet.
  86. // This data is runtime data that is used by the worldbuider editor, but
  87. // not saved in the map file.
  88. Int m_color; ///< Display color.
  89. RenderObjClass* m_renderObj; ///< object that renders in the 3d scene.
  90. Shadow* m_shadowObj; ///< object that renders shadow in the 3d scene.
  91. RenderObjClass* m_bridgeTowers[ BRIDGE_MAX_TOWERS ]; ///< for bridge towers
  92. Int m_runtimeFlags;
  93. public:
  94. static MapObject *TheMapObjectListPtr;
  95. static Dict TheWorldDict;
  96. public:
  97. MapObject(Coord3D loc, AsciiString name, Real angle, Int flags, const Dict* props,
  98. const ThingTemplate *thingTemplate );
  99. //~MapObject(void); ///< Note that deleting the head of a list deletes all linked objects in the list.
  100. public:
  101. Dict *getProperties() { return &m_properties; } ///< return the object's property sheet.
  102. void setNextMap(MapObject *nextMap) {m_nextMapObject = nextMap;} ///< Link the next map object.
  103. const Coord3D *getLocation(void) const {return &m_location;} ///< Get the center point.
  104. Real getAngle(void) const {return m_angle;} ///< Get the angle.
  105. Int getColor(void) const {return m_color;} ///< Gets whatever ui color we set.
  106. void setColor(Int color) {m_color=color;} ///< Sets the ui color.
  107. AsciiString getName(void) const {return m_objectName;} ///< Gets the object name
  108. void setName(AsciiString name); ///< Sets the object name
  109. void setThingTemplate( const ThingTemplate* thing ); ///< set template
  110. const ThingTemplate *getThingTemplate( void ) const;
  111. MapObject *getNext(void) const {return m_nextMapObject;} ///< Next map object in the list. Not a copy, don't delete it.
  112. MapObject *duplicate(void); ///< Allocates a copy. Caller is responsible for delete-ing this when done with it.
  113. void setAngle(Real angle) {m_angle = normalizeAngle(angle);}
  114. void setLocation(Coord3D *pLoc) {m_location = *pLoc;}
  115. void setFlag(Int flag) {m_flags |= flag;}
  116. void clearFlag(Int flag) {m_flags &= (~flag);}
  117. Bool getFlag(Int flag) const {return (m_flags&flag)?true:false;}
  118. Int getFlags(void) const {return (m_flags);}
  119. Bool isSelected(void) const {return (m_runtimeFlags & MO_SELECTED) != 0;}
  120. void setSelected(Bool sel) { if (sel) m_runtimeFlags |= MO_SELECTED; else m_runtimeFlags &= ~MO_SELECTED; }
  121. Bool isLight(void) const {return (m_runtimeFlags & MO_LIGHT) != 0;}
  122. Bool isWaypoint(void) const {return (m_runtimeFlags & MO_WAYPOINT) != 0;}
  123. Bool isScorch(void) const {return (m_runtimeFlags & MO_SCORCH) != 0;}
  124. void setIsLight() {m_runtimeFlags |= MO_LIGHT;}
  125. void setIsWaypoint() { m_runtimeFlags |= MO_WAYPOINT; }
  126. void setIsScorch() { m_runtimeFlags |= MO_SCORCH; }
  127. void setRenderObj(RenderObjClass *pObj);
  128. RenderObjClass *getRenderObj(void) const {return m_renderObj;}
  129. void setShadowObj(Shadow *pObj) {m_shadowObj=pObj;}
  130. Shadow *getShadowObj(void) const {return m_shadowObj;}
  131. RenderObjClass* getBridgeRenderObject( BridgeTowerType type );
  132. void setBridgeRenderObject( BridgeTowerType type, RenderObjClass* renderObj );
  133. WaypointID getWaypointID();
  134. AsciiString getWaypointName();
  135. void setWaypointID(Int i);
  136. void setWaypointName(AsciiString n);
  137. // calling validate will call verifyValidTeam and verifyValidUniqueID.
  138. void validate(void);
  139. // verifyValidTeam will either place the map object on an approrpriate team, or leave the
  140. // current team (if it is valid)
  141. void verifyValidTeam(void);
  142. // verifyValidUniqueID will ensure that this unit isn't sharing a number with another unit.
  143. void verifyValidUniqueID(void);
  144. // The fast version doesn't attempt to verify uniqueness. It goes
  145. static void fastAssignAllUniqueIDs(void);
  146. static MapObject *getFirstMapObject(void) { return TheMapObjectListPtr; }
  147. static Dict* getWorldDict() { return &TheWorldDict; }
  148. static Int countMapObjectsWithOwner(const AsciiString& n);
  149. };
  150. #endif