variables.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. VARIABLES.CPP
  18. INCLUDES ALL FINAL SUN CONSTANTS AND
  19. VARIABLES USED
  20. *************************************/
  21. #include "stdafx.h"
  22. #include "mapdata.h"
  23. #include "structs.h"
  24. #include "FinalSun.h"
  25. #include <Shlobj.h>
  26. #include "MapTool.h"
  27. #include "inlines.h"
  28. #include <string>
  29. #include <codecvt>
  30. /**INI Files**/
  31. CIniFile rules;
  32. CIniFile art;
  33. CIniFile ai;
  34. CIniFile sound;
  35. CIniFile tutorial;
  36. CIniFile eva;
  37. CIniFile theme;
  38. CIniFile g_data;
  39. CIniFile language;
  40. CIniFile tiles_t; // temperat.ini shouldn´t be used except in CMapData::UpdateIniFile() and CLoading
  41. CIniFile tiles_s; // snow.ini shouldn´t be used except in CMapData::UpdateIniFile() and CLoading
  42. CIniFile tiles_u; // urban.ini ...
  43. CIniFile tiles_un; // new urbannmd.ini
  44. CIniFile tiles_l; // lunarmd.ini
  45. CIniFile tiles_d; // desertmd.ini
  46. CIniFile* tiles=NULL; // this should be used by every class/function except CMapData::UpdateIniFile();
  47. /*************/
  48. /* the mapdata! */
  49. CMapData* Map;
  50. /* actiondata used for iso view */
  51. ACTIONDATA AD;
  52. /* A map with all the pictures in the pics directory, and some special pics */
  53. map<CString, PICDATA> pics;
  54. TILEDATA* t_tiledata=NULL;
  55. DWORD t_tiledata_count=0;
  56. TILEDATA* s_tiledata=NULL;
  57. DWORD s_tiledata_count=0;
  58. TILEDATA* u_tiledata=NULL;
  59. DWORD u_tiledata_count=0;
  60. // MW new tilesets
  61. TILEDATA* un_tiledata=NULL;
  62. DWORD un_tiledata_count=0;
  63. TILEDATA* l_tiledata=NULL;
  64. DWORD l_tiledata_count=0;
  65. TILEDATA* d_tiledata=NULL;
  66. DWORD d_tiledata_count=0;
  67. TILEDATA** tiledata=NULL;
  68. DWORD* tiledata_count=NULL;
  69. map<int, int> tilesets_start;
  70. // Palettes:
  71. RGBTRIPLE palIso[256];
  72. RGBTRIPLE palUnit[256];
  73. RGBTRIPLE palStd[256];
  74. RGBTRIPLE palTheater[256];
  75. RGBTRIPLE palLib[256];
  76. int iPalIso[256];
  77. int iPalUnit[256];
  78. int iPalStd[256];
  79. int iPalTheater[256];
  80. int iPalLib[256];
  81. int bpp;
  82. map<CString, int> color_conv;
  83. map<COLORREF, int> colorref_conv;
  84. map<int, HOUSEINFO> houses;
  85. map<int, SIDEINFO> sides;
  86. map<CString, BOOL> missingimages;
  87. vector<CString> rndterrainsrc;
  88. /* Overlay tile data */
  89. #ifndef RA2_MODE
  90. int overlay_number[]={0x0,0x2, 0x1a, 0x7e, 0xa7, 0x27};
  91. CString overlay_name[]={"Sandbags","GDI Wall", "Nod Wall", "Veins", "Veinhole monster", "Tracks"};
  92. BOOL overlay_visible[]={TRUE,TRUE,TRUE,FALSE,FALSE, TRUE};
  93. BOOL overlay_trail[]={TRUE,TRUE,TRUE,FALSE,FALSE, TRUE};
  94. BOOL overlay_trdebug[]={FALSE,FALSE,FALSE,FALSE,FALSE, FALSE};
  95. BOOL yr_only[]={FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
  96. int overlay_count=6;
  97. const std::string editor_name = "FinalSun";
  98. #else
  99. int overlay_number[]={0x0,0x2, 0x1a, 0xcb, 0xf1, 0xcc,0xf3,0xf0, 0x27};
  100. BOOL overlay_trdebug[]={FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE};
  101. CString overlay_name[]={"Sandbags","Allied Wall", "Soviet Wall", "Black fence", "Prison camp fence", "White fence", "Yuri Wall", "Kremlin Wall", "Tracks"};
  102. BOOL overlay_visible[]={TRUE,TRUE,TRUE,TRUE,TRUE,TRUE, TRUE, TRUE, TRUE};
  103. BOOL overlay_trail[]={TRUE,TRUE,TRUE,TRUE,TRUE,TRUE, TRUE, TRUE, TRUE};
  104. BOOL yr_only[]={FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE};
  105. int overlay_count=9;
  106. const std::string editor_name = "FinalAlert 2";
  107. #endif
  108. static const std::string GetAppDataPath()
  109. {
  110. _setmbcp(CP_UTF8);
  111. setlocale(LC_ALL, "C");
  112. if (!setlocale(LC_CTYPE, ".65001"))
  113. setlocale(LC_CTYPE, "");
  114. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  115. CComPtr<IKnownFolderManager> manager;
  116. CComPtr<IKnownFolder> local_app_data;
  117. CComHeapPtr<WCHAR> local_app_data_folder;
  118. HRESULT hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&manager));
  119. if (SUCCEEDED(hr)) {
  120. //std::shared_ptr<LPWSTR> x()
  121. if (SUCCEEDED(manager->GetFolder(FOLDERID_LocalAppData, &local_app_data))) {
  122. LPWSTR b;
  123. local_app_data->GetPath(KF_FLAG_CREATE, &b);
  124. local_app_data_folder.Attach(b);
  125. int a = 0;
  126. std::string AppFolder = utf16ToUtf8(std::wstring(local_app_data_folder));
  127. //return CString(CW2A(CStringW(local_app_data_folder), CP_ACP)) + "\\" + editor_name + "\\";
  128. return AppFolder + "\\" + editor_name + "\\";
  129. }
  130. }
  131. // fallback: use app directory
  132. wchar_t app_path[MAX_PATH] = { 0 };
  133. GetModuleFileNameW(NULL, app_path, MAX_PATH);
  134. std::wstring appPath = app_path;
  135. std::size_t end = appPath.rfind(L'\\');
  136. if (end != std::wstring::npos)
  137. appPath.resize(end + 1);
  138. return utf16ToUtf8(appPath);
  139. }
  140. /* Application specific global variables */
  141. char AppPath[MAX_PATH + 1] = { 0 };
  142. const std::string u8AppDataPath = GetAppDataPath();
  143. const std::wstring u16AppDataPath = utf8ToUtf16(u8AppDataPath);
  144. char TSPath[MAX_PATH + 1] = { 0 };
  145. char currentMapFile[MAX_PATH + 1] = { 0 };
  146. BOOL bOptionsStartup=FALSE;
  147. bool bAllowAccessBehindCliffs=false;
  148. // infos for buildings and trees (should be extended to infantry, units, and aircraft)
  149. // they are initialized in CIsoView, should be changed to CMapData
  150. BUILDING_INFO buildinginfo[0x0F00];
  151. TREE_INFO treeinfo[0x0F00];
  152. #ifdef SMUDGE_SUPP
  153. SMUDGE_INFO smudgeinfo[0x0F00];
  154. #endif
  155. /* error output */
  156. ofstream errstream;
  157. /* the finalsun app object */
  158. CFinalSunApp theApp;
  159. CString currentOwner="Neutral";
  160. map<CString, XCString> CCStrings;
  161. map<CString, XCString> AllStrings;
  162. // tilesets
  163. int cliffset;
  164. int cliffset_start;
  165. int rampset;
  166. int rampsmoothset;
  167. int slopesetpiecesset;
  168. int tunnelset;
  169. int tracktunnelset;
  170. int dirttunnelset;
  171. int dirttracktunnelset;
  172. int waterset;
  173. int shoreset;
  174. int ramp2set_start;
  175. int pave2set_start;
  176. int rampset_start;
  177. int ramp2set;
  178. int pave2set;
  179. int cliff2set;
  180. int cliff2set_start;
  181. int cliffwater2set;
  182. // debug information
  183. int last_succeeded_operation=0;
  184. #ifdef RA2_MODE
  185. int editor_mode=1;
  186. #ifdef YR_MODE
  187. int yuri_mode=1;
  188. #else
  189. int yuri_mode=0;
  190. #endif
  191. #else
  192. int editor_mode=0;
  193. int yuri_mode=0;
  194. #endif