update_json.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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_json.c
  19. *
  20. * Implementation of {@link update_json}.
  21. *
  22. * This file implements the funciton {@link update_json} declared in
  23. * {@link update.h}. It also defines and implements some static functions used
  24. * by it.
  25. */
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <sqlite3.h>
  29. #include <json-c/json.h>
  30. #include "../runeoptimizer.h"
  31. #include "../error/error.h"
  32. #include "../db/db.h"
  33. #include "update.h"
  34. /**
  35. * Saves a single rune to the database obtaining data from its json object.
  36. *
  37. * Saves data to the tables 'runes' and 'rune_stats'. In case of error, a
  38. * description will be printed to stderr.
  39. *
  40. * @param[in] rune_json Rune json fragment.
  41. * @param[in] unit_id ID of the unit the rune is assigned to. To leave it
  42. * unassigned, pass an empty string, not NULL.
  43. * @return The number of stats saved to the database, including the main stat,
  44. * innate stat (if any), and all the normal stats. -1 in case of error.
  45. */
  46. static int update_json_rune(json_object *rune_json, unsigned char *unit_id);
  47. /**
  48. * Saves a single unit to the database obtaining data from its json object.
  49. *
  50. * Saves data to the tables 'units'. If the unit has any rune assigned, it will
  51. * also be saved to 'runes'. In case of error, a description will be printed to
  52. * stderr.
  53. *
  54. * @param[in] unit_json Unit json fragment.
  55. * @param[in] six_stars Indicator to import only 6* units. Units with runes will
  56. * be saved anyway.
  57. * @param[in] with_runes Indicator to import only units with runes.
  58. * @param[out] total_runes Cunter for runes. Will be increased for each saved
  59. * rune.
  60. * @param[out] total_stats Cunter for rune stats. Will be increased for each
  61. * stat on each saved rune.
  62. * @return 1 if the unit was saved to the database. 0 If everything was OK but
  63. * the unit was not saved because it did not match the criteria. -1 on error.
  64. */
  65. static int update_json_unit(
  66. json_object *unit_json, unsigned char six_stars,
  67. unsigned char with_runes, unsigned int *total_runes, unsigned int *total_stats
  68. );
  69. extern int update_json(
  70. char file[], unsigned char six_stars,
  71. unsigned char with_runes, unsigned char clear_teams, unsigned char gui
  72. ){
  73. // Counters for objcts saved
  74. unsigned int total_units = 0;
  75. unsigned int total_runes = 0;
  76. unsigned int total_stats = 0;
  77. if (gui == FALSE) printf("Updating from json file: %s\n", file);
  78. // Read the JSON content
  79. json_object *root = json_object_from_file(file);
  80. if (!root){
  81. fprintf(stderr, "Cant access file: %s\n", file);
  82. return(ERROR_INPUT_UPDATE_UNKNOWN_SOURCE);
  83. }
  84. json_object *wizard_id = json_object_object_get(root, "wizard_id");
  85. json_object *wizard_info = json_object_object_get(root, "wizard_info");
  86. json_object *wizard_name =
  87. json_object_object_get(wizard_info, "wizard_name");
  88. json_object *wizard_level =
  89. json_object_object_get(wizard_info, "wizard_level");
  90. printf("Player ID: %s\n", json_object_get_string(wizard_id));
  91. printf("Player name: %s\n", json_object_get_string(wizard_name));
  92. printf("Player level: %s\n", json_object_get_string(wizard_level));
  93. fflush(stdout); // To refresh GUI output.
  94. // Recreate the database tables
  95. int status = update_db_tables(clear_teams);
  96. if (SUCCESS != status) return(status);
  97. // Parse runes
  98. json_object *runes = json_object_object_get(root, "runes");
  99. int rune_count = json_object_array_length(runes);
  100. json_object *idx;
  101. for (int i = 0; i < rune_count; i++){
  102. total_runes ++;
  103. idx = json_object_array_get_idx(runes, i);
  104. status = update_json_rune(idx, (unsigned char *) "");
  105. if (status != -1) total_stats += status;
  106. }
  107. // Parse units
  108. json_object *unit_list = json_object_object_get(root, "unit_list");
  109. int unit_count = json_object_array_length(unit_list);
  110. for (int i = 0; i < unit_count; i++){
  111. idx = json_object_array_get_idx(unit_list, i);
  112. status = update_json_unit(
  113. idx, six_stars, with_runes, &total_runes, &total_stats
  114. );
  115. if (status == 1) total_units ++;
  116. }
  117. status = update_current_stats();
  118. if (SUCCESS != status) return(status);
  119. // Insert into table info
  120. status = update_info(
  121. json_object_get_string(wizard_id),
  122. json_object_get_string(wizard_name),
  123. json_object_get_string(wizard_level)
  124. );
  125. if (SUCCESS != status) return(status);
  126. // All parsed
  127. printf("%u units saved.\n", total_units);
  128. printf("%u runes saved.\n", total_runes);
  129. printf("%u rune stats saved.\n", total_stats);
  130. printf("Player info updated\n");
  131. return(SUCCESS);
  132. }
  133. static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
  134. int total_stats = 0;
  135. DB_Rune rune;
  136. char *query_parameters[43];
  137. for (int i = 1; i < 43; i ++) query_parameters[i] = malloc(35);
  138. // Rune ID
  139. json_object *rune_id = json_object_object_get(rune_json, "rune_id");
  140. strcpy((char *) rune.id, json_object_get_string(rune_id));
  141. // Rune unit
  142. strcpy((char *) rune.unit, (const char *) unit_id);
  143. // Rune slot
  144. json_object *slot_no = json_object_object_get(rune_json, "slot_no");
  145. rune.slot = json_object_get_int(slot_no);
  146. // Rune quality (extra)
  147. json_object *extra = json_object_object_get(rune_json, "extra");
  148. rune.quality = json_object_get_int(extra);
  149. // Rune stars (class)
  150. json_object *class = json_object_object_get(rune_json, "class");
  151. rune.stars = json_object_get_int(class);
  152. // Ancient runes have stars + 10.
  153. if (rune.stars > 10) rune.stars -= 10;
  154. // Rune set
  155. json_object *set_id = json_object_object_get(rune_json, "set_id");
  156. rune.set = json_object_get_int(set_id);
  157. // Rune level (upgrade_curr)
  158. json_object *upgrade_curr =
  159. json_object_object_get(rune_json, "upgrade_curr");
  160. rune.level = json_object_get_int(upgrade_curr);
  161. // Rune value
  162. json_object *base_value = json_object_object_get(rune_json, "base_value");
  163. rune.buy_value = json_object_get_int(base_value);
  164. // Rune sell value
  165. json_object *sell_value = json_object_object_get(rune_json, "sell_value");
  166. rune.sell_value = json_object_get_int(sell_value);
  167. // Main stat
  168. json_object *pri_eff = json_object_object_get(rune_json, "pri_eff");
  169. json_object *pri_stat = json_object_array_get_idx(pri_eff, 0);
  170. rune.main.stat = json_object_get_int(pri_stat);
  171. json_object *pri_value = json_object_array_get_idx(pri_eff, 1);
  172. rune.main.value = json_object_get_int(pri_value);
  173. // Innate stat
  174. json_object *prefix_eff = json_object_object_get(rune_json, "prefix_eff");
  175. json_object *prefix_stat = json_object_array_get_idx(prefix_eff, 0);
  176. rune.innate.stat = json_object_get_int(prefix_stat);
  177. json_object *prefix_value = json_object_array_get_idx(prefix_eff, 1);
  178. rune.innate.value = json_object_get_int(prefix_value);
  179. json_object *sec_eff = json_object_object_get(rune_json, "sec_eff");
  180. // Loop stats
  181. int stat_count = json_object_array_length(sec_eff);
  182. rune.stat_count = 0;
  183. for (int i = 0; i < stat_count && i < 4; i++){
  184. rune.stat_count ++;
  185. json_object *stat_json = json_object_array_get_idx(sec_eff, i);
  186. json_object *stat = json_object_array_get_idx(stat_json, 0);
  187. rune.stats[i].stat = json_object_get_int(stat);
  188. json_object *value = json_object_array_get_idx(stat_json, 1);
  189. rune.stats[i].value = json_object_get_int(value);
  190. json_object *enchant = json_object_array_get_idx(stat_json, 2);
  191. rune.stats[i].enchant = json_object_get_int(enchant);
  192. json_object *grind = json_object_array_get_idx(stat_json, 3);
  193. rune.stats[i].grind = json_object_get_int(grind);
  194. }
  195. // All the rune info has been loaded. Now, calculate the rest of stats
  196. update_rune_totals(&rune);
  197. // Insert the rune into the database
  198. query_parameters[0] = (char *) rune.id;
  199. query_parameters[1] = (char *) unit_id;
  200. sprintf(query_parameters[2], "%d", rune.set);
  201. sprintf(query_parameters[3], "%d", rune.slot);
  202. sprintf(query_parameters[4], "%d", rune.stars);
  203. sprintf(query_parameters[5], "%d", rune.level);
  204. sprintf(query_parameters[6], "%d", rune.quality);
  205. sprintf(query_parameters[7], "%f", rune.efficiency);
  206. sprintf(query_parameters[8], "%f", rune.max_efficiency);
  207. sprintf(query_parameters[9], "%d", rune.main.stat);
  208. sprintf(query_parameters[10], "%u", rune.current_hp_percent);
  209. sprintf(query_parameters[11], "%u", rune.current_atk_percent);
  210. sprintf(query_parameters[12], "%u", rune.current_def_percent);
  211. sprintf(query_parameters[13], "%u", rune.current_hp_flat);
  212. sprintf(query_parameters[14], "%u", rune.current_atk_flat);
  213. sprintf(query_parameters[15], "%u", rune.current_def_flat);
  214. sprintf(query_parameters[16], "%u", rune.current_spd);
  215. sprintf(query_parameters[17], "%u", rune.current_crr);
  216. sprintf(query_parameters[18], "%u", rune.current_crd);
  217. sprintf(query_parameters[19], "%u", rune.current_acc);
  218. sprintf(query_parameters[20], "%u", rune.current_res);
  219. sprintf(query_parameters[21], "%u", rune.lv12_hp_percent);
  220. sprintf(query_parameters[22], "%u", rune.lv12_atk_percent);
  221. sprintf(query_parameters[23], "%u", rune.lv12_def_percent);
  222. sprintf(query_parameters[24], "%u", rune.lv12_hp_flat);
  223. sprintf(query_parameters[25], "%u", rune.lv12_atk_flat);
  224. sprintf(query_parameters[26], "%u", rune.lv12_def_flat);
  225. sprintf(query_parameters[27], "%u", rune.lv12_spd);
  226. sprintf(query_parameters[28], "%u", rune.lv12_crr);
  227. sprintf(query_parameters[29], "%u", rune.lv12_crd);
  228. sprintf(query_parameters[30], "%u", rune.lv12_acc);
  229. sprintf(query_parameters[31], "%u", rune.lv12_res);
  230. sprintf(query_parameters[32], "%u", rune.lv15_hp_percent);
  231. sprintf(query_parameters[33], "%u", rune.lv15_atk_percent);
  232. sprintf(query_parameters[34], "%u", rune.lv15_def_percent);
  233. sprintf(query_parameters[35], "%u", rune.lv15_hp_flat);
  234. sprintf(query_parameters[36], "%u", rune.lv15_atk_flat);
  235. sprintf(query_parameters[37], "%u", rune.lv15_def_flat);
  236. sprintf(query_parameters[38], "%u", rune.lv15_spd);
  237. sprintf(query_parameters[39], "%u", rune.lv15_crr);
  238. sprintf(query_parameters[40], "%u", rune.lv15_crd);
  239. sprintf(query_parameters[41], "%u", rune.lv15_acc);
  240. sprintf(query_parameters[42], "%u", rune.lv15_res);
  241. if (
  242. SUCCESS !=
  243. db_execute(
  244. "INSERT INTO runes ("
  245. " id, unit, type,"
  246. " slot, stars, level,"
  247. " quality, efficiency, max_efficiency,"
  248. " main_stat, current_hp_percent, current_atk_percent,"
  249. " current_def_percent, current_hp_flat, current_atk_flat,"
  250. " current_def_flat, current_spd, current_crr,"
  251. " current_crd, current_acc, current_res,"
  252. " lv12_hp_percent, lv12_atk_percent, lv12_def_percent,"
  253. " lv12_hp_flat, lv12_atk_flat, lv12_def_flat,"
  254. " lv12_spd, lv12_crr, lv12_crd,"
  255. " lv12_acc, lv12_res, lv15_hp_percent,"
  256. " lv15_atk_percent, lv15_def_percent, lv15_hp_flat,"
  257. " lv15_atk_flat, lv15_def_flat, lv15_spd,"
  258. " lv15_crr, lv15_crd, lv15_acc,"
  259. " lv15_res"
  260. ") VALUES ("
  261. " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
  262. " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
  263. ")",
  264. query_parameters
  265. )
  266. ){
  267. fprintf(stderr, "Unable to insert rune: %s\n", sqlite3_errmsg(db));
  268. return(-1);
  269. }
  270. // Insert main stat
  271. total_stats ++;
  272. //query_parameters[0] = rune.id; // No need, already has id
  273. query_parameters[1] = "-1"; // Main stat
  274. sprintf(query_parameters[2], "%d", rune.main.stat);
  275. sprintf(query_parameters[3], "%u", rune.main.value);
  276. query_parameters[4] = "0"; // Mains can't be grinded.
  277. query_parameters[5] = "0"; // Mains can't be enchanted.
  278. if (
  279. SUCCESS !=
  280. db_execute(
  281. "INSERT INTO rune_stats(rune, slot, stat, value, grind, enchant) "
  282. "VALUES (?, ?, ?, ?, ?, ?)",
  283. query_parameters
  284. )
  285. ){
  286. fprintf(
  287. stderr, "Unable to insert rune main stat: %s\n", sqlite3_errmsg(db)
  288. );
  289. return(-1);
  290. }
  291. // Insert innate stat
  292. if (rune.innate.stat != 0){
  293. total_stats ++;
  294. //query_parameters[0] = rune.id; // No need, already has id
  295. query_parameters[1] = "0"; // Main stat
  296. sprintf(query_parameters[2], "%d", rune.innate.stat);
  297. sprintf(query_parameters[3], "%u", rune.innate.value);
  298. query_parameters[4] = "0"; // Innates can't be grinded.
  299. query_parameters[5] = "0"; // Innates can't be enchanted.
  300. if (
  301. SUCCESS !=
  302. db_execute(
  303. "INSERT INTO rune_stats "
  304. "(rune, slot, stat, value, grind, enchant) "
  305. "VALUES (?, ?, ?, ?, ?, ?)",
  306. query_parameters
  307. )
  308. ){
  309. fprintf(
  310. stderr,
  311. "Unable to insert rune innate stat: %s\n", sqlite3_errmsg(db)
  312. );
  313. return(-1);
  314. }
  315. }
  316. // Insert normal stats
  317. for (int s = 0; s < rune.stat_count; s ++){
  318. total_stats ++;
  319. //query_parameters[0] = rune.id; // No need, already has id
  320. query_parameters[1] = malloc(5);
  321. sprintf(query_parameters[1], "%d", s + 1); // 1-4
  322. query_parameters[2] = malloc(5);
  323. sprintf(query_parameters[2], "%d", rune.stats[s].stat);
  324. sprintf(query_parameters[3], "%u", rune.stats[s].value);
  325. query_parameters[4] = malloc(5);
  326. sprintf(query_parameters[4], "%u", rune.stats[s].grind);
  327. query_parameters[5] = malloc(5);
  328. sprintf(query_parameters[5], "%d", rune.stats[s].enchant);
  329. if (
  330. SUCCESS !=
  331. db_execute(
  332. "INSERT INTO rune_stats"
  333. "(rune, slot, stat, value, grind, enchant) "
  334. "VALUES (?, ?, ?, ?, ?, ?)",
  335. query_parameters
  336. )
  337. ){
  338. fprintf(
  339. stderr, "Unable to insert rune stat: %s\n", sqlite3_errmsg(db)
  340. );
  341. return(-1);
  342. }
  343. }
  344. // Now that everything is in the database, I can calculate efficiencies
  345. float efficiency = 0.0f;
  346. float max_efficiency = 0.0f;
  347. update_efficiency(query_parameters[0], &efficiency, &max_efficiency);
  348. strcpy(query_parameters[2], query_parameters[0]); //ID
  349. query_parameters[0] = malloc(35);
  350. query_parameters[1] = malloc(35);
  351. sprintf(query_parameters[0], "%3.2f", efficiency);
  352. sprintf(query_parameters[1], "%3.2f", max_efficiency);
  353. if (
  354. SUCCESS !=
  355. db_execute(
  356. "UPDATE runes SET efficiency = ?, max_efficiency = ? WHERE id = ?",
  357. query_parameters
  358. )
  359. ){
  360. fprintf(
  361. stderr, "Unable to update rune efficiency: %s\n", sqlite3_errmsg(db)
  362. );
  363. return(-1);
  364. }
  365. return(total_stats);
  366. }
  367. static int update_json_unit(
  368. json_object *unit_json, unsigned char six_stars,
  369. unsigned char with_runes, unsigned int *total_runes, unsigned int *total_stats
  370. ){
  371. int ret_val = 0;
  372. unsigned char unit_has_runes = FALSE;
  373. struct DB_Unit unit;
  374. char *query_parameters[23];
  375. for (int i = 1; i < 23; i ++) query_parameters[i] = malloc(5);
  376. // Unit ID
  377. json_object *unit_id = json_object_object_get(unit_json, "unit_id");
  378. strcpy((char *) unit.id, json_object_get_string(unit_id));
  379. // Unit monster ID
  380. json_object *unit_master_id =
  381. json_object_object_get(unit_json, "unit_master_id");
  382. unit.monster= json_object_get_int(unit_master_id);
  383. // Unit name
  384. update_get_monster_name(unit.monster, (char *) unit.name);
  385. json_object *unit_level = json_object_object_get(unit_json, "unit_level");
  386. unit.level = json_object_get_int(unit_level);
  387. // Unit stars (class)
  388. json_object *class = json_object_object_get(unit_json, "class");
  389. unit.stars = json_object_get_int(class);
  390. // Unit base HP (con * 15)
  391. json_object *con = json_object_object_get(unit_json, "con");
  392. unit.base_hp = json_object_get_int(con) * 15;
  393. // Unit base ATK
  394. json_object *atk = json_object_object_get(unit_json, "atk");
  395. unit.base_atk = json_object_get_int(atk);
  396. // Unit base DEF
  397. json_object *def = json_object_object_get(unit_json, "def");
  398. unit.base_def = json_object_get_int(def);
  399. // Unit base SPD
  400. json_object *spd = json_object_object_get(unit_json, "spd");
  401. unit.base_spd = json_object_get_int(spd);
  402. // Unit base RES
  403. json_object *resist = json_object_object_get(unit_json, "resist");
  404. unit.base_res = json_object_get_int(resist);
  405. // Unit base ACC
  406. json_object *accuracy = json_object_object_get(unit_json, "accuracy");
  407. unit.base_acc = json_object_get_int(accuracy);
  408. // Unit base CRR
  409. json_object *critical_rate =
  410. json_object_object_get(unit_json, "critical_rate");
  411. unit.base_crr = json_object_get_int(critical_rate);
  412. // Unit base CRD
  413. json_object *critical_damage =
  414. json_object_object_get(unit_json, "critical_damage");
  415. unit.base_crd = json_object_get_int(critical_damage);
  416. // Homunculus name (if is Homunculus)
  417. json_object *homunculus_name =
  418. json_object_object_get(unit_json, "homunculus_name");
  419. if (strlen(json_object_get_string(homunculus_name)) > 0){
  420. strcpy((char *) unit.name, json_object_get_string(homunculus_name));
  421. }
  422. // Parse unit runes
  423. json_object *unit_runes = json_object_object_get(unit_json, "runes");
  424. int rune_count = json_object_array_length(unit_runes);
  425. for (int i = 0; i < rune_count; i++){
  426. unit_has_runes = TRUE;
  427. // TODO: Test this: reference or value?
  428. total_runes ++;
  429. json_object *idx = json_object_array_get_idx(unit_runes, i);
  430. int status = update_json_rune(idx, unit.id);
  431. if (status != -1) *total_stats += status;
  432. }
  433. // Insert unit, depending on flags and status
  434. if (
  435. unit_has_runes == TRUE ||
  436. (six_stars == FALSE && with_runes == FALSE) ||
  437. (six_stars == TRUE && unit.stars == TRUE)
  438. ){
  439. ret_val = 1;
  440. query_parameters[0] = (char *) unit.id;
  441. query_parameters[1] = (char *) unit.name;
  442. sprintf(query_parameters[2], "%d", unit.stars);
  443. sprintf(query_parameters[3], "%d", unit.level);
  444. sprintf(query_parameters[4], "%u", unit.base_hp);
  445. sprintf(query_parameters[5], "%u", unit.base_atk);
  446. sprintf(query_parameters[6], "%u", unit.base_def);
  447. sprintf(query_parameters[7], "%u", unit.base_spd);
  448. sprintf(query_parameters[8], "%u", unit.base_crr);
  449. sprintf(query_parameters[9], "%u", unit.base_crd);
  450. sprintf(query_parameters[10], "%u", unit.base_res);
  451. sprintf(query_parameters[11], "%u", unit.base_acc);
  452. // Insert current stats as base stats.
  453. // They will be updated later.
  454. sprintf(query_parameters[12], "%u", unit.base_hp);
  455. sprintf(query_parameters[13], "%u", unit.base_atk);
  456. sprintf(query_parameters[14], "%u", unit.base_def);
  457. sprintf(query_parameters[15], "%u", unit.base_spd);
  458. sprintf(query_parameters[16], "%u", unit.base_crr);
  459. sprintf(query_parameters[17], "%u", unit.base_crd);
  460. sprintf(query_parameters[18], "%u", unit.base_res);
  461. sprintf(query_parameters[19], "%u", unit.base_acc);
  462. // TODO: Get storage status. But how??
  463. sprintf(query_parameters[20], "%d", 0);
  464. sprintf(query_parameters[21], "%u", unit.monster);
  465. if (
  466. SUCCESS !=
  467. db_execute(
  468. "INSERT INTO units ("
  469. " id, name, stars, level,"
  470. " base_hp, base_atk, base_def, base_spd,"
  471. " base_crr, base_crd, base_res, base_acc,"
  472. " current_hp, current_atk, current_def, current_spd,"
  473. " current_crr, current_crd, current_res, current_acc,"
  474. " storage, monster"
  475. ") VALUES ("
  476. " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
  477. ")",
  478. query_parameters
  479. )
  480. ){
  481. fprintf(stderr, "Unable to insert unit: %s\n", sqlite3_errmsg(db));
  482. return(-1);
  483. }
  484. }
  485. return(ret_val);
  486. }