Savemap.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. #pragma once
  16. #include <map>
  17. #include <string>
  18. #include "common/TypeDefine.h"
  19. /**
  20. * A savemap.
  21. */
  22. class Savemap{
  23. public:
  24. /**
  25. * Constructor. Initializes an empty savemap.
  26. */
  27. Savemap();
  28. /**
  29. * Destructor.
  30. */
  31. ~Savemap();
  32. /**
  33. * Assignment operator.
  34. *
  35. * Copies a savemap into another, including control data.
  36. *
  37. * @param[in] to_copy The savemap to copy from.
  38. */
  39. void operator = (const Savemap &to_copy);
  40. /**
  41. * Reads the savemap data from a file.
  42. *
  43. * @param[in] file_name The name of the file to read.
  44. */
  45. void Read(std::string file_name);
  46. /**
  47. * Writes the savemap to a file.
  48. *
  49. * @param[in] slot The slot the savemap is to be written to.
  50. * @param[in] file_name Name of the file the savemap is to be written to.
  51. */
  52. void Write(int slot, std::string file_name);
  53. /**
  54. * Retrieves a control string for a savemap.
  55. *
  56. * Not a checksum, it does not depend on the actual data. It never mutates, is used to
  57. * differenciate savemaps when asking to override.
  58. */
  59. std::string GetControlKey() const;
  60. /**
  61. * Sets the control string of the savemap.
  62. *
  63. * @param[in] control The control string.
  64. */
  65. void SetControlKey(const std::string control);
  66. /**
  67. * Sets the window colours in the current savemap.
  68. *
  69. * @param[in] t_l_r Top-left corner, red component.
  70. * @param[in] t_l_g Top-left corner, green component.
  71. * @param[in] t_l_b Top-left corner, blue component.
  72. * @param[in] t_r_r Top-right corner, red component.
  73. * @param[in] t_r_g Top-right corner, green component.
  74. * @param[in] t_r_b Top-right corner, blue component.
  75. * @param[in] b_r_r Bottom-right corner, red component.
  76. * @param[in] b_r_g Bottom-right corner, green component.
  77. * @param[in] b_r_b Bottom-right corner, blue component.
  78. * @param[in] b_l_r Bottom-left corner, red component.
  79. * @param[in] b_l_g Bottom-left corner, green component.
  80. * @param[in] b_l_b Bottom-left corner, blue component.
  81. */
  82. void SetWindowColours(
  83. const unsigned int t_l_r, const unsigned int t_l_g, const unsigned int t_l_b,
  84. const unsigned int t_r_r, const unsigned int t_r_g, const unsigned int t_r_b,
  85. const unsigned int b_r_r, const unsigned int b_r_g, const unsigned int b_r_b,
  86. const unsigned int b_l_r, const unsigned int b_l_g, const unsigned int b_l_b
  87. );
  88. /**
  89. * Sets the money of the savemap.
  90. *
  91. * @param[in] money The current money.
  92. */
  93. void SetMoney(const unsigned int money);
  94. /**
  95. * Sets the total playtime of the savemap.
  96. *
  97. * @param[in] seconds The total playtime, in seconds.
  98. */
  99. void SetGameTime(const unsigned int seconds);
  100. /**
  101. * Sets the time of the curent timer.
  102. *
  103. * @param[in] seconds The current countdown timer time, in seconds.
  104. */
  105. void SetCountdownTime(const unsigned int seconds);
  106. /**
  107. * Marks a key item as owned or non-owned in the savemap.
  108. *
  109. * @param[in] item Key item id.
  110. * @param[in] owned True to mark it as owned, false to mark is as non-owned.
  111. */
  112. void SetKeyItem(const unsigned int item, const bool owned);
  113. /**
  114. * Sets the current party in the savemap.
  115. *
  116. * @param[in] member_1 The first party member ID. -1 to leave empty.
  117. * @param[in] member_2 The second party member ID. -1 to leave empty.
  118. * @param[in] member_3 The third party member ID. -1 to leave empty.
  119. */
  120. void SetParty(const int member_1, const int member_2, const int member_3);
  121. /**
  122. * Sets an item in a inventory slot in the savemap.
  123. *
  124. * @param[in] slot Inventory slot.
  125. * @param[in] id Item ID.
  126. * @param[in] quantity Item quantity. Set to 0 to mark as no item in the specified slot.
  127. */
  128. void SetItem(const unsigned int slot, const unsigned int id, const unsigned int quantity);
  129. /**
  130. * Sets a materia in a materia inventory slot in the savemap.
  131. *
  132. * For Enemy Skill materia, don't use this, use {@see SetESkillMateria}.
  133. *
  134. * @param[in] slot Materia inventory slot.
  135. * @param[in] id Materia ID. Set to -1 to mark it as an empty slot.
  136. * @param[in] ap Total AP of the materia.
  137. */
  138. void SetMateria(const unsigned int slot, const int id, const unsigned int ap);
  139. /**
  140. * Sets a skill as learned in an Enemy Skill materia inventory slot in the savemap.
  141. *
  142. * Calling this will make the materia in the slot to be an Enemy Skill materia and set the
  143. * AP to 0. To delete it, call {@see SetMateria} with the same slot and id -1.
  144. *
  145. * @param[in] slot Materia inventory slot.
  146. * @param[in] skill Enemy Skill ID (sequential, from 0).
  147. * @param[in] learned TRue to mark as learned, false to mark as not learned.
  148. */
  149. void SetESkillMateria(const unsigned slot, const unsigned int skill, const bool learned);
  150. /**
  151. * Sets a materia in a materia inventory slot in the savemap.
  152. *
  153. * For Enemy Skill materia, don't use this, use {@see SetEnemySkillMateriaStash}.
  154. *
  155. * @param[in] slot Materia inventory slot.
  156. * @param[in] id Materia ID. Set to -1 to mark it as an empty slot.
  157. * @param[in] ap Total AP of the materia.
  158. */
  159. void SetMateriaStash(const unsigned int slot, const int id, const unsigned int ap);
  160. /**
  161. * Sets a skill as learned in an Enemy Skill materia stash slot in the savemap.
  162. *
  163. * Calling this will make the materia in the slot to be an Enemy Skill materia and set the
  164. * AP to 0. To delete it, call {@see SetMateriaStash} with the same slot and id -1.
  165. *
  166. * @param[in] slot Materia inventory slot.
  167. * @param[in] skill Enemy Skill ID (sequential, from 0)
  168. * @param[in] learned TRue to mark as learned, false to mark as not learned.
  169. */
  170. void SetESkillMateriaStash(
  171. const unsigned slot, const unsigned int skill, const bool learned
  172. );
  173. /**
  174. * Sets the current location in the savemap.
  175. *
  176. * @param[in] x X coordinate.
  177. * @param[in] y Y coordinate.
  178. * @param[in] z Z coordinate. It's optional, set it to -1 to ignore it.
  179. * @param[in] triangle Walkmesh triangle ID.
  180. * @param[in] angle Facing direction.
  181. * @param[in] field Field map ID, or empty for the world map.
  182. * @param[in] name Name of the location to show in the save slot.
  183. */
  184. void SetLocation(
  185. const float x, const float y, const float z,
  186. const unsigned int triangle, const int angle, std::string field, std::string name
  187. );
  188. /**
  189. * Sets a setting value in the savemap.
  190. *
  191. * @param[in] key Name of the setting.
  192. * @param[in] value Setting value.
  193. */
  194. void SetSetting(const std::string& key, const int value);
  195. /**
  196. * Checks if the savemap has a setting.
  197. *
  198. * @param[in] key Name of the setting.
  199. * @return True if the setting was saved. Savemaps from older versions have none.
  200. */
  201. bool HasSetting(const std::string& key) const;
  202. /**
  203. * Gets the value of a setting.
  204. *
  205. * @param[in] key Name of the setting.
  206. * @return The value of the setting, or 0 if the savemap doesn't have it.
  207. */
  208. int GetSetting(const std::string& key) const;
  209. /**
  210. * Sets a character basic information in the savemap.
  211. *
  212. * @param[in] id Character ID.
  213. * @param[in] char_id Character identifier.
  214. * @param[in] name Character name.
  215. * @param[in] enabled If enabled in the PHS.
  216. * @param[in] locked If locked in or out the current party.
  217. * @param[in] level Character level.
  218. * @param[in] kills Total kills.
  219. * @param[in] back_row If the character is in the back row.
  220. * @param[in] exp Total experience.
  221. * @param[in] exp_to_next Experience to reach next level.
  222. * @param[in] limit_level Currently selected limit level.
  223. * @param[in] limit_bar Current limit bar fill status
  224. * @param[in] weapon Equipped weapon ID.
  225. * @param[in] armor Equipped armor ID.
  226. * @param[in] accessory Equipped accessory ID. -1 if none equipped.
  227. */
  228. void SetCharacterInfo(
  229. const unsigned int id, const int char_id, const std::string name,
  230. const bool enabled, const bool locked,
  231. const unsigned int level, const unsigned int kills,
  232. const bool back_row, const unsigned int exp, const unsigned int exp_to_next,
  233. const unsigned int limit_level, const unsigned int limit_bar,
  234. const unsigned int weapon, const unsigned int armor, const int accessory
  235. );
  236. /**
  237. * Sets a character stat values in the savemap.
  238. *
  239. * @param[in] id Character ID.
  240. * @param[in] stat Stat ID. See {@see STAT}.
  241. * @param[in] base Base value of the stat.
  242. * @param[in] extra Extra value of the stat. For STR, VIT, MAG, SPR, DEX and LCK, it means
  243. * the increment by means of sources. For HP and MP, the current value.
  244. */
  245. void SetCharacterStat(
  246. const unsigned int id, const unsigned int stat,
  247. const unsigned int base, const unsigned int extra
  248. );
  249. /**
  250. * Sets a character limit learned status in the savemap.
  251. *
  252. * @param[in] id Character ID.
  253. * @param[in] level Limit level.
  254. * @param[in] technique Limit level technique ID.
  255. * @param[in] learned TRue to mark as learned, false to mark as non-learned.
  256. * @param[in] uses Times the technique has been used.
  257. */
  258. void SetCharacterLimitLearned(
  259. const unsigned int id, const unsigned int level,
  260. const unsigned int technique, const bool learned, const unsigned int uses
  261. );
  262. /**
  263. * Sets a materia in a character weapon or armor slot in the savemap.
  264. *
  265. * For Enemy Skill materia, don't use this, use {@see SetCharacterESkillMateria}.
  266. *
  267. * @param[in] id Character ID.
  268. * @param[in] weapon True to set the materia in the weapon, false to set it in the armor.
  269. * @param[in] slot Weapon or armor slot.
  270. * @param[in] materia Materia ID. Set to -1 to mark it as an empty slot.
  271. * @param[in] ap Total AP of the materia.
  272. */
  273. void SetCharacterMateria(
  274. const unsigned int id, const bool weapon, const unsigned int slot,
  275. const int materia, const unsigned int ap
  276. );
  277. /**
  278. * Sets a skill as learned in a character's Enemy Skill materia in the savemap.
  279. *
  280. * Calling this will make the materia to be an Enemy Skill materia and set the AP to 0. To
  281. * delete it, call {@see SetCharacterMateria} with the same character ID, weapon/armor and
  282. * slot and id -1.
  283. *
  284. * @param[in] id Character ID.
  285. * @param[in] weapon True to set the materia in the weapon, false to set it in the armor.
  286. * @param[in] slot Weapon or armor slot.
  287. * @param[in] skill Enemy Skill ID (sequential, from 0).
  288. * @param[in] learned TRue to mark as learned, false to mark as not learned.
  289. */
  290. void SetCharacterESkillMateria(
  291. const unsigned int id, const bool weapon, const unsigned int slot,
  292. const unsigned int skill, const bool learned
  293. );
  294. /**
  295. * Adds or removes a status to a character in the savemap.
  296. *
  297. * @param[in] id Character ID.
  298. * @param[in] status ID of the status.
  299. * @param[in] inflicted True to add the status, false to remove it.
  300. */
  301. void SetCharacterStatus(
  302. const unsigned int id, const unsigned int status, const bool inflicted
  303. );
  304. /**
  305. * Sets data in a data bank.
  306. *
  307. * @param[in] bank Data bank index.
  308. * @param[in] address Address in the data bank.
  309. * @param[in] value The value to store.
  310. */
  311. void SetData(const unsigned int bank, const unsigned int address, const int value);
  312. /**
  313. * Checks if the savemap is empty.
  314. *
  315. * @return True if the savemap is empty, false if it contains a saved game.
  316. */
  317. bool IsEmpty();
  318. /**
  319. * Retrieves the control key .
  320. *
  321. * @return The control key of the slot.
  322. */
  323. std::string GetControlKey();
  324. /**
  325. * Retrieves a colour component from a window corner.
  326. *
  327. * @param[in] corner The window corner. See {@see Corner}.
  328. * @param[in] comp The color component to get. See {@see Colour}.
  329. * @return The color component of the specified corner of windows. If an invalid slot is
  330. * specified, or if the slot is empty, or if an invalid corner or color are requested, 0.
  331. */
  332. unsigned int GetWindowCornerColourComponent(
  333. const unsigned int corner, const unsigned int comp
  334. );
  335. /**
  336. * Retrieves the money.
  337. *
  338. * @return The money of the slot.
  339. */
  340. unsigned int GetMoney();
  341. /**
  342. * Retrieves the total playtime.
  343. *
  344. * @param[in] slot The slot to read from.
  345. * @return The total playtime, in seconds.
  346. */
  347. unsigned int GetGameTime();
  348. /**
  349. * Retrieves the time in the timer.
  350. *
  351. * @return The timer time, in seconds. If there is no timer saved, 0.
  352. */
  353. unsigned int GetCountdownTime();
  354. /**
  355. * Retrieves the ID of a party member.
  356. *
  357. * @param[in] pos Position in the party.
  358. * @return The ID of the character at the requested position. If there is no character at
  359. * the requested position, -1.
  360. */
  361. int GetPartyMember(const unsigned int pos);
  362. /**
  363. * Retrieves the ID of an item in the inventory.
  364. *
  365. * @param[in] pos Position in the inventory.
  366. * @return The ID of the item at the requested inventory position. If there is no item at
  367. * the requested position, 0.
  368. */
  369. unsigned int GetItemAtPosId(const unsigned int pos);
  370. /**
  371. * Retrieves the quantity of an item in the inventory.
  372. *
  373. * @param[in] pos Position in the inventory.
  374. * @return The quantity of the item at the requested inventory position. If there is no
  375. * item at the requested position, 0.
  376. */
  377. unsigned int GetItemAtPosQty(const unsigned int pos);
  378. /**
  379. * Checks if a key item is owned.
  380. *
  381. * @param[in] id Key item ID.
  382. * @return True if the key item is owned, false if not. If an invalid id is passed, false.
  383. */
  384. bool GetKeyItem(const unsigned int id);
  385. /**
  386. * Retrieves the ID of a materia in the inventory.
  387. *
  388. * @param[in] pos Position in the materia inventory.
  389. * @return The ID of the materia at the requested inventory position. If an invalid
  390. * position is passed, or if there is no materia at the requested position, -1.
  391. */
  392. int GetMateriaAtPosId(const unsigned int pos);
  393. /**
  394. * Retrieves the AP of a materia in the inventory.
  395. *
  396. * @param[in] pos Position in the materia inventory.
  397. * @return The AP of the materia at the requested inventory position. If an invalid
  398. * position is passed, or if there is no materia at the requested position, 0.
  399. */
  400. unsigned int GetMateriaAtPosAp(const unsigned int pos);
  401. /**
  402. * Checks if there is an Enemy Skill materia at a inventory position.
  403. *
  404. * @param[in] pos Position in the materia inventory.
  405. * @return True if the materia in the specified position is an Enemy Skill materia, false
  406. * if not. If an invalid position is passed, or if there is no materia at that position,
  407. * false.
  408. */
  409. bool IsMateriaAtPosESkill(const unsigned int pos);
  410. /**
  411. * Checks if a a enemy skill is learned by a materia in the inventory.
  412. *
  413. * @param[in] pos Position in the materia inventory.
  414. * @param[in] skill Skill ID, starting from 0.
  415. * @return True if the materia in the specified position exists, is an Enemy Skill materia
  416. * and has learned the specified skill. False in any other case.
  417. */
  418. bool IsMateriaAtPosESkillLearned(const unsigned int pos, const unsigned int skill);
  419. /**
  420. * Retrieves the ID of a materia in the stash.
  421. *
  422. * @param[in] pos Position in the materia stash.
  423. * @return The ID of the materia at the requested stahs position. If an invalid
  424. * position is passed, or if there is no materia at the requested position, -1.
  425. */
  426. int GetStashAtPosId(const unsigned int pos);
  427. /**
  428. * Retrieves the AP of a materia in the stash.
  429. *
  430. * @param[in] pos Position in the materia stash.
  431. * @return The AP of the materia at the requested inventory position. If an invalid
  432. * position is passed, or if there is no materia at the requested position, 0.
  433. */
  434. unsigned int GetStashAtPosAp(const unsigned int pos);
  435. /**
  436. * Checks if there is an Enemy Skill materia at a stash position.
  437. *
  438. * @param[in] pos Position in the materia stash.
  439. * @return True if the materia in the specified position is an Enemy Skill materia, false
  440. * if not. If an invalid position is passed, or if there is no materia at that position,
  441. * false.
  442. */
  443. bool IsStashAtPosESkill(const unsigned int pos);
  444. /**
  445. * Checks if a a enemy skill is learned by a materia in the stash.
  446. *
  447. * @param[in] pos Position in the materia stash.
  448. * @param[in] skill Skill ID, starting from 0.
  449. * @return True if the materia in the specified position exists, is an Enemy Skill materia
  450. * and has learned the specified skill. False in any other case.
  451. */
  452. bool IsStashAtPosESkillLearned(const unsigned int pos, const unsigned int skill);
  453. /**
  454. * Retrieves the X coordinate of the player.
  455. *
  456. * @return The X coordinate.
  457. */
  458. float GetLocationX();
  459. /**
  460. * Retrieves the Y coordinate of the player.
  461. *
  462. * @return The Y coordinate.
  463. */
  464. float GetLocationY();
  465. /**
  466. * Retrieves the Z coordinate of the player.
  467. *
  468. * @return The Z coordinate. If it was not saved, it will be lower than 0.
  469. */
  470. float GetLocationZ();
  471. /**
  472. * Retrieves the walkmesh triangle of the player.
  473. *
  474. * @return The triangle ID.
  475. */
  476. unsigned int GetLocationTriangle();
  477. /**
  478. * Retrieves the facing angle of the player.
  479. *
  480. * @param[in] slot The slot to read from.
  481. * @return The angle.
  482. */
  483. int GetLocationAngle();
  484. /**
  485. * Retrieves the field ID.
  486. *
  487. * @return The field ID. If the savemap is saved in the worldmap, an empty string.
  488. */
  489. std::string GetLocationField();
  490. /**
  491. * Retrieves the location name.
  492. *
  493. * @return The location name to be displayed in the save slot. If the location name has not
  494. * been saved, an empty string.
  495. */
  496. std::string GetLocationName();
  497. /**
  498. * Retrieves the char ID of a character.
  499. *
  500. * @param[in] id The character ID.
  501. * @return The char ID of the character. If an invalid id is passed, or if the character
  502. * doesn't have a char ID, -1.
  503. */
  504. int GetCharacterCharId(const unsigned int id);
  505. /**
  506. * Retrieves the name of a character.
  507. *
  508. * @param[in] id The character ID.
  509. * @return The name of the character. If an invalid id is passed, an empty string.
  510. */
  511. std::string GetCharacterName(const unsigned int id);
  512. /**
  513. * Retrieves the level of a character.
  514. *
  515. * @param[in] id The character ID.
  516. * @return The level of the character. If an invalid id is passed, 1.
  517. */
  518. unsigned int GetCharacterLevel(const unsigned int id);
  519. /**
  520. * Retrieves the total kills of a character.
  521. *
  522. * @param[in] id The character ID.
  523. * @return The kills of the character. If an invalid id is passed, 0.
  524. */
  525. unsigned int GetCharacterKills(const unsigned int id);
  526. /**
  527. * Checks if a character is enabled.
  528. *
  529. * @param[in] id The character ID.
  530. * @return True if the character is enabled, false if not. If an invalid id is passed,
  531. * false.
  532. */
  533. bool IsCharacterEnabled(const unsigned int id);
  534. /**
  535. * Checks if a character is locked in or out of the party
  536. *
  537. * @param[in] id The character ID.
  538. * @return True if the character is enabled, false if not. If an invalid id is passed,
  539. * false.
  540. */
  541. bool IsCharacterLocked(const unsigned int id);
  542. /**
  543. * Checks the row of a character.
  544. *
  545. * @param[in] id The character ID.
  546. * @return True if the character is in the back row, false if not. If an invalid id is
  547. * passed, false.
  548. */
  549. bool IsCharacterBackRow(const unsigned int id);
  550. /**
  551. * Retrieves the total experience of a character.
  552. *
  553. * @param[in] id The character ID.
  554. * @return The experience of the character. If an invalid id is passed, 0.
  555. */
  556. unsigned int GetCharacterExp(const unsigned int id);
  557. /**
  558. * Retrieves the experience for next level of a character.
  559. *
  560. * @param[in] id The character ID.
  561. * @return The experience of the character. If an invalid id is passed, 0.
  562. */
  563. unsigned int GetCharacterExpToNext(const unsigned int id);
  564. /**
  565. * Retrieves the current limit level of a character from a saved savemap.
  566. *
  567. * @param[in] id The character ID.
  568. * @return The limit level of the character. If an invalid id is passed, 0.
  569. */
  570. unsigned int GetCharacterLimitLevel(const unsigned int id);
  571. /**
  572. * Retrieves the current limit bar status level of a character.
  573. *
  574. * @param[in] id The character ID.
  575. * @return The limit bar status of the character. If an invalid id is passed, 0.
  576. */
  577. unsigned int GetCharacterLimitBar(const unsigned int id);
  578. /**
  579. * Retrieves the ID of the weapon of a character.
  580. *
  581. * @param[in] id The character ID.
  582. * @return The character's weapon ID. If an invalid id is passed, 0.
  583. */
  584. unsigned int GetCharacterWeaponId(const unsigned int id);
  585. /**
  586. * Retrieves the ID of the armor of a character.
  587. *
  588. * @param[in] id The character ID.
  589. * @return The character's armor ID. If an invalid id is passed, 0.
  590. */
  591. unsigned int GetCharacterArmorId(const unsigned int id);
  592. /**
  593. * Retrieves the ID of the weapon of a character.
  594. *
  595. * @param[in] id The character ID.
  596. * @return The character's weapon ID. If an invalid id is passed, or if the characetr has
  597. * no accessory, -1.
  598. */
  599. int GetCharacterAccessoryId(const unsigned int id);
  600. /**
  601. * Retrieves the base value of a stat of a character.
  602. *
  603. * @param[in] id The character ID.
  604. * @param[in] stat The stat ID (see {@see STAT}).
  605. * @return The base value of the specified stat. If an invalid id or stat is passed, 0.
  606. */
  607. unsigned int GetCharacterStatBase(const unsigned int id, const unsigned int stat);
  608. /**
  609. * Retrieves the extra value of a stat of a character.
  610. *
  611. * For HP and MP, the extra value means the current value. For any other stat, the bonus
  612. * gained by using sources.
  613. *
  614. * @param[in] id The character ID.
  615. * @param[in] stat The stat ID (see {@see Savemap::STAT}).
  616. * @return The extra value of the specified stat. If an invalid id or stat is passed, 0.
  617. */
  618. unsigned int GetCharacterStatExtra(const unsigned int id, const unsigned int stat);
  619. /**
  620. * Retrieves the uses of a character's limit level.
  621. *
  622. * @param[in] id The character ID.
  623. * @param[in] level The limit level.
  624. * @return Number of uses of the techniques in the specified limit level. If an invalid id
  625. * or limit level is passed, 0.
  626. */
  627. unsigned int GetCharacterLimitUses(const unsigned int id, const unsigned int level);
  628. /**
  629. * Checks if a limit technique is learned by a character.
  630. *
  631. * @param[in] id The character ID.
  632. * @param[in] level The limit level.
  633. * @param[in] tech The technique position in the level.
  634. * @return True if the technique has been learned, false if not. If an invalid id, limit
  635. * level or technique is passed, 0.
  636. */
  637. bool IsCharacterLimitLearned(
  638. const unsigned int id, const unsigned int level, const unsigned int tech
  639. );
  640. /**
  641. * Retrieves the ID of an equipped materia.
  642. *
  643. * @param[in] id The character ID.
  644. * @param[in] weapon If false, check materia equipped in the weapon. If false, check
  645. * materia equiped in the armor.
  646. * @param[in] pos Position in the equipment slots.
  647. * @return The ID of the equipped materia. Id or position is passed, or if there is no
  648. * materia at the requested position, -1.
  649. */
  650. int GetCharacterMateriaId(const unsigned int id, const bool weapon, const unsigned int pos);
  651. /**
  652. * Retrieves the AP of an equipped materia.
  653. *
  654. * @param[in] id The character ID.
  655. * @param[in] weapon If false, check materia equipped in the weapon. If false, check
  656. * materia equiped in the armor.
  657. * @param[in] pos Position in the equipment slots.
  658. * @return The AP of the equipped materia. If an invalid id or position is passed, or if
  659. * there is no materia at the requested position, 0.
  660. */
  661. unsigned int GetCharacterMateriaAp(
  662. const unsigned int id, const bool weapon, const unsigned int pos
  663. );
  664. /**
  665. * Checks if an equipped materia is Enemy Skill.
  666. *
  667. * @param[in] id The character ID.
  668. * @param[in] weapon If false, check materia equipped in the weapon. If false, check
  669. * materia equiped in the armor.
  670. * @param[in] pos Position in the equipment slots.
  671. * @return True if the materia in the specified position is an Enemy Skill materia, false
  672. * if not. If an invalid position is passed, or if there is no materia at that position,
  673. * false.
  674. */
  675. bool IsCharacterMateriaESkill(const unsigned int id, const bool weapon, const unsigned int pos);
  676. /**
  677. * Checks if a a enemy skill is learned by a equipped materia.
  678. *
  679. * @param[in] id The character ID.
  680. * @param[in] weapon If false, check materia equipped in the weapon. If false, check
  681. * materia equiped in the armor.
  682. * @param[in] pos Position in the equipment slots.
  683. * @param[in] skill Skill ID, starting from 0.
  684. * @return True if the materia in the specified position exists, is an Enemy Skill materia
  685. * and has learned the specified skill. False in any other case.
  686. */
  687. bool IsCharacterMateriaESkillLearned(
  688. const unsigned int id, const bool weapon, const unsigned int pos, const unsigned int skill
  689. );
  690. /**
  691. * Retrieves the value of a bank address.
  692. *
  693. * @param[in] bank The bank ID.
  694. * @param[in] address The address in the bank.
  695. * @return The value. If an invalid bank or address level is passed, 0.
  696. */
  697. int GetData(const unsigned int bank, const unsigned int address);
  698. /**
  699. * Character basic stats.
  700. */
  701. class STAT{
  702. public:
  703. /**
  704. * Strength stat.
  705. */
  706. static constexpr unsigned int STR = 0;
  707. /**
  708. * Vtatlity stat.
  709. */
  710. static constexpr unsigned int VIT = 1;
  711. /**
  712. * Magic stat.
  713. */
  714. static constexpr unsigned int MAG = 2;
  715. /**
  716. * Spirit stat.
  717. */
  718. static constexpr unsigned int SPR = 3;
  719. /**
  720. * Dexterity stat.
  721. */
  722. static constexpr unsigned int DEX = 4;
  723. /**
  724. * Luck stat.
  725. */
  726. static constexpr unsigned int LCK = 5;
  727. /**
  728. * HP stat.
  729. */
  730. static constexpr unsigned int HP = 6;
  731. /**
  732. * MP stat.
  733. */
  734. static constexpr unsigned int MP = 7;
  735. };
  736. /**
  737. * Window corners.
  738. */
  739. class CORNER{
  740. public:
  741. /**
  742. * Top left window corner.
  743. */
  744. static constexpr unsigned int T_L = 0;
  745. /**
  746. * Top right window corner.
  747. */
  748. static constexpr unsigned int T_R = 1;
  749. /**
  750. * Bottom right window corner.
  751. */
  752. static constexpr unsigned int B_R = 2;
  753. /**
  754. * Bottom left window corner.
  755. */
  756. static constexpr unsigned int B_L = 3;
  757. };
  758. /**
  759. * Colour codes
  760. */
  761. class COLOUR{
  762. public:
  763. /**
  764. * Red colour.
  765. */
  766. static constexpr unsigned int R = 0;
  767. /**
  768. * Green colour.
  769. */
  770. static constexpr unsigned int G = 1;
  771. /**
  772. * Blue colour.
  773. */
  774. static constexpr unsigned int B = 2;
  775. };
  776. private:
  777. /**
  778. * Maximum number of characters.
  779. */
  780. static constexpr unsigned int MAX_CHARACTERS = 11;
  781. /**
  782. * Maximum number of inventory slots.
  783. */
  784. static constexpr unsigned int MAX_ITEM_SLOTS = 500;
  785. /**
  786. * Maximum number of inventory slots for key items.
  787. */
  788. static constexpr unsigned int MAX_KEY_ITEM_SLOTS = 100;
  789. /**
  790. * Maximum number of materia slots.
  791. */
  792. static constexpr unsigned int MAX_MATERIA_SLOTS = 500;
  793. /**
  794. * Maximum number of materia slots in the stash.
  795. */
  796. static constexpr unsigned int MAX_STASH_SLOTS = 500;
  797. /**
  798. * Maximum number of materia slots in a weapon or armor.
  799. */
  800. static constexpr unsigned int MAX_EQUIP_SLOTS = 10;
  801. /**
  802. * Maximum number of skills in an Enemy Skill materia.
  803. */
  804. static constexpr unsigned int MAX_ENEMY_SKILLS = 32;
  805. /**
  806. * Maximum limit level.
  807. */
  808. static constexpr unsigned int MAX_LIMIT_LEVELS = 4;
  809. /**
  810. * Maximum limit techniques per level.
  811. */
  812. static constexpr unsigned int MAX_LIMIT_TECHNIQUES = 4;
  813. /**
  814. * Level at which the limit level is full.
  815. */
  816. static constexpr unsigned int MAX_LIMIT_BAR = 254;
  817. /**
  818. * Maximum number of party member.
  819. */
  820. static constexpr unsigned int MAX_PARTY_MEMBERS = 3;
  821. /**
  822. * Number of data banks.
  823. */
  824. static constexpr unsigned int BANK_COUNT = 16;
  825. /**
  826. * Number of addresses in each data bank.
  827. */
  828. static constexpr unsigned int BANK_ADDRESS_COUNT = 256;
  829. /**
  830. * Max colour component value (they are stored in a byte).
  831. */
  832. static constexpr unsigned int MAX_COLOUR = 255;
  833. /**
  834. * Location information.
  835. *
  836. * Used for fields and world map.
  837. */
  838. struct Location{
  839. /**
  840. * X coordinate.
  841. */
  842. float x;
  843. /**
  844. * Y coordinate.
  845. */
  846. float y;
  847. /**
  848. * Z coordinate.
  849. *
  850. * Usually unused.
  851. */
  852. float z;
  853. /**
  854. * Triangle in the walkmesh;
  855. */
  856. unsigned int triangle;
  857. /**
  858. * Facing direction.
  859. */
  860. unsigned int angle;
  861. /**
  862. * Current field map.
  863. *
  864. * If null or empty, it means the player is in in the world map.
  865. */
  866. std::string field;
  867. /**
  868. * Location name. Used for the saveslot.
  869. */
  870. std::string name;
  871. };
  872. /**
  873. * A materia structure.
  874. */
  875. struct Materia{
  876. /**
  877. * Materia ID.
  878. */
  879. int id;
  880. /**
  881. * Total AP in the materia.
  882. */
  883. unsigned int ap;
  884. /**
  885. * Indicates if the materia is an enemy skill materia.
  886. */
  887. bool enemy_skill;
  888. /**
  889. * Learned enemy skills (only for Enemy Skill materia).
  890. */
  891. bool enemy_skill_learned[MAX_ENEMY_SKILLS];
  892. };
  893. /**
  894. * Item structure.
  895. */
  896. struct Item{
  897. /**
  898. * Item ID.
  899. */
  900. int id;
  901. /**
  902. * Item stock.
  903. */
  904. unsigned int quantity;
  905. };
  906. /**
  907. * A character entri in the savemap.
  908. */
  909. struct Character{
  910. /**
  911. * A character stat.
  912. */
  913. struct Stat{
  914. /**
  915. * Stat base value.
  916. */
  917. unsigned int base;
  918. /**
  919. * For STR, VIT, DEX and LCK, it means the source bonus. For HP and MP, it means
  920. * the current values.
  921. */
  922. unsigned int extra;
  923. };
  924. /**
  925. * A weapon or armor.
  926. */
  927. struct Equipment{
  928. /**
  929. * Item ID of the weapon or armor.
  930. */
  931. u16 id;
  932. /**
  933. * Materia in the weapon/armor.
  934. */
  935. Materia materia[MAX_EQUIP_SLOTS];
  936. };
  937. /**
  938. * Character ID, sequential.
  939. */
  940. unsigned int id;
  941. /**
  942. * Character ID, can change with the history. -1 to not use.
  943. */
  944. int char_id;
  945. /**
  946. * Indicates if the character has been unlocked for the PHS.
  947. */
  948. bool enabled;
  949. /**
  950. * Indicates if the character is locked in or out of the PHS.
  951. */
  952. bool locked;
  953. /**
  954. * Character name.
  955. */
  956. std::string name;
  957. /**
  958. * Character level.
  959. */
  960. unsigned int level;
  961. /**
  962. * Enemies killed by the character.
  963. */
  964. unsigned int kills;
  965. /**
  966. * Indicates if the character is in the back_row;
  967. */
  968. bool back_row;
  969. /**
  970. * Total experience.
  971. */
  972. unsigned int exp;
  973. /**
  974. * Experience required to reach next level.
  975. */
  976. unsigned int exp_to_next;
  977. /**
  978. * STR stat.
  979. */
  980. Stat str;
  981. /**
  982. * VIT stat.
  983. */
  984. Stat vit;
  985. /**
  986. * MAG stat.
  987. */
  988. Stat mag;
  989. /**
  990. * SPR stat.
  991. */
  992. Stat spr;
  993. /**
  994. * DEX stat.
  995. */
  996. Stat dex;
  997. /**
  998. * LCK stat.
  999. */
  1000. Stat lck;
  1001. /**
  1002. * HP stat.
  1003. */
  1004. Stat hp;
  1005. /**
  1006. * MP stat.
  1007. */
  1008. Stat mp;
  1009. /**
  1010. * Current limit level.
  1011. */
  1012. unsigned int limit_level;
  1013. /**
  1014. * Current limit bar.
  1015. */
  1016. unsigned int limit_bar;
  1017. /**
  1018. * Learned limits.
  1019. *
  1020. * Grouped by level and technique.
  1021. */
  1022. bool limits_learned[MAX_LIMIT_LEVELS][MAX_LIMIT_TECHNIQUES];
  1023. /**
  1024. * Uses of techniques in each limit level.
  1025. */
  1026. unsigned int limit_uses[MAX_LIMIT_LEVELS];
  1027. /**
  1028. * Equipped weapon;
  1029. */
  1030. Equipment weapon;
  1031. /**
  1032. * Equipped weapon;
  1033. */
  1034. Equipment armor;
  1035. /**
  1036. * Equipped accessory ID. -1 if none equipped.
  1037. */
  1038. int accessory;
  1039. /**
  1040. * Current status list.
  1041. */
  1042. std::vector<u8> status;
  1043. };
  1044. /**
  1045. * Indicates if the savemap is empty or contains actual data.
  1046. */
  1047. bool empty_;
  1048. /**
  1049. * The slot the savemap is saved at, or -1 if not saved
  1050. */
  1051. int slot_;
  1052. /**
  1053. * Control string.
  1054. *
  1055. * Not a checksum, it does not depend on the actual data. It never mutates, is used to
  1056. * differenciate savemaps when asking to override.
  1057. */
  1058. std::string control_;
  1059. /**
  1060. * Window colours.
  1061. */
  1062. u8 window_colours_[4][3];
  1063. /**
  1064. * List of characters.
  1065. */
  1066. Character characters_[MAX_CHARACTERS];
  1067. /**
  1068. * IDs of characters in the party.
  1069. */
  1070. int party_[MAX_PARTY_MEMBERS];
  1071. /**
  1072. * Owned items.
  1073. */
  1074. Item items_[MAX_ITEM_SLOTS];
  1075. /**
  1076. * Owned key items.
  1077. */
  1078. bool key_items_[MAX_KEY_ITEM_SLOTS];
  1079. /**
  1080. * Owned materia.
  1081. */
  1082. Materia materia_[MAX_MATERIA_SLOTS];
  1083. /**
  1084. * Alternative materia stash.
  1085. *
  1086. * Used for the Yuffie materia event.
  1087. */
  1088. Materia materia_stash_[MAX_STASH_SLOTS];
  1089. /**
  1090. * Current party money.
  1091. */
  1092. unsigned int money_;
  1093. /**
  1094. * Seconds played
  1095. */
  1096. unsigned int seconds_;
  1097. /**
  1098. * Current countdown remaining seconds.
  1099. */
  1100. unsigned int countdown_;
  1101. /**
  1102. * Current location.
  1103. */
  1104. Location location_;
  1105. /**
  1106. * Settings of the game (config menu), by name. The scripts decide which ones there are.
  1107. */
  1108. std::map<std::string, int> settings_;
  1109. /**
  1110. * Memory banks.
  1111. */
  1112. int data_[BANK_COUNT][BANK_ADDRESS_COUNT];
  1113. };