Structs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. /**************************************
  17. Global structs here
  18. **************************************/
  19. #ifndef GLOBALSTRUCTS_H_INCLUDED
  20. #define GLOBALSTRUCTS_H_INCLUDED
  21. #include "defines.h"
  22. #include <vector>
  23. #include <memory>
  24. #include <cstdint>
  25. #include "MissionEditorPackLib.h"
  26. #include "Vec2.h"
  27. class MapTool;
  28. enum class TheaterChar : char
  29. {
  30. T = 'T',
  31. A = 'A',
  32. U = 'U',
  33. N = 'N',
  34. D = 'D',
  35. L = 'L',
  36. Generic = 'G',
  37. None = 0
  38. };
  39. inline TheaterChar toTheaterChar(char c)
  40. {
  41. switch (c)
  42. {
  43. case 'T':
  44. return TheaterChar::T;
  45. case 'A':
  46. return TheaterChar::A;
  47. case 'U':
  48. return TheaterChar::U;
  49. case 'N':
  50. return TheaterChar::N;
  51. case 'D':
  52. return TheaterChar::D;
  53. case 'L':
  54. return TheaterChar::L;
  55. case 'G':
  56. return TheaterChar::Generic;
  57. default:
  58. return TheaterChar::None;
  59. }
  60. }
  61. struct CLIPBOARD_MAPCOPY_ENTRY
  62. {
  63. BOOL bRedrawTerrain;
  64. BYTE overlay;
  65. BYTE overlaydata;
  66. WORD wGround;
  67. WORD bMapData;
  68. BYTE bSubTile;
  69. BYTE bHeight;
  70. BYTE bMapData2;
  71. // for RA2<->TS conversion:
  72. WORD wTileSet;
  73. BYTE bTile;
  74. };
  75. struct CLIPBOARD_DATA
  76. {
  77. DWORD dwType;
  78. DWORD dwVersion;
  79. DWORD dwReserved;
  80. BYTE bGame; // 0 TS, 1 RA2
  81. UINT iWidth;
  82. UINT iHeight;
  83. };
  84. struct VBORDER
  85. {
  86. short left;
  87. short right;
  88. };
  89. /*
  90. picdata
  91. Holds information for every picture:
  92. a directdraw surface, and additional data
  93. */
  94. struct PICDATA{
  95. PICDATA() = default;
  96. PICDATA(const PICDATA& c) = default;
  97. PICDATA& operator=(const PICDATA& c) = default;
  98. ~PICDATA() = default;
  99. #ifndef NOSURFACES_OBJECTS
  100. LPDIRECTDRAWSURFACE4 pic;
  101. #else
  102. void* pic = nullptr; // BYTE* to image, exception: if bType==PICDATA_TYPE_BMP then this is a LPDIRECTDRAWSURFACE!
  103. VBORDER* vborder = nullptr;
  104. int* pal = nullptr;
  105. std::shared_ptr<std::vector<BYTE>> lighting;
  106. std::shared_ptr<std::vector<BYTE>> rawPic;
  107. std::shared_ptr<std::vector<VBORDER>> _vBorder;
  108. #endif
  109. FSunPackLib::VoxelNormalClass normalClass = FSunPackLib::VoxelNormalClass::Unknown;
  110. short x = 0; // for SHPs (starting point of main graphic inside surface)
  111. short y = 0; // for SHPs (starting point of main graphic inside surface)
  112. WORD wWidth = 0; // for non-shps: size of whole surface, else size of main graphic
  113. WORD wHeight = 0; // for non-shps: size of whole surface, else size of main graphic
  114. WORD wMaxWidth = 0; // for SHPs (size of whole surface)
  115. WORD wMaxHeight = 0; // for SHPs (size of whole surface)
  116. BYTE bType = 0; // is loaded from voxel, shp, bmp, etc... (for drawing logic)
  117. TheaterChar bTerrain = TheaterChar::None;
  118. BOOL bTried = 0; // already tried to load this? - superseded by global array missingimages
  119. inline ProjectedVec drawOffset() const
  120. {
  121. return ProjectedVec(x, y);
  122. }
  123. #ifdef NOSURFACES_OBJECTS
  124. void createVBorder();
  125. #endif
  126. };
  127. /*
  128. TILEPIC / TILEDATA
  129. Holds information for every tile/subtile in TS.
  130. */
  131. struct SUBTILE{
  132. #ifndef NOSURFACES
  133. LPDIRECTDRAWSURFACE4 pic;
  134. #else
  135. #ifdef NOSURFACES_EXTRACT
  136. BOOL bNotExtracted; // pic is not extracted, even if NOSURFACES_EXTRACT is specifed. Probably there is inner transparency!
  137. #endif
  138. BYTE* pic; // optionally use direct blitting? This is either a palette index array or non-palette data (if NOSURFACES_EXTRACT is specified)
  139. VBORDER * vborder;
  140. #endif
  141. WORD wWidth; // width of tile
  142. WORD wHeight; // height "
  143. short sX; // x starting pos
  144. short sY; // y starting pos
  145. BYTE bZHeight; // z difference from tile ground surface (1unit == f_y/2pixel == 12pixel)
  146. BYTE bDirection; // for ramps for example
  147. BYTE bTerrainType; // water, etc...
  148. RGBTRIPLE rgbLeft;
  149. RGBTRIPLE rgbRight;
  150. BYTE bHackedTerrainType; // same like bTerrainType, except some shore pieces that were hacked in fsdata.ini
  151. std::shared_ptr<PICDATA> anim;
  152. inline ProjectedVec drawOffset() const
  153. {
  154. return ProjectedVec(sX, sY);
  155. }
  156. };
  157. struct TILEDATA{
  158. TILEDATA() = default;
  159. ~TILEDATA();
  160. WORD wTileSet = 0;
  161. SUBTILE* tiles = nullptr; // the different tiles
  162. WORD wTileCount = 0; // number of tiles
  163. WORD cx = 0;
  164. WORD cy = 0;
  165. BOOL bAllowTiberium = 0;
  166. BOOL bAllowToPlace = TRUE;
  167. BOOL bMorphable = FALSE; // morphable using lower/raise ground function?
  168. BOOL bHide = FALSE; // for user interface only
  169. BOOL bMarbleMadness = FALSE;
  170. WORD wMarbleGround = 0xFFFF;
  171. public:
  172. RECT rect = { 0 };
  173. TILEDATA* lpReplacements = nullptr;
  174. BYTE bReplacementCount = 0;
  175. };
  176. /*
  177. actiondata
  178. CViewObjects sets this data struct,
  179. and CIsoView uses it to interact with the user´s CViewObjects and terrain editing choice
  180. */
  181. struct ACTIONDATA{
  182. DWORD mode;
  183. DWORD type;
  184. DWORD data;
  185. DWORD data2;
  186. DWORD data3;
  187. int z_data;
  188. CString data_s;
  189. std::unique_ptr<MapTool> tool;
  190. ~ACTIONDATA();
  191. void reset();
  192. };
  193. struct SIDEINFO{
  194. CString name;
  195. int orig_n;
  196. };
  197. struct HOUSEINFO{
  198. CString name;
  199. SIDEINFO* side; // side is used for rules.ini owner= settings
  200. RGBTRIPLE color;
  201. BOOL bPlayable;
  202. };
  203. /**********************
  204. Unittype infos
  205. **********************/
  206. /*
  207. building infos
  208. */
  209. struct BUILDING_INFO
  210. {
  211. PICDATA pic[8];
  212. int pic_count;
  213. BYTE w;
  214. BYTE h;
  215. BOOL bTemp;
  216. BOOL bSnow;
  217. BOOL bUrban;
  218. };
  219. struct TREE_INFO
  220. {
  221. PICDATA pic;
  222. BYTE w;
  223. BYTE h;
  224. };
  225. #ifdef SMUDGE_SUPP
  226. struct SMUDGE_INFO
  227. {
  228. PICDATA pic;
  229. //BYTE w;
  230. //BYTE h;
  231. };
  232. #endif
  233. /*
  234. ** Condition enumeration
  235. */
  236. enum ConditionEnum {
  237. COND_LT = 0, // less than
  238. COND_LE, // less than or equal to
  239. COND_EQ, // equal to
  240. COND_GE, // greater than or equal to
  241. COND_GT, // greater than
  242. COND_NE, // not equal to
  243. COND_COUNT
  244. };
  245. struct AITrigInfo
  246. {
  247. union{
  248. struct{
  249. int Number;
  250. ConditionEnum Condition;
  251. };
  252. char Padding[32];
  253. };
  254. };
  255. /*
  256. Struct for string items
  257. */
  258. struct XCString
  259. {
  260. XCString()
  261. {
  262. //wString=new(WCHAR[2]);
  263. //memset(wString, 0, 4);
  264. wString=NULL;
  265. bUsedDefault=FALSE;
  266. len=0;
  267. }
  268. ~XCString()
  269. {
  270. if(wString) delete[] wString;
  271. len=0;
  272. wString=NULL;
  273. }
  274. void SetString(const CHAR* cString)
  275. {
  276. len=strlen(cString);
  277. this->cString=cString;
  278. if(wString) delete[] wString;
  279. bUsedDefault=FALSE;
  280. wString=new(WCHAR[len+1]);
  281. memset(wString, 0, (len+1)*2);
  282. //MultiByteToWideChar(CP_ACP, WC_COMPOSITECHECK, cString, len, wString, len+1);
  283. mbstowcs(wString, cString, len);
  284. }
  285. void SetString(const WCHAR* wString, int len)
  286. {
  287. this->len=len;
  288. if(this->wString) delete[] this->wString;
  289. bUsedDefault=FALSE;
  290. this->wString=new(WCHAR[len+1]);
  291. memset(this->wString, 0, (len+1)*2);
  292. memcpy(this->wString, wString, len*2);
  293. auto bufferSize = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, this->wString, len + 1, nullptr, 0, NULL, &bUsedDefault);
  294. if (bufferSize == 0)
  295. {
  296. cString = "";
  297. return; // failed
  298. }
  299. std::vector<BYTE> bByte(bufferSize + 4, 0);
  300. if (WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, this->wString, len + 1, (LPSTR)bByte.data(), bufferSize, NULL, &bUsedDefault) == 0)
  301. {
  302. cString = "";
  303. return; // failed
  304. }
  305. cString = bByte.data();
  306. }
  307. CString cString;
  308. WCHAR* wString;
  309. BOOL bUsedDefault;
  310. int len;
  311. };
  312. /**********************
  313. Map stuff structs
  314. ***********************/
  315. /*
  316. AITRIGGERTYPE{};
  317. Data for ai trigger types
  318. */
  319. struct AITRIGGERTYPE{
  320. CString ID; // ai trigger id
  321. CString name; // param 1
  322. CString teamtype1; // param 2
  323. CString owner; // param 3
  324. CString techlevel; // flag 1/ param 4
  325. CString type; // param 5
  326. CString unittype; // param 6
  327. CString data; // param 7
  328. CString float1; // param 8
  329. CString float2; // param 9
  330. CString float3; // param 10
  331. CString skirmish; // param 11
  332. CString flag4; // param 12
  333. CString multihouse; // param 13
  334. CString basedefense; // param 14
  335. CString teamtype2; // param 15
  336. CString easy; // param 16
  337. CString medium; // param 17
  338. CString hard; // param 18
  339. };
  340. /*
  341. STDOBJECTDATA
  342. Data for Trees, Units, Infantry, Aircraft & Structures
  343. This should be used for painting procedure...
  344. except if you want to draw the upgrades on buildings
  345. */
  346. struct STDOBJECTDATA
  347. {
  348. CString house; // 1
  349. CString type; // 2
  350. CString strength; // 3
  351. CString y; // 4
  352. CString x; // 5
  353. };
  354. /*
  355. STRUCTURE
  356. Data for a structure
  357. */
  358. struct STRUCTURE{
  359. CString house; // 1
  360. CString type; // 2
  361. CString strength; // 3
  362. CString y; // 4
  363. CString x; // 5
  364. CString direction; // 6
  365. CString tag; // 7
  366. CString flag1; // 8
  367. CString flag2; // 9
  368. CString energy; // 10
  369. CString upgradecount; // 11
  370. CString spotlight; // 12
  371. CString upgrade1; // 13
  372. CString upgrade2; // 14
  373. CString upgrade3; // 15
  374. CString flag3; // 16
  375. CString flag4; // 17
  376. unsigned deleted:1;
  377. };
  378. // structure data especially for painting
  379. struct STRUCTUREPAINT{
  380. COLORREF col;
  381. CString type;
  382. short x;
  383. short y;
  384. short direction;
  385. BYTE strength;
  386. BYTE upradecount;
  387. CString upgrade1;
  388. CString upgrade2;
  389. CString upgrade3;
  390. };
  391. /*
  392. struct INFANTRY{};
  393. Data for an infantry unit
  394. */
  395. struct INFANTRY{
  396. CString house; // 1
  397. CString type; // 2
  398. CString strength; // 3
  399. CString y; // 4
  400. CString x; // 5
  401. CString pos; // 6
  402. CString action; // 7
  403. CString direction; // 8
  404. CString tag; // 9
  405. CString flag1; // 10
  406. CString flag2; // 11
  407. CString flag3; // 12
  408. CString flag4; // 13
  409. CString flag5; // 14
  410. unsigned deleted:1;
  411. };
  412. struct UNIT{
  413. CString house; // 1
  414. CString type; // 2
  415. CString strength; // 3
  416. CString y; // 4
  417. CString x; // 5
  418. CString direction; // 6
  419. CString action; // 7
  420. CString tag; // 8
  421. CString flag1; // 9
  422. CString flag2; // 10
  423. CString flag3; // 11
  424. CString flag4; // 12
  425. CString flag5; // 13
  426. CString flag6; // 14
  427. unsigned deleted:1;
  428. };
  429. struct AIRCRAFT{
  430. CString house; // 1
  431. CString type; // 2
  432. CString strength; // 3
  433. CString y; // 4
  434. CString x; // 5
  435. CString direction; // 6
  436. CString action; // 7
  437. CString tag; // 8
  438. CString flag1; // 9
  439. CString flag2; // 10
  440. CString flag3; // 11
  441. CString flag4; // 12
  442. unsigned deleted:1;
  443. };
  444. struct TERRAIN{
  445. CString type;
  446. int x;
  447. int y;
  448. unsigned deleted:1;
  449. };
  450. // MW 08/07/01: Smudge
  451. #ifdef SMUDGE_SUPP
  452. struct SMUDGE{
  453. CString type;
  454. int x;
  455. int y;
  456. unsigned deleted:1;
  457. };
  458. #endif
  459. /*
  460. NODE
  461. Data for a node
  462. */
  463. struct NODE{
  464. CString house;
  465. CString type;
  466. CString x;
  467. CString y;
  468. };
  469. struct RA2STRFILEHEAD
  470. {
  471. DWORD dwFlag1;
  472. DWORD dwCount1;
  473. DWORD dwCount2;
  474. DWORD dwUnused;
  475. DWORD dwFlag2;
  476. };
  477. #define RA2STRFILEHEADSIZE 20
  478. struct RA2STRINGENTRY
  479. {
  480. RA2STRINGENTRY(){
  481. //memset(this, 0, sizeof(RA2STRINGENTRY));
  482. id=NULL;
  483. value=NULL;
  484. value_asc=0;
  485. value_asc_size=0;
  486. dwFlag = 0;
  487. id_size = 0;
  488. value_size = 0;
  489. }
  490. ~RA2STRINGENTRY(){
  491. if(value) delete[] value;
  492. if(id) delete[] id;
  493. if(value_asc) delete[] value_asc;
  494. value=NULL;
  495. value_size=0;
  496. id=NULL;
  497. id_size=0;
  498. value_asc=0;
  499. value_asc_size=0;
  500. }
  501. RA2STRINGENTRY(RA2STRINGENTRY& ref)
  502. {
  503. value=NULL;
  504. value_size=0;
  505. id=NULL;
  506. id_size = 0;
  507. value_asc=0;
  508. value_asc_size=0;
  509. if(ref.value_size && ref.value)
  510. {
  511. value_size=ref.value_size;
  512. value=new(WCHAR[value_size+1]);
  513. memcpy(value, ref.value, value_size*sizeof(WCHAR));
  514. value[value_size]=0;
  515. }
  516. if(ref.id_size && ref.id)
  517. {
  518. id_size=ref.id_size;
  519. id=new(CHAR[id_size+1]);
  520. memcpy(id, ref.id, id_size*sizeof(CHAR));
  521. id[id_size]=0;
  522. }
  523. if(ref.value_asc_size && ref.value_asc)
  524. {
  525. value_asc_size=ref.value_asc_size;
  526. value_asc=new(CHAR[value_asc_size+1]);
  527. memcpy(value_asc, ref.value_asc, value_asc_size*sizeof(CHAR));
  528. value_asc[value_asc_size]=0;
  529. }
  530. dwFlag=ref.dwFlag;
  531. }
  532. RA2STRINGENTRY& operator=(RA2STRINGENTRY& ref)
  533. {
  534. if(value) delete[] value;
  535. if(id) delete[] id;
  536. value=NULL;
  537. value_size=0;
  538. id=NULL;
  539. value_asc=0;
  540. value_asc_size=0;
  541. if(ref.value_size)
  542. {
  543. value_size=ref.value_size;
  544. value=new(WCHAR[value_size+1]);
  545. memcpy(value, ref.value, value_size*sizeof(WCHAR));
  546. value[value_size]=0;
  547. }
  548. if(ref.id_size)
  549. {
  550. id_size=ref.id_size;
  551. id=new(CHAR[id_size+1]);
  552. memcpy(id, ref.id, id_size*sizeof(CHAR));
  553. id[id_size]=0;
  554. }
  555. if(ref.value_asc_size)
  556. {
  557. value_asc_size=ref.value_asc_size;
  558. value_asc=new(CHAR[value_asc_size+1]);
  559. memcpy(value_asc, ref.value_asc, value_asc_size*sizeof(CHAR));
  560. value_asc[value_asc_size]=0;
  561. }
  562. dwFlag=ref.dwFlag;
  563. return *this;
  564. }
  565. DWORD dwFlag;
  566. CHAR* id;
  567. DWORD id_size;
  568. DWORD value_size;
  569. WCHAR* value;
  570. CHAR* value_asc;
  571. DWORD value_asc_size;
  572. };
  573. #endif