EditorObjectMgr.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #ifndef EDITOROBJECTMGR_H
  2. #define EDITOROBJECTMGR_H
  3. /*************************************************************************************************\
  4. EditorObjectMgr.h : Interface for the EditorObjectMgr component. This thing holds lists
  5. of all the objects on the map.
  6. //---------------------------------------------------------------------------//
  7. // Copyright (C) Microsoft Corporation. All rights reserved. //
  8. //===========================================================================//
  9. \*************************************************************************************************/
  10. #ifndef ELIST_H
  11. #include "Elist.h"
  12. #endif
  13. #ifndef EDITOROBJECTS_H
  14. #include "EditorObjects.h"
  15. #endif
  16. #ifndef FOREST_H
  17. #include "Forest.h"
  18. #endif
  19. #include "mclib.h"
  20. class ObjectAppearance;
  21. class AppearanceType;
  22. class EditorObject;
  23. class Mech;
  24. class BuildingLink;
  25. class EditorObjectMgr
  26. {
  27. private:
  28. struct Building;
  29. public:
  30. static EditorObjectMgr* instance(){ return s_instance; }
  31. enum BuildingType
  32. {
  33. UNSPECIAL = -1,
  34. NORMAL_BUILDING = 0,
  35. DROP_ZONE = 1,
  36. TURRET_CONTROL,
  37. GATE_CONTROL,
  38. POWER_STATION,
  39. TURRET_GENERATOR,
  40. SENSOR_CONTROL,
  41. EDITOR_GATE,
  42. EDITOR_TURRET,
  43. SENSOR_TOWER,
  44. EDITOR_BRIDGE,
  45. BRIDGE_CONTROL,
  46. SPOTLIGHT,
  47. SPOTLIGHT_CONTROL,
  48. DROPZONE,
  49. NAV_MARKER,
  50. WALL,
  51. LOOKOUT,
  52. RESOURCE_BUILDING,
  53. HELICOPTER
  54. };
  55. class EDITOR_OBJECT_LIST : public EList< EditorObject*, EditorObject*>
  56. {
  57. public:
  58. void AddUnique(EditorObject* item)
  59. {
  60. if ((0 < Count()) && (INVALID_ITERATOR != Find(item)))
  61. {
  62. return;
  63. }
  64. Append(item);
  65. }
  66. void RemoveIfThere(EditorObject* item)
  67. {
  68. if (0 < Count())
  69. {
  70. EIterator it = Find(item);
  71. if (INVALID_ITERATOR != it)
  72. {
  73. Delete(it);
  74. }
  75. }
  76. }
  77. };
  78. EditorObjectMgr(); // should only be one of these
  79. ~EditorObjectMgr();
  80. void render();
  81. void update();
  82. void renderShadows();
  83. void init( const char* bldgListFileName, const char* objectFileName );
  84. EditorObject* addBuilding( const Stuff::Vector3D& position,
  85. unsigned long group,
  86. unsigned long indexWithinGroup,
  87. int alignment,
  88. float rotation = 0.0,
  89. float height = 1.0,
  90. bool bSnapToCell = true ); // returns NULL if failure
  91. bool addBuilding( EditorObject* pObjectThatWeWillCopy );
  92. EditorObject* addDropZone( const Stuff::Vector3D& position,
  93. int alignment, bool bVTol ); // returns NULL if failure
  94. bool deleteBuilding( const EditorObject* pInfo ); // should only be one building in a spot
  95. bool deleteObject( const EditorObject* pInfo){ return deleteBuilding( pInfo ); } // only object FOR NOW
  96. /* This function (getObjectAtPosition(...)) is for use in determining objects selected by the
  97. mouse, not really for general use. It appears to return an object that a) is visible on screen,
  98. and b) has the property that the screen projection of the given position is contained in
  99. (intersect with) the screen projection of the object. */
  100. EditorObject* getObjectAtPosition( const Stuff::Vector3D& position );
  101. /*This function (getObjectAtCell(...)) returns an object that occupies the given cell (i.e. it
  102. doesn't have to be centered at the given cell).*/
  103. EditorObject* getObjectAtCell( long cellJ, long cellI );
  104. /*This function (getObjectAtLocation(...)) returns an object whose x and y positions are the
  105. same as (or very close to) those given. Screen visibility, object geometry, etc., are not
  106. considerred.*/
  107. EditorObject* getObjectAtLocation( float x, float y );
  108. EditorObject* getBuilding( const EditorObject &building );
  109. bool canAddBuilding( const Stuff::Vector3D& position,
  110. float rotation,
  111. unsigned long group,
  112. unsigned long indexWithinGroup );
  113. bool canAddDropZone( const Stuff::Vector3D& position, int alignment, bool bVTol );
  114. int getBuildingGroupCount() const; // mechs count too!
  115. int getNumberBuildingsInGroup( int Group ) const;
  116. void getBuildingGroupNames( const char** names, int& numberOfNames ) const;
  117. void getNamesOfObjectsInGroup( const char* groupName, const char** names, int& numberOfNames ) const;
  118. void getBuildingNamesInGroup( int Group, const char** names, int& numberOfNames ) const;
  119. int getNumberOfVariants( int group, int indexInGroup ) const;
  120. void getVariantNames( int group, int indexInGroup, const char** names, int& numberOfNames ) const;
  121. const char* getGroupName( int group ) const;
  122. const char* getObjectName( int ID ) const;
  123. int getUnitGroupCount() const;
  124. void getUnitGroupNames( const char** names, int* IDs, int& numberOfNames ) const;
  125. bool save( PacketFile& file, int whichPacket );
  126. bool load( PacketFile& file, int whichPacket );
  127. bool saveMechs( FitIniFile& file );
  128. bool loadMechs( FitIniFile& file ); // need to implement this
  129. bool saveDropZones( FitIniFile& file );
  130. bool loadDropZones( FitIniFile& file );
  131. bool saveForests( FitIniFile& file );
  132. bool loadForests( FitIniFile& file );
  133. int getFitID( int id ) const;
  134. bool moveBuilding( EditorObject* pInfo, long cellI, long cellJ );
  135. bool getBlocksLineOfFire( int id ) const;
  136. bool getIsHoverCraft( int id ) const;
  137. inline int getID( long group, long index ) { return (getType(group,index) << 24) | (group << 16) | (index << 8); }
  138. void clear(); // delete all objects
  139. __int64 getImpassability( int id );
  140. inline static unsigned long getGroup( long id );
  141. inline static unsigned long getIndexInGroup( long id );
  142. inline int getAppearanceType( int ID );
  143. bool getBuildingFromID( int fitID, unsigned long& group, unsigned long& index, bool canBeMech );
  144. void unselectAll();
  145. void select( const Stuff::Vector4D& pos1, const Stuff::Vector4D& pos2 );
  146. void select( EditorObject &object, bool bSelect = true );
  147. void objectSelectionChanged(void) /* use this to notify the EditorObjectMgr when selection states of objects are changed externally */
  148. { selectedObjectsNeedsToBeSynched = true; }
  149. bool hasSelection();
  150. int getSelectionCount(); // returns the number of selected items
  151. EDITOR_OBJECT_LIST getSelectedObjectList();
  152. void deleteSelectedObjects();
  153. void adjustObjectsToNewTerrainHeights();
  154. ObjectAppearance* getAppearance( unsigned long group,
  155. unsigned long indexWithinGroup );
  156. ObjectAppearance* getAppearance( Building* pBuilding );
  157. // LINKS!
  158. BuildingLink* getLinkWithParent( const EditorObject* pObj );
  159. BuildingLink* getLinkWithChild( const EditorObject* pObj );
  160. BuildingLink* getLinkWithBuilding( const EditorObject* pObj ); // parent or child
  161. void addLink( BuildingLink* );
  162. void deleteLink( BuildingLink* );
  163. inline BuildingType getSpecialType( int ID );
  164. inline bool isCapturable( int ID );
  165. inline float getScale( int ID );
  166. inline bool isAlignable( int ID );
  167. inline int getObjectTypeNum( int ID );
  168. inline const char* getFileName( int ID ) const;
  169. inline const char* getTGAFileName( int ID ) const;
  170. inline DWORD getTacMapColor( int ID ) const;
  171. typedef EList< EditorObject*, EditorObject*> BUILDING_LIST; // buildings on the map
  172. typedef EList< Unit*, Unit* > UNIT_LIST;
  173. void getSelectedUnits( UNIT_LIST& );
  174. UNIT_LIST getUnits() { return units; }
  175. BUILDING_LIST getBuildings() { return buildings; }
  176. unsigned long getNextAvailableSquadNum() { return nextAvailableSquadNum; }
  177. void registerSquadNum(unsigned long squadNum);
  178. void unregisterSquadNum(unsigned long squadNum) {}
  179. void resetAvailableSquadNums() { nextAvailableSquadNum = 1; }
  180. int getNextAvailableForestID();
  181. long createForest( const Forest& settings );
  182. void editForest( long& ID, const Forest& newSettings );
  183. void removeForest( const Forest& settings );
  184. const Forest* getForest( long ID );
  185. long getForests( Forest** pForests, long& count );
  186. void selectForest( long ID );
  187. private:
  188. struct Building
  189. {
  190. char name[64];
  191. char** varNames;
  192. int nameID;
  193. char fileName[64];
  194. AppearanceType* appearanceType;
  195. int type;
  196. unsigned long fitID;
  197. __int64 impassability;
  198. bool blocksLineOfFire;
  199. BuildingType specialType;
  200. bool capturable;
  201. bool alignable;
  202. DWORD writeOnTacMap;
  203. char tgaName[64];
  204. long objectTypeNum;
  205. char forestId;
  206. float scale;
  207. bool isHoverCraft;
  208. ~Building();
  209. };
  210. struct Group
  211. {
  212. char name[64];
  213. EList< Building, Building& > buildings;
  214. };
  215. typedef EList< EditorObject*, EditorObject*> BUILDING_LIST; // buildings on the map
  216. typedef EList< Unit*, Unit* > UNIT_LIST;
  217. typedef EList< Group, Group& > GROUP_LIST;
  218. typedef EList< BuildingLink*, BuildingLink* > LINK_LIST;
  219. typedef EList< DropZone*, DropZone* > DROP_LIST;
  220. typedef EList< Forest*, Forest* > FOREST_LIST;
  221. GROUP_LIST groups; // list of possible buildings
  222. Group dropZoneGroup;
  223. BUILDING_LIST buildings;
  224. UNIT_LIST units;
  225. LINK_LIST links;
  226. DROP_LIST dropZones;
  227. FOREST_LIST forests;
  228. EDITOR_OBJECT_LIST selectedObjects;
  229. bool selectedObjectsNeedsToBeSynched;
  230. void syncSelectedObjectPointerList(); // makes sure that the "selectedObjects" list corresponds to the objects marked as selected
  231. // HELPERS
  232. int ExtractNextString( unsigned char*& pFileLine, char* pBuffer, int bufferLength );
  233. int ExtractNextInt( unsigned char*& pFileLine );
  234. float ExtractNextFloat( unsigned char*& pFileLine );
  235. int getType( unsigned long group, unsigned long indexWithinGroup );
  236. void getRandomTreeFromGroup( int treeGroup, int& group, int& index );
  237. void doForest( const Forest& forest );
  238. unsigned long nextAvailableSquadNum;
  239. static EditorObjectMgr* s_instance; // the one and only instance of this object
  240. };
  241. inline unsigned long EditorObjectMgr::getGroup( long id )
  242. {
  243. return ((id >> 16) & 0x00ff);
  244. }
  245. inline unsigned long EditorObjectMgr::getIndexInGroup( long id )
  246. {
  247. return ((id >> 8) & 0x00ff);
  248. }
  249. inline EditorObjectMgr::BuildingType EditorObjectMgr::getSpecialType( int ID )
  250. {
  251. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].specialType;
  252. }
  253. inline bool EditorObjectMgr::isAlignable( int ID )
  254. {
  255. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].alignable;
  256. }
  257. inline int EditorObjectMgr::getAppearanceType( int ID )
  258. {
  259. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].appearanceType->getAppearanceClass();
  260. }
  261. inline int EditorObjectMgr::getObjectTypeNum( int ID )
  262. {
  263. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].objectTypeNum;
  264. }
  265. inline const char* EditorObjectMgr::getFileName( int ID ) const
  266. {
  267. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].fileName;
  268. }
  269. inline const char* EditorObjectMgr::getTGAFileName( int ID ) const
  270. {
  271. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].tgaName;
  272. }
  273. inline DWORD EditorObjectMgr::getTacMapColor( int ID ) const
  274. {
  275. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].writeOnTacMap;
  276. }
  277. inline float EditorObjectMgr::getScale( int ID )
  278. {
  279. return groups[getGroup( ID )].buildings[getIndexInGroup( ID )].scale;
  280. }
  281. //*************************************************************************************************
  282. #endif // end of file ( EditorObjectMgr.h )