update.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 update.c
  19. *
  20. * Implementation of the update command.
  21. *
  22. * This file implements the update command declared in {@link update.h}.
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "../runeoptimizer.h"
  27. #include "../error/error.h"
  28. #include "update.h"
  29. const int MAIN_STATS_VALUES[DIFFERENT_STATS][RUNE_MAX_STARS + 1][2] = {
  30. { //NULL (unused)
  31. {0, 0},
  32. {0, 0},
  33. {0, 0},
  34. {0, 0},
  35. {0, 0},
  36. {0, 0}
  37. },
  38. { //HP_FLAT
  39. {0, 0}, // 0 stars (unused)
  40. {580, 804}, // 1 stars
  41. {790, 1092}, // 2 stars
  42. {1000, 1380}, // 3 stars
  43. {1240, 1704}, // 4 stars
  44. {1530, 2088}, // 5 stars
  45. {1800, 2448} // 6 stars
  46. },
  47. { //HP_PERCENT
  48. {0, 0}, // 0 stars (unused)
  49. {13, 18}, // 1 stars
  50. {14, 19}, // 2 stars
  51. {28, 38}, // 3 stars
  52. {31, 43}, // 4 stars
  53. {37, 51}, // 5 stars
  54. {47, 63} // 6 stars
  55. },
  56. { //ATK_FLAT
  57. {0, 0}, // 0 stars (unused)
  58. {39, 54}, // 1 stars
  59. {53, 73}, // 2 stars
  60. {67, 92}, // 3 stars
  61. {82, 112}, // 4 stars
  62. {99, 135}, // 5 stars
  63. {118, 160}, // 6 stars
  64. },
  65. { //ATK_PERCENT
  66. {0, 0}, // 0 stars (unused)
  67. {13, 18}, // 1 stars
  68. {14, 19}, // 2 stars
  69. {28, 38}, // 3 stars
  70. {31, 43}, // 4 stars
  71. {37, 51}, // 5 stars
  72. {47, 63} // 6 stars
  73. },
  74. { //DEF_FLAT
  75. {0, 0}, // 0 stars (unused)
  76. {39, 54}, // 1 stars
  77. {53, 73}, // 2 stars
  78. {67, 92}, // 3 stars
  79. {82, 112}, // 4 stars
  80. {99, 135}, // 5 stars
  81. {118, 160}, // 6 stars
  82. },
  83. { //DEF_PERCENT
  84. {0, 0}, // 0 stars (unused)
  85. {13, 18}, // 1 stars
  86. {14, 19}, // 2 stars
  87. {28, 38}, // 3 stars
  88. {31, 43}, // 4 stars
  89. {37, 51}, // 5 stars
  90. {47, 63} // 6 stars
  91. },
  92. { //NULL (unused)
  93. {0, 0},
  94. {0, 0},
  95. {0, 0},
  96. {0, 0},
  97. {0, 0},
  98. {0, 0}
  99. },
  100. { //SPD
  101. {0, 0}, // 0 stars (unused)
  102. {13, 18}, // 1 stars
  103. {14, 19}, // 2 stars
  104. {18, 25}, // 3 stars
  105. {22, 30}, // 4 stars
  106. {29, 39}, // 5 stars
  107. {31, 42} // 6 stars
  108. },
  109. { //CRR
  110. {0, 0}, // 0 stars (unused)
  111. {13, 18}, // 1 stars
  112. {14, 19}, // 2 stars
  113. {27, 37}, // 3 stars
  114. {30, 41}, // 4 stars
  115. {34, 47}, // 5 stars
  116. {43, 58} // 6 stars
  117. },
  118. { //CRD
  119. {0, 0}, // 0 stars (unused)
  120. {14, 19}, // 1 stars
  121. {27, 37}, // 2 stars
  122. {32, 43}, // 3 stars
  123. {42, 57}, // 4 stars
  124. {48, 65}, // 5 stars
  125. {59, 80} // 6 stars
  126. },
  127. { //RES
  128. {0, 0}, // 0 stars (unused)
  129. {13, 18}, // 1 stars
  130. {14, 19}, // 2 stars
  131. {28, 38}, // 3 stars
  132. {32, 44}, // 4 stars
  133. {38, 51}, // 5 stars
  134. {48, 64} // 6 stars
  135. },
  136. { //ACC
  137. {0, 0}, // 0 stars (unused)
  138. {13, 18}, // 1 stars
  139. {14, 19}, // 2 stars
  140. {28, 38}, // 3 stars
  141. {32, 44}, // 4 stars
  142. {38, 51}, // 5 stars
  143. {48, 64} // 6 stars
  144. }
  145. };
  146. extern int update(int argc, char *argv[]){
  147. // Options
  148. unsigned char six_stars = FALSE;
  149. unsigned char with_runes = FALSE;
  150. unsigned char clear_teams = FALSE;
  151. unsigned char gui = FALSE;
  152. // One argument mandatory
  153. if (argc == 0){
  154. fprintf(
  155. stderr,
  156. "update command takes 1 or more arguments, %d supplied\n", argc - 3
  157. );
  158. return ERROR_INPUT_UPDATE_NO_ARGUMENTS;
  159. }
  160. // Parse options, skip first arg
  161. for (int i = 1; i < argc; i ++){
  162. if (strcmp("--six-stars", argv[i]) == 0 || strcmp("-s", argv[i]) == 0){
  163. six_stars = TRUE;
  164. }
  165. else if (
  166. strcmp("--with-runes", argv[i]) == 0 || strcmp("-r", argv[i]) == 0
  167. ){
  168. with_runes = TRUE;
  169. }
  170. else if (
  171. strcmp("--clear-teams", argv[i]) == 0 || strcmp("-t", argv[i]) == 0
  172. ){
  173. clear_teams = TRUE;
  174. }
  175. else if (
  176. strcmp("--gui", argv[i]) == 0 || strcmp("-g", argv[i]) == 0
  177. ){
  178. gui = TRUE;
  179. }
  180. }
  181. // First, test json
  182. if (strlen(argv[0]) > 5){
  183. char extension[6];
  184. strncpy(extension, argv[0] + strlen(argv[0]) - 5, 5);
  185. extension[5] = '\0';
  186. if (strcmp(extension, ".json") == 0){
  187. return update_json(
  188. argv[0], six_stars, with_runes, clear_teams, gui
  189. );
  190. }
  191. }
  192. // TODO: More ifs as more options are implemented...
  193. fprintf(stderr, "Unknwon source supplied: %s\n", argv[0]);
  194. return ERROR_INPUT_UPDATE_UNKNOWN_SOURCE;
  195. }