runeoptimizer.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. /*
  2. * This file is part of RuneOptimizer.
  3. *
  4. * RuneOptimizer is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation, either version 3 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * @file runeoptimizer.h
  19. *
  20. * Declarations of the functions and data types used across the application.
  21. *
  22. * This file declares all the functions and data types used from anywhere in the
  23. * program.
  24. */
  25. #pragma once
  26. #include <sqlite3.h>
  27. /**
  28. * Application version.
  29. *
  30. * Metadata, only used in the help and version commands.
  31. */
  32. #define VERSION "0.1-RC1"
  33. /**
  34. * Application author.
  35. *
  36. * Metadata, only used in the help command.
  37. */
  38. #define AUTHOR "Iñigo Valentin"
  39. /**
  40. * Application author email.
  41. *
  42. * Metadata, only used in the help command.
  43. */
  44. #define MAIL "i@inigovalentin.com"
  45. /**
  46. * Boolean value TRUE.
  47. *
  48. * Mocked boolean for consistence across functions.
  49. */
  50. #define TRUE 1
  51. /**
  52. * Boolean value FALSE.
  53. *
  54. * Mocked boolean for consistence across functions.
  55. */
  56. #define FALSE 0
  57. /**
  58. * Energy Set.
  59. *
  60. * Set ID of Energy runes, as given by Com2Us.
  61. */
  62. #define ENERGY 1
  63. /**
  64. * Guard Set.
  65. *
  66. * Set ID of Guard runes, as given by Com2Us.
  67. */
  68. #define GUARD 2
  69. /**
  70. * Swift Set.
  71. *
  72. * Set ID of Swift runes, as given by Com2Us.
  73. */
  74. #define SWIFT 3
  75. /**
  76. * Blade Set.
  77. *
  78. * Set ID of Blade runes, as given by Com2Us.
  79. */
  80. #define BLADE 4
  81. /**
  82. * Rage Set.
  83. *
  84. * Set ID of Rage runes, as given by Com2Us.
  85. */
  86. #define RAGE 5
  87. /**
  88. * Focus Set.
  89. *
  90. * Set ID of Focus runes, as given by Com2Us.
  91. */
  92. #define FOCUS 6
  93. /**
  94. * Endure Set.
  95. *
  96. * Set ID of Endure runes, as given by Com2Us.
  97. */
  98. #define ENDURE 7
  99. /**
  100. * Fatal Set.
  101. *
  102. * Set ID of Fatal runes, as given by Com2Us.
  103. */
  104. #define FATAL 8
  105. /**
  106. * Despair Set.
  107. *
  108. * Set ID of Despair runes, as given by Com2Us.
  109. */
  110. #define DESPAIR 10
  111. /**
  112. * Vampire Set.
  113. *
  114. * Set ID of Vampire runes, as given by Com2Us.
  115. */
  116. #define VAMPIRE 11
  117. /**
  118. * Violent Set.
  119. *
  120. * Set ID of Violent runes, as given by Com2Us.
  121. */
  122. #define VIOLENT 13
  123. /**
  124. * Nemesis Set.
  125. *
  126. * Set ID of Nemesis runes, as given by Com2Us.
  127. */
  128. #define NEMESIS 14
  129. /**
  130. * Will Set.
  131. *
  132. * Set ID of Will runes, as given by Com2Us.
  133. */
  134. #define WILL 15
  135. /**
  136. * Shield Set.
  137. *
  138. * Set ID of Shield runes, as given by Com2Us.
  139. */
  140. #define SHIELD 16
  141. /**
  142. * Revenge Set.
  143. *
  144. * Set ID of Revenge runes, as given by Com2Us.
  145. */
  146. #define REVENGE 17
  147. /**
  148. * Destroy Set.
  149. *
  150. * Set ID of Destroy runes, as given by Com2Us.
  151. */
  152. #define DESTROY 18
  153. /**
  154. * Fight Set.
  155. *
  156. * Set ID of Fight runes, as given by Com2Us.
  157. */
  158. #define FIGHT 19
  159. /**
  160. * Determination Set.
  161. *
  162. * Set ID of Determination runes, as given by Com2Us.
  163. */
  164. #define DETERMINATION 20
  165. /**
  166. * Enhance Set.
  167. *
  168. * Set ID of Enhance runes, as given by Com2Us.
  169. */
  170. #define ENHANCE 21
  171. /**
  172. * Accuracy Set.
  173. *
  174. * Set ID of Accuracy runes, as given by Com2Us.
  175. */
  176. #define ACCURACY 22
  177. /**
  178. * Tolerance Set.
  179. *
  180. * Set ID of Tolerance runes, as given by Com2Us.
  181. */
  182. #define TOLERANCE 23
  183. /**
  184. * HP rune stat.
  185. *
  186. * Rune stat ID for HP in runes, as given by Com2Us.
  187. */
  188. #define HP_FLAT 1
  189. /**
  190. * HP% rune stat.
  191. *
  192. * Rune stat ID for HP% in runes, as given by Com2Us.
  193. */
  194. #define HP_PERCENT 2
  195. /**
  196. * ATK rune stat.
  197. *
  198. * Rune stat ID for ATK in runes, as given by Com2Us.
  199. */
  200. #define ATK_FLAT 3
  201. /**
  202. * ATK% rune stat.
  203. *
  204. * Rune stat ID for ATK% in runes, as given by Com2Us.
  205. */
  206. #define ATK_PERCENT 4
  207. /**
  208. * DEF rune stat.
  209. *
  210. * Rune stat ID for DEF in runes, as given by Com2Us.
  211. */
  212. #define DEF_FLAT 5
  213. /**
  214. * DEF% rune stat.
  215. *
  216. * Rune stat ID for DEF% in runes, as given by Com2Us.
  217. */
  218. #define DEF_PERCENT 6
  219. /**
  220. * SPD rune stat.
  221. *
  222. * Rune stat ID for SPD in runes, as given by Com2Us.
  223. */
  224. #define SPD 8
  225. /**
  226. * CRR rune stat.
  227. *
  228. * Rune stat ID for CRR in runes, as given by Com2Us.
  229. */
  230. #define CRR 9
  231. /**
  232. * CRD rune stat.
  233. *
  234. * Rune stat ID for CRD in runes, as given by Com2Us.
  235. */
  236. #define CRD 10
  237. /**
  238. * RES rune stat.
  239. *
  240. * Rune stat ID for RES in runes, as given by Com2Us.
  241. */
  242. #define RES 11
  243. /**
  244. * ACC rune stat.
  245. *
  246. * Rune stat ID for ACC in runes, as given by Com2Us.
  247. */
  248. #define ACC 12
  249. /**
  250. * Maximum length of Unit IDs.
  251. *
  252. * It can never be higher thahn this.
  253. */
  254. #define UNIT_ID_LEN 14
  255. /**
  256. * Maximum length of Unit name.
  257. *
  258. * It can never be higher thahn this.
  259. */
  260. #define UNIT_NAME_LEN 128
  261. /**
  262. * Maximum length of Rune IDs.
  263. *
  264. * It can never be higher thahn this.
  265. */
  266. #define RUNE_ID_LEN 14
  267. /**
  268. * Maximum length of Teams IDs.
  269. *
  270. * It can never be higher thahn this.
  271. */
  272. #define TEAM_ID_LEN 4
  273. /**
  274. * Length for the database file path.
  275. *
  276. * Totally arbitrary.
  277. * @todo This may be worriesome.
  278. */
  279. #define DB_PATH_LEN 512
  280. /**
  281. * Rune slots.
  282. *
  283. * Number of rune slots. In-game, and in many parts of this program, slots are
  284. * used with a 1-index.
  285. */
  286. #define RUNE_SLOTS 6
  287. /**
  288. * CRR Cap.
  289. *
  290. * Critical rate does nothing over 100%, so for more realistic calcultations,
  291. * it's better to have it capped.
  292. */
  293. #define CRR_CAP 100.0f
  294. /**
  295. * RES Cap.
  296. *
  297. * Resistance does nothing over 100%, so for more realistic calcultations, it's
  298. * better to have it capped.
  299. */
  300. #define RES_CAP 100.0f
  301. /**
  302. * ACC Cap.
  303. *
  304. * In the game, accurary is effectively capped at 85%, so for more realistic
  305. * calcultations, it's better to have it capped.
  306. */
  307. #define ACC_CAP 85.0f
  308. /**
  309. * Number of stats defined in the game.
  310. *
  311. * It's not actually 13, because 0 and 7 are never used in game, but is a good
  312. * value for counters and loops.
  313. */
  314. #define DIFFERENT_STATS 13
  315. /**
  316. * Number of rune sets defined in the game.
  317. *
  318. * It's not actually 25, because 0, 9 and 12 are never used in game, but is a
  319. * good value for counters and loops.
  320. */
  321. #define DIFFERENT_SETS 25
  322. /**
  323. * Number of rune sets defined in the game.
  324. *
  325. * It's not actually 26, because a lot of them are never used in game, but is a
  326. * good value for counters and loops.
  327. */
  328. #define DIFFERENT_QUALITIES 16
  329. /**
  330. * Rune max stars.
  331. *
  332. * Watch out, a rune can't have 0 stars, so in loos, better start at 1.
  333. */
  334. #define RUNE_MAX_STARS 6
  335. /**
  336. * Structure representing a unit.
  337. *
  338. * Represents an entity from the table 'unit', but is doesn't have that mucha
  339. * data, just the mambers needed for optimization and some other thigs. For a
  340. * more complete representation of the table, {@link DB_Unit} can be used.
  341. */
  342. typedef struct Unit {
  343. /**
  344. * Unit ID.
  345. *
  346. * The ID as given by Com2Us.
  347. */
  348. unsigned char id[UNIT_ID_LEN];
  349. /**
  350. * The Unit name.
  351. *
  352. * The name as given by Com2Us, except for Homunculus. For them, the user
  353. * given by the naem will be used.
  354. */
  355. unsigned char name[UNIT_NAME_LEN];
  356. /**
  357. * The unit base HP.
  358. *
  359. * The Unit HP, at it's current level, without counting runes, artifacts,
  360. * towers...
  361. */
  362. unsigned int base_hp;
  363. /**
  364. * The unit base ATK.
  365. *
  366. * The Unit ATK, at it's current level, without counting runes, artifacts,
  367. * towers...
  368. */
  369. unsigned short base_atk;
  370. /**
  371. * The unit base DEF.
  372. *
  373. * The Unit DEF, at it's current level, without counting runes, artifacts,
  374. * towers...
  375. */
  376. unsigned short base_def;
  377. /**
  378. * The unit base SPD.
  379. *
  380. * The Unit SPD, at it's current level, without counting runes, artifacts,
  381. * towers...
  382. */
  383. unsigned short base_spd;
  384. /**
  385. * The unit base CRR.
  386. *
  387. * The Unit CRR, at it's current level, without counting runes, artifacts,
  388. * towers...
  389. */
  390. unsigned short base_crr;
  391. /**
  392. * The unit base CRD.
  393. *
  394. * The Unit CRD, at it's current level, without counting runes, artifacts,
  395. * towers...
  396. */
  397. unsigned short base_crd;
  398. /**
  399. * The unit base RES.
  400. *
  401. * The Unit RES, at it's current level, without counting runes, artifacts,
  402. * towers...
  403. */
  404. unsigned short base_res;
  405. /**
  406. * The unit base ACC.
  407. *
  408. * The Unit ACC, at it's current level, without counting runes, artifacts,
  409. * towers...
  410. */
  411. unsigned short base_acc;
  412. /**
  413. * The unit base EHP.
  414. *
  415. * The Unit EHP, at it's current level, without counting runes, artifacts,
  416. * towers... See {@link calculate_ehp} for more details bout EHP.
  417. */
  418. unsigned int base_ehp;
  419. /**
  420. * The unit base DMG.
  421. *
  422. * The Unit DMG, at it's current level, without counting runes, artifacts,
  423. * towers...See {@link calculate_ehp} for more details bout EHP.
  424. */
  425. unsigned short base_dmg;
  426. /**
  427. * The unit base HP.
  428. *
  429. * The Unit HP, at it's current level, counting equiped runes, but not
  430. * artifacts or towers.
  431. */
  432. unsigned int current_hp;
  433. /**
  434. * The unit base ATK.
  435. *
  436. * The Unit ATK, at it's current level, counting equiped runes, but not
  437. * artifacts or towers.
  438. */
  439. unsigned short current_atk;
  440. /**
  441. * The unit base DEF.
  442. *
  443. * The Unit DEF, at it's current level, counting equiped runes, but not
  444. * artifacts or towers.
  445. */
  446. unsigned short current_def;
  447. /**
  448. * The unit base SPD.
  449. *
  450. * The Unit SPD, at it's current level, counting equiped runes, but not
  451. * artifacts or towers.
  452. */
  453. unsigned short current_spd;
  454. /**
  455. * The unit base CRR.
  456. *
  457. * The Unit CRR, at it's current level, counting equiped runes, but not
  458. * artifacts or towers.
  459. */
  460. unsigned short current_crr;
  461. /**
  462. * The unit base CRD.
  463. *
  464. * The Unit CRD, at it's current level, counting equiped runes, but not
  465. * artifacts or towers.
  466. */
  467. unsigned short current_crd;
  468. /**
  469. * The unit base RES.
  470. *
  471. * The Unit RES, at it's current level, counting equiped runes, but not
  472. * artifacts or towers.
  473. */
  474. unsigned short current_res;
  475. /**
  476. * The unit base ACC.
  477. *
  478. * The Unit ACC, at it's current level, counting equiped runes, but not
  479. * artifacts or towers.
  480. */
  481. unsigned short current_acc;
  482. /**
  483. * The unit base EHP.
  484. *
  485. * The Unit EHP, at it's current level, counting equiped runes, but not
  486. * artifacts or towers.See {@link calculate_ehp} for more details bout EHP.
  487. */
  488. unsigned int current_ehp;
  489. /**
  490. * The unit base DMG.
  491. *
  492. * The Unit DMG, at it's current level, counting equiped runes, but not
  493. * artifacts or towers. See {@link calculate_ehp} for more details bout EHP.
  494. */
  495. unsigned short current_dmg;
  496. } Unit;
  497. /**
  498. * Number of runes for a given list of runes.
  499. *
  500. * It just holds numbers of rune sets. See {@link optimize_count_runes_for_sets}
  501. * for a use case.
  502. */
  503. typedef struct Rune_Set_Count {
  504. /**
  505. * Energy count.
  506. *
  507. * Number of Energy runes.
  508. */
  509. unsigned short energy;
  510. /**
  511. * Guard count.
  512. *
  513. * Number of Guard runes.
  514. */
  515. unsigned short guard;
  516. /**
  517. * Swift count.
  518. *
  519. * Number of Swift runes.
  520. */
  521. unsigned short swift;
  522. /**
  523. * Blade count.
  524. *
  525. * Number of Blade runes.
  526. */
  527. unsigned short blade;
  528. /**
  529. * Rage count.
  530. *
  531. * Number of Rage runes.
  532. */
  533. unsigned short rage;
  534. /**
  535. * Focus count.
  536. *
  537. * Number of Focus runes.
  538. */
  539. unsigned short focus;
  540. /**
  541. * Endure count.
  542. *
  543. * Number of Endure runes.
  544. */
  545. unsigned short endure;
  546. /**
  547. * Fatal count.
  548. *
  549. * Number of Fatal runes.
  550. */
  551. unsigned short fatal;
  552. /**
  553. * Despair count.
  554. *
  555. * Number of Despair runes.
  556. */
  557. unsigned short despair;
  558. /**
  559. * Vampire count.
  560. *
  561. * Number of Vampire runes.
  562. */
  563. unsigned short vampire;
  564. /**
  565. * Violent count.
  566. *
  567. * Number of Violent runes.
  568. */
  569. unsigned short violent;
  570. /**
  571. * Nemesis count.
  572. *
  573. * Number of Nemesis runes.
  574. */
  575. unsigned short nemesis;
  576. /**
  577. * Will count.
  578. *
  579. * Number of Will runes.
  580. */
  581. unsigned short will;
  582. /**
  583. * Shield count.
  584. *
  585. * Number of Shield runes.
  586. */
  587. unsigned short shield;
  588. /**
  589. * Revenge count.
  590. *
  591. * Number of Revenge runes.
  592. */
  593. unsigned short revenge;
  594. /**
  595. * Destroy count.
  596. *
  597. * Number of Destroy runes.
  598. */
  599. unsigned short destroy;
  600. /**
  601. * Fight count.
  602. *
  603. * Number of Fight runes.
  604. */
  605. unsigned short fight;
  606. /**
  607. * Determination count.
  608. *
  609. * Number of Determination runes.
  610. */
  611. unsigned short determination;
  612. /**
  613. * Enhance count.
  614. *
  615. * Number of Enhance runes.
  616. */
  617. unsigned short enhance;
  618. /**
  619. * Accuracy count.
  620. *
  621. * Number of Accuracy runes.
  622. */
  623. unsigned short accuracy;
  624. /**
  625. * Tolerance count.
  626. *
  627. * Number of Tolerance runes.
  628. */
  629. unsigned short tolerance;
  630. } Rune_Set_Count;
  631. /**
  632. * Names for run stats.
  633. *
  634. * Indexed by Com2Us ID. Watch out for indexes 0 and 7, they are undefined in
  635. * the game.
  636. */
  637. extern const char STAT_NAMES[DIFFERENT_STATS][9];
  638. /**
  639. * Names for rune sets.
  640. *
  641. * Indexed by Com2Us ID.Watch out for indexes 0, 9 and 12, they are undefined in
  642. * the game.
  643. */
  644. extern const char SET_NAMES[DIFFERENT_SETS][9];
  645. /**
  646. * Names for rune qualities.
  647. *
  648. * Indexed by Com2Us ID. 1-5 are qualities for normal runes, 11-15 for ancient
  649. * runes. All the others are not defined in the game,
  650. */
  651. extern const char QUALITY_NAMES[DIFFERENT_QUALITIES][9];
  652. /**
  653. * Names for rune stats, in a printable format.
  654. *
  655. * They hold a 4 digit stat, padded to the right, with a percent sign on the
  656. * right for the stats that are percentual. All padded to the right with a
  657. * single space, for a total length of 10 characters.
  658. *
  659. * Indexed by Com2Us ID. Watch out for indexes 0 and 7, they are undefined in
  660. * the game.
  661. */
  662. extern const char STAT_NAMES_PRINTABLE[DIFFERENT_STATS][12];
  663. /**
  664. * Names for rune sets.
  665. *
  666. * Thy don't indicate if it's for a flat or a percentile stat.
  667. *
  668. * Indexed by Com2Us ID.Watch out for indexes 0, 9 and 12, they are undefined in
  669. * the game.
  670. */
  671. extern const char STAT_NAMES_UNSIGNED[DIFFERENT_STATS][4];
  672. /**
  673. * Max roll values for each stat.
  674. *
  675. * Used for efficiency calculations. Indexed by
  676. * - Stat id (indexes 0 and 7 undefined in game).
  677. * - Rune stars (1-6, dont use index 0).
  678. *
  679. * @todo For ancient runes, the initial rolls are higher.
  680. */
  681. extern const int STAT_ROLL_MAX[DIFFERENT_STATS][RUNE_MAX_STARS + 1];
  682. /**
  683. * Global database connection.
  684. *
  685. * Used across the app. Opened in {@link db_open}.
  686. */
  687. extern sqlite3 *db;
  688. /**
  689. * Path to the database.
  690. *
  691. * When possible, use be an absolute path.
  692. */
  693. extern char db_location[DB_PATH_LEN];
  694. /**
  695. * Calculates effective HP.
  696. *
  697. * EHP is a complex stat, depending on HP and DEF. In short, the formula is
  698. * ((( def * 3.5) + 1140) * hp) / 1000 .
  699. *
  700. * @param[in] hp HP stat.
  701. * @param[in] def DEF stat.
  702. * @return Calculated EHP.
  703. */
  704. extern unsigned int calculate_ehp(unsigned int hp, unsigned short def);
  705. /**
  706. * Calculates damage.
  707. *
  708. * DMG is a complex stat, depending on ATK, CRR and CRD. In short, the formula
  709. * is
  710. * (atk * ((100 - crr) / 100)) + (atk * (crr / 100) * ((100 + crd) / 100)) .
  711. *
  712. * @param[in] atk ATK stat.
  713. * @param[in] crr CRR stat.
  714. * @param[in] crd CRD stat.
  715. * @return Calculated DMG.
  716. */
  717. extern unsigned short calculate_dmg(
  718. unsigned short atk, unsigned short crr, unsigned short crd
  719. );
  720. /**
  721. * Starts the program.
  722. *
  723. * Reads command line parameters and runs the appropiate command.
  724. *
  725. * @param argc Number of arguments passed to the program.
  726. * @param argv Arguments passed to the program.
  727. * @return SUCCESS on success, other on error. Most errors are listed in
  728. * <a href="file:../error/error.h">../error/error.h</a>
  729. */
  730. int main(int argc, char *argv[]);