WorldmapData.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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. #include "modules/worldmap/WorldmapData.h"
  16. #include <OgreLogManager.h>
  17. #include <OgreResourceGroupManager.h>
  18. #include "formats/worldmap/WorldmapFile.h"
  19. namespace VGears {
  20. using namespace Ogre;
  21. /**
  22. * World map hardcoded textures
  23. */
  24. const HarcodedTextureInfo WORLD_MAP_TEXTURES[] ={
  25. {0, "pond", 32, 32, 0, 352},
  26. {1, "riv_m2", 32, 32, 128, 64},
  27. {2, "was_gs", 64, 64, 64, 192},
  28. {3, "wpcltr", 32, 128, 0, 256},
  29. {4, "wpcltr2", 32, 32, 160, 64},
  30. {5, "bzdun", 64, 64, 192, 192},
  31. {6, "bone", 32, 32, 224, 384},
  32. {7, "bone2", 32, 32, 224, 416},
  33. {8, "bornwd", 64, 64, 160, 320},
  34. {9, "bridge", 32, 64, 192, 0},
  35. {10, "bridge2", 32, 32, 224, 0},
  36. {11, "cave", 32, 32, 224, 448},
  37. {12, "cave2", 32, 32, 224, 320},
  38. {13, "cave_s", 32, 32, 160, 224},
  39. {14, "cdl_cl2", 64, 32, 96, 96},
  40. {15, "cf01", 64, 32, 192, 288},
  41. {16, "clf_bgs", 64, 32, 192, 384},
  42. {17, "clf_ggl", 64, 64, 128, 256},
  43. {18, "clf_ggs", 64, 32, 192, 352},
  44. {19, "clf_l", 64, 64, 0, 0},
  45. {20, "clf_ld", 64, 64, 64, 0},
  46. {21, "clf_lf", 64, 64, 128, 0},
  47. {22, "clf_lg", 32, 64, 0, 96},
  48. {23, "clf_lr", 32, 64, 128, 0},
  49. {24, "clf_lsg", 32, 64, 64, 64},
  50. {25, "clf_r", 32, 32, 0, 96},
  51. {26, "clf_s", 64, 32, 192, 0},
  52. {27, "clf_sd", 64, 32, 192, 32},
  53. {28, "clf_sf", 64, 32, 0, 64},
  54. {29, "clf_sg", 32, 32, 32, 96},
  55. {30, "clf_sg2", 32, 32, 0, 160},
  56. {31, "clf_sr", 32, 32, 32, 96},
  57. {32, "clf_ss", 32, 32, 32, 128},
  58. {33, "clf_ssd", 32, 32, 0, 224},
  59. {34, "clf_ssw", 32, 32, 224, 32},
  60. {35, "clf_sw", 32, 32, 192, 32},
  61. {36, "clf_w02", 64, 64, 128, 64},
  62. {37, "clf_w03", 64, 64, 192, 64},
  63. {38, "clf_was", 64, 32, 64, 64},
  64. {39, "clfeg", 32, 32, 192, 320},
  65. {40, "clfegd", 32, 32, 0, 320},
  66. {41, "clftop", 64, 32, 192, 64},
  67. {42, "clftop2", 32, 32, 128, 64},
  68. {43, "cndl_cl", 64, 32, 96, 128},
  69. {44, "cndlf", 64, 64, 160, 64},
  70. {45, "cndlf02", 64, 64, 208, 64},
  71. {46, "comtr", 16, 32, 144, 96},
  72. {47, "cosinn", 32, 32, 224, 416},
  73. {48, "cosinn2", 32, 32, 192, 448},
  74. {49, "csmk", 32, 32, 64, 64},
  75. {50, "csmk2", 32, 32, 96, 64},
  76. {51, "cstds01", 32, 32, 224, 160},
  77. {52, "cstds02", 64, 64, 0, 448},
  78. {53, "des01", 32, 32, 160, 320},
  79. {54, "desert", 64, 64, 128, 128},
  80. {55, "desor", 64, 32, 160, 64},
  81. {56, "ds1", 32, 32, 0, 256},
  82. {57, "ds_s1", 32, 32, 192, 288},
  83. {58, "dsee1", 32, 32, 96, 288},
  84. {59, "dsrt_d", 32, 32, 224, 0},
  85. {60, "dsrt_e", 64, 128, 64, 128},
  86. {61, "edes01", 32, 32, 224, 320},
  87. {62, "elm01", 32, 32, 160, 0},
  88. {63, "elm02", 32, 32, 64, 96},
  89. {64, "elm_gro", 64, 64, 0, 96},
  90. {65, "elm_r", 32, 32, 192, 0},
  91. {66, "elm_r2", 32, 32, 224, 0},
  92. {67, "fall1", 32, 32, 128, 256},
  93. {68, "farm01", 32, 32, 160, 32},
  94. {69, "farm02", 32, 32, 192, 32},
  95. {70, "farm_g", 32, 32, 128, 64},
  96. {71, "farm_r", 32, 16, 128, 48},
  97. {72, "fld", 64, 64, 64, 96},
  98. {73, "fld_02", 64, 64, 0, 64},
  99. {74, "fld_s", 64, 64, 0, 160},
  100. {75, "fld_s2", 32, 32, 224, 256},
  101. {76, "fld_sw", 64, 64, 128, 192},
  102. {77, "fld_v", 128, 128, 0, 128},
  103. {78, "fld_vd", 32, 64, 96, 128},
  104. {79, "fld_vd2", 32, 64, 192, 416},
  105. {80, "fvedge", 32, 64, 0, 0},
  106. {81, "gclf_d", 128, 64, 128, 128},
  107. {82, "gclf_g", 32, 64, 224, 128},
  108. {83, "gclfwa", 128, 64, 64, 320},
  109. {84, "gclfwa2", 32, 64, 160, 320},
  110. {85, "gclfwag", 32, 64, 32, 320},
  111. {86, "gg_gro", 64, 64, 64, 448},
  112. {87, "gg_mts", 64, 128, 0, 128},
  113. {88, "ggmk", 64, 64, 128, 448},
  114. {89, "ggmt", 128, 128, 0, 0},
  115. {90, "ggmt_e", 128, 32, 0, 96},
  116. {91, "ggmt_ed", 128, 32, 128, 96},
  117. {92, "ggmt_eg", 32, 32, 96, 224},
  118. {93, "ggmtd", 128, 128, 128, 0},
  119. {94, "ggs_g", 32, 32, 32, 64},
  120. {95, "ggshr", 32, 32, 192, 96},
  121. {96, "ggshrg", 32, 32, 224, 96},
  122. {97, "gia", 64, 32, 64, 224},
  123. {98, "gia2", 64, 32, 0, 224},
  124. {99, "gia_d", 64, 32, 128, 224},
  125. {100, "gia_d2", 64, 32, 64, 224},
  126. {101, "gia_g", 32, 32, 192, 224},
  127. {102, "gia_g2", 32, 32, 128, 224},
  128. {103, "gmt_eda", 32, 32, 0, 352},
  129. {104, "gonclf", 128, 64, 96, 64},
  130. {105, "gredge", 32, 32, 192, 192},
  131. {106, "hyouga", 64, 64, 192, 64},
  132. {107, "iceclf", 64, 32, 64, 96},
  133. {108, "iceclfd", 64, 32, 128, 96},
  134. {109, "iceclfg", 32, 32, 32, 224},
  135. {110, "jun", 64, 64, 192, 192},
  136. {111, "jun_d", 64, 64, 128, 192},
  137. {112, "jun_e", 64, 16, 0, 240},
  138. {113, "jun_gro", 64, 64, 0, 64},
  139. {114, "junmk", 32, 32, 0, 96},
  140. {115, "junn01", 32, 32, 160, 112},
  141. {116, "junn02", 32, 32, 192, 112},
  142. {117, "junn03", 32, 32, 224, 112},
  143. {118, "junn04", 32, 32, 64, 128},
  144. {119, "jutmpl01", 64, 64, 128, 192},
  145. {120, "lake-e", 32, 32, 96, 192},
  146. {121, "lake_ef", 32, 32, 128, 224},
  147. {122, "lake_fl", 128, 32, 160, 224},
  148. {123, "lostclf", 32, 64, 128, 384},
  149. {124, "lostmt", 128, 32, 128, 448},
  150. {125, "lostmtd", 128, 32, 128, 480},
  151. {126, "lostmts", 64, 32, 160, 384},
  152. {127, "lostwd_e", 32, 32, 64, 480},
  153. {128, "lostwod", 64, 64, 0, 448},
  154. {129, "lst1", 32, 32, 192, 256},
  155. {130, "lstwd_e2", 32, 32, 96, 480},
  156. {131, "mzes", 32, 32, 224, 128},
  157. {132, "mzmt_e", 128, 64, 128, 64},
  158. {133, "mzmt_ed", 128, 32, 128, 128},
  159. {134, "mzmt_edw", 128, 32, 128, 160},
  160. {135, "mzmt_ew", 128, 32, 0, 128},
  161. {136, "mzmt_o", 128, 32, 64, 416},
  162. {137, "mzmt_od", 128, 32, 64, 448},
  163. {138, "mzmt_s", 128, 32, 0, 192},
  164. {139, "mzmt_sd", 128, 32, 0, 160},
  165. {140, "md01", 32, 32, 96, 16},
  166. {141, "md02", 128, 128, 0, 0},
  167. {142, "md03", 16, 16, 112, 64},
  168. {143, "md04", 32, 32, 128, 16},
  169. {144, "md05", 64, 16, 96, 0},
  170. {145, "md06", 16, 32, 96, 48},
  171. {146, "md07", 16, 16, 112, 48},
  172. {147, "md_mt", 128, 128, 128, 0},
  173. {148, "md_mtd", 128, 128, 0, 0},
  174. {149, "md_mts", 64, 128, 64, 160},
  175. {150, "md_snow", 128, 32, 128, 0},
  176. {151, "md_snw2", 128, 32, 128, 32},
  177. {152, "md_snwd", 128, 64, 0, 128},
  178. {153, "md_snwe", 64, 64, 96, 320},
  179. {154, "md_snws", 64, 64, 128, 128},
  180. {155, "md_snwt", 128, 32, 0, 192},
  181. {156, "md_snww", 32, 32, 224, 224},
  182. {157, "md_sw_s", 128, 128, 0, 0},
  183. {158, "md_swd2", 32, 32, 192, 256},
  184. {159, "md_swnp", 128, 128, 0, 96},
  185. {160, "mdsrt_e", 128, 32, 128, 192},
  186. {161, "mdsrt_ed", 128, 32, 128, 224},
  187. {162, "mdsrt_eg", 32, 32, 64, 224},
  188. {163, "midil", 32, 32, 32, 192},
  189. {164, "midild", 32, 32, 224, 192},
  190. {165, "mt_ewg", 32, 32, 64, 96},
  191. {166, "mt_road", 64, 64, 192, 128},
  192. {167, "mt_se", 32, 32, 160, 416},
  193. {168, "mt_se2", 64, 64, 128, 256},
  194. {169, "mt_sg01", 32, 32, 0, 224},
  195. {170, "mt_sg02", 32, 32, 32, 224},
  196. {171, "mt_sg03", 32, 32, 0, 192},
  197. {172, "mt_sg04", 32, 32, 160, 384},
  198. {173, "mtcoin", 64, 64, 0, 256},
  199. {174, "mtwas_e", 128, 32, 0, 224},
  200. {175, "mtwas_ed", 128, 32, 0, 224},
  201. {176, "ncol_gro", 64, 64, 64, 384},
  202. {177, "ncole01", 32, 32, 224, 384},
  203. {178, "ncole02", 32, 32, 192, 416},
  204. {179, "nivl_gro", 64, 64, 128, 384},
  205. {180, "nivl_mt", 128, 64, 0, 0},
  206. {181, "nivl_top", 32, 32, 0, 64},
  207. {182, "nivlr", 32, 32, 192, 384},
  208. {183, "port", 32, 32, 96, 224},
  209. {184, "port_d", 32, 32, 160, 0},
  210. {185, "rzclf02", 64, 64, 128, 128},
  211. {186, "rct_gro", 64, 128, 0, 416},
  212. {187, "riv_cls", 64, 64, 64, 0},
  213. {188, "riv_l1", 32, 32, 96, 320},
  214. {189, "riv_m", 32, 32, 0, 224},
  215. {190, "rivr", 32, 32, 64, 224},
  216. {191, "rivrclf", 64, 64, 128, 192},
  217. {192, "rivs1", 32, 32, 128, 320},
  218. {193, "rivshr", 64, 64, 192, 192},
  219. {194, "rivssr", 64, 32, 192, 224},
  220. {195, "rivstrt", 32, 32, 192, 160},
  221. {196, "rm1", 32, 32, 32, 288},
  222. {197, "rocet", 32, 32, 128, 160},
  223. {198, "rs_ss", 32, 32, 96, 224},
  224. {199, "sango", 32, 32, 224, 320},
  225. {200, "sango2", 32, 32, 224, 352},
  226. {201, "sango3", 32, 32, 128, 384},
  227. {202, "sango4", 64, 64, 0, 384},
  228. {203, "sdun", 64, 64, 0, 160},
  229. {204, "sdun02", 64, 64, 64, 160},
  230. {205, "sh1", 32, 32, 32, 256},
  231. {206, "sh_s1", 32, 32, 224, 288},
  232. {207, "shedge", 32, 64, 160, 160},
  233. {208, "shlm_1", 32, 32, 192, 320},
  234. {209, "shol", 128, 128, 128, 96},
  235. {210, "shol_s", 64, 64, 192, 192},
  236. {211, "shor", 128, 128, 0, 0},
  237. {212, "shor_s", 64, 64, 128, 192},
  238. {213, "shor_s2", 32, 32, 224, 416},
  239. {214, "shor_v", 32, 32, 192, 0},
  240. {215, "silo", 32, 32, 224, 32},
  241. {216, "slope", 128, 32, 0, 384},
  242. {217, "snow_es", 32, 32, 192, 480},
  243. {218, "snow_es2", 32, 32, 224, 480},
  244. {219, "snow_es3", 32, 32, 224, 448},
  245. {220, "snw_mt", 128, 128, 0, 0},
  246. {221, "snw_mtd", 128, 128, 128, 0},
  247. {222, "snw_mte", 64, 32, 0, 96},
  248. {223, "snw_mted", 64, 32, 64, 96},
  249. {224, "snw_mts", 64, 128, 64, 0},
  250. {225, "snw_mts2", 64, 32, 128, 192},
  251. {226, "snwfld", 64, 64, 0, 64},
  252. {227, "snwfld_s", 64, 32, 128, 128},
  253. {228, "snwgra", 64, 64, 192, 192},
  254. {229, "snwhm01", 32, 32, 32, 0},
  255. {230, "snwhm02", 32, 32, 32, 32},
  256. {231, "snwods", 32, 32, 224, 192},
  257. {232, "snwood", 64, 64, 192, 128},
  258. {233, "snwtrk", 32, 64, 96, 256},
  259. {234, "sse_s1", 32, 32, 32, 320},
  260. {235, "ssee1", 32, 32, 64, 288},
  261. {236, "sst1", 32, 32, 224, 256},
  262. {237, "stown_r", 32, 32, 192, 256},
  263. {238, "stw_gro", 64, 64, 0, 384},
  264. {239, "subrg2", 32, 32, 224, 160},
  265. {240, "susbrg", 64, 64, 192, 96},
  266. {241, "sw_se", 64, 64, 0, 0},
  267. {242, "swclf_l", 64, 64, 64, 128},
  268. {243, "swclf_ld", 64, 64, 192, 128},
  269. {244, "swclf_lg", 32, 64, 0, 192},
  270. {245, "swclf_s", 64, 32, 128, 96},
  271. {246, "swclf_sd", 64, 32, 192, 96},
  272. {247, "swclf_sg", 32, 32, 32, 192},
  273. {248, "swclf_wg", 32, 32, 192, 192},
  274. {249, "swfld_s2", 64, 32, 128, 160},
  275. {250, "swfld_s3", 32, 32, 160, 192},
  276. {251, "swmd_cg", 32, 32, 128, 192},
  277. {252, "swmd_clf", 64, 32, 64, 192},
  278. {253, "swp1", 32, 32, 0, 288},
  279. {254, "trk", 64, 64, 128, 0},
  280. {255, "tyo_f", 128, 128, 128, 128},
  281. {256, "tyosnw", 64, 128, 64, 384},
  282. {257, "uf1", 32, 32, 160, 256},
  283. {258, "utai01", 32, 32, 32, 96},
  284. {259, "utai02", 32, 32, 224, 64},
  285. {260, "utai_gro", 64, 64, 128, 96},
  286. {261, "utaimt", 32, 32, 0, 128},
  287. {262, "utaimtd", 32, 32, 96, 96},
  288. {263, "utaimtg", 32, 32, 96, 128},
  289. {264, "wa1", 32, 32, 192, 320},
  290. {265, "wzs1", 32, 32, 128, 288},
  291. {266, "wzshr", 32, 32, 160, 32},
  292. {267, "wzshr2", 32, 32, 32, 128},
  293. {268, "wzshrs", 32, 32, 32, 160},
  294. {269, "was", 128, 128, 0, 96},
  295. {270, "was_d", 64, 32, 0, 224},
  296. {271, "was_g", 64, 64, 0, 192},
  297. {272, "was_s", 128, 128, 128, 0},
  298. {273, "wasfld", 64, 64, 64, 256},
  299. {274, "wdedge", 64, 64, 64, 160},
  300. {275, "we1", 32, 32, 96, 256},
  301. {276, "we_s1", 32, 32, 160, 288},
  302. {277, "wedged", 32, 64, 128, 160},
  303. {278, "wod-e2", 32, 32, 64, 224},
  304. {279, "wood", 64, 64, 192, 0},
  305. {280, "wood_d", 64, 64, 192, 160},
  306. {281, "wtrk", 32, 64, 64, 96},
  307. // The ids 282-293 (ff7.exe table of u, v at 0x95b9f0) are the ones that WM2 uses (its ids + 282).
  308. {282, "cltr", 128, 128, 0, 0},
  309. {283, "lake_a", 128, 256, 0, 0},
  310. {284, "rock", 256, 256, 0, 0},
  311. {285, "scave", 256, 256, 0, 0},
  312. {286, "ssand", 256, 256, 0, 0},
  313. {287, "swall02", 256, 256, 0, 0},
  314. {288, "sng01", 128, 128, 128, 0},
  315. {289, "sng02", 128, 128, 128, 0},
  316. {290, "hokola01", 64, 64, 0, 0},
  317. {291, "hokola02", 64, 64, 0, 128},
  318. {292, "snwfldl", 64, 64, 0, 64},
  319. {293, "snwfld2", 64, 64, 0, 192}
  320. };
  321. const size_t WORLD_MAP_TEXTURE_COUNT = sizeof(WORLD_MAP_TEXTURES) / sizeof(WORLD_MAP_TEXTURES[0]);
  322. /**
  323. * The ids of the textures of WM2 and WM3 start after the ones of WM0 in the table of the game:
  324. * WM2 uses 0-7 as 282-289 and WM3 0-3 as 290-293 (checked with the ranges of their UVs).
  325. */
  326. uint16 GetTextureIdOffset(const uint8 map_id){
  327. return map_id == 1 ? 282 : (map_id == 2 ? 290 : 0);
  328. }
  329. bool IsFootWalkable(uint8 walkability_type){
  330. using WalkType = VGears::WorldmapFileSerializer::TriangleWalkMapTypes;
  331. switch (walkability_type){
  332. case WalkType::GRASS:
  333. case WalkType::FOREST:
  334. case WalkType::SWAMP:
  335. case WalkType::DESERT:
  336. case WalkType::WASTELAND:
  337. case WalkType::SNOW:
  338. case WalkType::RIVERSIDE:
  339. case WalkType::COREL_BRIDGE:
  340. case WalkType::WUTAI_BRIDGE:
  341. case WalkType::HILL_SIDE:
  342. case WalkType::BEACH:
  343. case WalkType::CANYON:
  344. case WalkType::MOUNTAIN_PASS:
  345. case WalkType::GOLD_SAUCER_DESERT:
  346. case WalkType::JUNGLE:
  347. case WalkType::NORTHERND_CAVE:
  348. case WalkType::GOLD_SAUCER_DESERT_BORDER:
  349. case WalkType::BRIDGE_HEAD:
  350. case WalkType::BACK_ENTRANCE:
  351. return true;
  352. default:
  353. return false;
  354. }
  355. }
  356. const std::map<Ogre::String, uint8>& GetWorldMapTerrainTypes(){
  357. using WalkType = VGears::WorldmapFileSerializer::TriangleWalkMapTypes;
  358. static const std::map<Ogre::String, uint8> terrain_types = {
  359. {"GRASS", static_cast<uint8>(WalkType::GRASS)},
  360. {"FOREST", static_cast<uint8>(WalkType::FOREST)},
  361. {"MOUNTAIN", static_cast<uint8>(WalkType::MOUNTAIN)},
  362. {"SEA_DEEP_WATER", static_cast<uint8>(WalkType::SEA_DEEP_WATER)},
  363. {"RIVER_CROSSING", static_cast<uint8>(WalkType::RIVER_CROSSING)},
  364. {"RIVER", static_cast<uint8>(WalkType::RIVER)},
  365. {"WATER", static_cast<uint8>(WalkType::WATER)},
  366. {"SWAMP", static_cast<uint8>(WalkType::SWAMP)},
  367. {"DESERT", static_cast<uint8>(WalkType::DESERT)},
  368. {"WASTELAND", static_cast<uint8>(WalkType::WASTELAND)},
  369. {"SNOW", static_cast<uint8>(WalkType::SNOW)},
  370. {"RIVERSIDE", static_cast<uint8>(WalkType::RIVERSIDE)},
  371. {"CLIFF", static_cast<uint8>(WalkType::CLIFF)},
  372. {"COREL_BRIDGE", static_cast<uint8>(WalkType::COREL_BRIDGE)},
  373. {"WUTAI_BRIDGE", static_cast<uint8>(WalkType::WUTAI_BRIDGE)},
  374. {"UNUSED_1", static_cast<uint8>(WalkType::UNUSED_1)},
  375. {"HILL_SIDE", static_cast<uint8>(WalkType::HILL_SIDE)},
  376. {"BEACH", static_cast<uint8>(WalkType::BEACH)},
  377. {"SUBMARINE_PEN", static_cast<uint8>(WalkType::SUBMARINE_PEN)},
  378. {"CANYON", static_cast<uint8>(WalkType::CANYON)},
  379. {"MOUNTAIN_PASS", static_cast<uint8>(WalkType::MOUNTAIN_PASS)},
  380. {"UNKNOWN_1", static_cast<uint8>(WalkType::UNKNOWN_1)},
  381. {"WATERFALL", static_cast<uint8>(WalkType::WATERFALL)},
  382. {"UNUSED_2", static_cast<uint8>(WalkType::UNUSED_2)},
  383. {"GOLD_SAUCER_DESERT", static_cast<uint8>(WalkType::GOLD_SAUCER_DESERT)},
  384. {"JUNGLE", static_cast<uint8>(WalkType::JUNGLE)},
  385. {"SEA", static_cast<uint8>(WalkType::SEA)},
  386. {"NORTHERND_CAVE", static_cast<uint8>(WalkType::NORTHERND_CAVE)},
  387. {"GOLD_SAUCER_DESERT_BORDER", static_cast<uint8>(WalkType::GOLD_SAUCER_DESERT_BORDER)},
  388. {"BRIDGE_HEAD", static_cast<uint8>(WalkType::BRIDGE_HEAD)},
  389. {"BACK_ENTRANCE", static_cast<uint8>(WalkType::BACK_ENTRANCE)},
  390. {"UNUSED_3", static_cast<uint8>(WalkType::UNUSED_3)}
  391. };
  392. return terrain_types;
  393. }
  394. Ogre::String GetWorldMapTerrainName(const uint8 walkability_type){
  395. for (const auto& terrain : GetWorldMapTerrainTypes()){
  396. if (terrain.second == walkability_type) return terrain.first;
  397. }
  398. return "";
  399. }
  400. MapLayout GetMapLayout(const int map_id){
  401. switch (map_id){
  402. case 1: return {3, 4, 3, 2};
  403. case 2: return {2, 2, 0, 0};
  404. default: return {9, 7, 0, 0};
  405. }
  406. }
  407. /**
  408. * Gets if a position of the world is inside the blocks of a map.
  409. */
  410. bool IsInsideMap(const int map_id, const float x, const float z){
  411. const MapLayout layout = GetMapLayout(map_id);
  412. const float block_size = (8182.0f / 4096.0f) * 4.0f;
  413. const float bx = x / block_size - layout.origin_x;
  414. const float bz = z / block_size - layout.origin_y;
  415. return bx >= 0 && bz >= 0 && bx < layout.width && bz < layout.height;
  416. }
  417. /**
  418. * Loads and parses an installed world map file.
  419. *
  420. * @param[in] file_name Name of the MAP file, like "WM0.MAP".
  421. * @return The map blocks.
  422. */
  423. std::vector<VGears::WorldmapFileSerializer::Block> LoadWorldMap(
  424. const Ogre::String& file_name
  425. ){
  426. /**
  427. * The serializer retains its parsed blocks; the resource argument is
  428. * currently unused by the MAP serializer.
  429. */
  430. class TestFile : public VGears::WorldmapFile{
  431. public:
  432. TestFile() : VGears::WorldmapFile(nullptr, "", 0, "") {}
  433. };
  434. Ogre::DataStreamPtr stream
  435. = Ogre::ResourceGroupManager::getSingleton().openResource(
  436. file_name, WORLD_MAP_RESOURCE_GROUP, nullptr, true
  437. );
  438. TestFile file;
  439. VGears::WorldmapFileSerializer serializer;
  440. serializer.ImportWorldmapFile(stream, file);
  441. Ogre::LogManager::getSingleton().logMessage(
  442. "Loaded " + file_name + " with " + std::to_string(serializer.blocks.size())
  443. + " blocks."
  444. );
  445. return serializer.blocks;
  446. }
  447. float From16BitFixedPoint(VGears::sint16 coord){
  448. // return float(coord);
  449. return (float(coord) / 4096.0f);
  450. }
  451. } // namespace VGears