MapObject.h 7.2 KB

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