2 7ea8226e 2021-09-06 xhr * Copyright (c) 2021 Matthias Schmidt <xhr@giessen.ccc.de>
4 7ea8226e 2021-09-06 xhr * Permission to use, copy, modify, and distribute this software for any
5 7ea8226e 2021-09-06 xhr * purpose with or without fee is hereby granted, provided that the above
6 7ea8226e 2021-09-06 xhr * copyright notice and this permission notice appear in all copies.
8 7ea8226e 2021-09-06 xhr * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7ea8226e 2021-09-06 xhr * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7ea8226e 2021-09-06 xhr * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7ea8226e 2021-09-06 xhr * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7ea8226e 2021-09-06 xhr * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7ea8226e 2021-09-06 xhr * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7ea8226e 2021-09-06 xhr * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ce559d58 2021-09-05 xhr #include "isscrolls.h"
19 ce559d58 2021-09-05 xhr #include <json-c/json.h>
21 7f1d5406 2021-09-06 xhr #include <limits.h>
22 ce559d58 2021-09-05 xhr #include <stdio.h>
23 ce559d58 2021-09-05 xhr #include <string.h>
25 c49b5003 2021-09-06 xhr static char oracle_is_names[200][MAX_NAME_LEN];
26 c49b5003 2021-09-06 xhr static char oracle_elf_names[100][MAX_NAME_LEN];
27 c49b5003 2021-09-06 xhr static char oracle_giant_names[100][MAX_NAME_LEN];
28 c49b5003 2021-09-06 xhr static char oracle_varou_names[100][MAX_NAME_LEN];
29 c49b5003 2021-09-06 xhr static char oracle_troll_names[100][MAX_NAME_LEN];
31 c49b5003 2021-09-06 xhr static char oracle_action[100][MAX_NAME_LEN];
32 c49b5003 2021-09-06 xhr static char oracle_theme[100][MAX_NAME_LEN];
34 c49b5003 2021-09-06 xhr static char oracle_rank[100][MAX_RANK_LEN];
35 c49b5003 2021-09-06 xhr static char oracle_combat_action[100][MAX_PLOT_LEN];
36 c49b5003 2021-09-06 xhr static char oracle_plot_twist[100][MAX_PLOT_LEN];
37 c49b5003 2021-09-06 xhr static char oracle_mystic_backslash[100][MAX_MYSTIC_LEN];
39 1a26b5c7 2021-09-06 xhr static char oracle_regions[100][MAX_PLACES_LEN];
40 1a26b5c7 2021-09-06 xhr static char oracle_locations[100][MAX_PLACES_LEN];
41 1a26b5c7 2021-09-06 xhr static char oracle_location_descriptions[100][MAX_PLACES_LEN];
42 3ea4b207 2021-09-09 xhr static char oracle_coastal_locations[100][MAX_PLACES_LEN];
44 3ad507cb 2021-09-13 xhr static char oracle_pay_the_price[100][MAX_PTP_LEN];
46 90849b35 2021-09-05 xhr static int read_names = 0;
47 90849b35 2021-09-05 xhr static int read_action = 0;
48 90849b35 2021-09-05 xhr static int read_turning = 0;
49 1a26b5c7 2021-09-06 xhr static int read_places = 0;
50 3ad507cb 2021-09-13 xhr static int read_moves = 0;
52 483f88df 2021-09-06 xhr static void read_names_from_json(void);
53 3ad507cb 2021-09-13 xhr static void read_moves_from_json(void);
54 483f88df 2021-09-06 xhr static void read_action_from_json(void);
55 483f88df 2021-09-06 xhr static void read_turning_from_json(void);
56 1a26b5c7 2021-09-06 xhr static void read_places_from_json(void);
58 29889142 2021-09-05 xhr enum oracle_codes {
59 29889142 2021-09-05 xhr ORACLE_IS_NAMES,
60 29889142 2021-09-05 xhr ORACLE_ELF_NAMES,
61 29889142 2021-09-05 xhr ORACLE_GIANT_NAMES,
62 29889142 2021-09-05 xhr ORACLE_VAROU_NAMES,
63 29889142 2021-09-05 xhr ORACLE_TROLL_NAMES,
64 29889142 2021-09-05 xhr ORACLE_ACTIONS,
65 29889142 2021-09-05 xhr ORACLE_THEMES,
66 29889142 2021-09-05 xhr ORACLE_RANKS,
67 29889142 2021-09-05 xhr ORACLE_COMBAT_ACTIONS,
68 29889142 2021-09-05 xhr ORACLE_PLOT_TWISTS,
69 29889142 2021-09-05 xhr ORACLE_MYSTIC_BACKSLASH,
70 1a26b5c7 2021-09-06 xhr ORACLE_REGION,
71 1a26b5c7 2021-09-06 xhr ORACLE_LOCATION ,
72 3ea4b207 2021-09-09 xhr ORACLE_COASTAL,
73 1a26b5c7 2021-09-06 xhr ORACLE_DESCRIPTION,
74 3ad507cb 2021-09-13 xhr ORACLE_PAYTHEPRICE,
78 89da551e 2021-09-05 xhr add_to_array(int what, int id, const char *value)
80 89da551e 2021-09-05 xhr log_debug("%d, %d, %s\n", what, id, value);
82 ce559d58 2021-09-05 xhr switch (what) {
84 89da551e 2021-09-05 xhr log_debug("Unknown array\n");
86 29889142 2021-09-05 xhr case ORACLE_IS_NAMES:
87 ce559d58 2021-09-05 xhr if (id < 0 || id > 200)
89 89da551e 2021-09-05 xhr snprintf(oracle_is_names[id], MAX_NAME_LEN, "%s", value);
91 29889142 2021-09-05 xhr case ORACLE_ELF_NAMES:
92 ce559d58 2021-09-05 xhr if (id < 0 || id > 100)
94 89da551e 2021-09-05 xhr snprintf(oracle_elf_names[id], MAX_NAME_LEN, "%s", value);
96 29889142 2021-09-05 xhr case ORACLE_GIANT_NAMES:
97 ce559d58 2021-09-05 xhr if (id < 0 || id > 100)
99 89da551e 2021-09-05 xhr snprintf(oracle_giant_names[id], MAX_NAME_LEN, "%s", value);
101 29889142 2021-09-05 xhr case ORACLE_VAROU_NAMES:
102 ce559d58 2021-09-05 xhr if (id < 0 || id > 100)
104 89da551e 2021-09-05 xhr snprintf(oracle_varou_names[id], MAX_NAME_LEN, "%s", value);
106 29889142 2021-09-05 xhr case ORACLE_TROLL_NAMES:
107 ce559d58 2021-09-05 xhr if (id < 0 || id > 100)
109 89da551e 2021-09-05 xhr snprintf(oracle_troll_names[id], MAX_NAME_LEN, "%s", value);
111 323180ed 2021-09-05 xhr /* -------------------------------------------------------------------- */
112 29889142 2021-09-05 xhr case ORACLE_ACTIONS:
113 89da551e 2021-09-05 xhr if (id < 0 || id > 100)
115 89da551e 2021-09-05 xhr snprintf(oracle_action[id], MAX_NAME_LEN, "%s", value);
117 29889142 2021-09-05 xhr case ORACLE_THEMES:
118 89da551e 2021-09-05 xhr if (id < 0 || id > 100)
120 89da551e 2021-09-05 xhr snprintf(oracle_theme[id], MAX_NAME_LEN, "%s", value);
122 323180ed 2021-09-05 xhr /* -------------------------------------------------------------------- */
123 29889142 2021-09-05 xhr case ORACLE_RANKS:
124 90849b35 2021-09-05 xhr if (id < 0 || id > 100)
126 90849b35 2021-09-05 xhr snprintf(oracle_rank[id], MAX_RANK_LEN, "%s", value);
128 29889142 2021-09-05 xhr case ORACLE_COMBAT_ACTIONS:
129 323180ed 2021-09-05 xhr if (id < 0 || id > 100)
131 323180ed 2021-09-05 xhr snprintf(oracle_combat_action[id], MAX_PLOT_LEN, "%s", value);
133 29889142 2021-09-05 xhr case ORACLE_PLOT_TWISTS:
134 323180ed 2021-09-05 xhr if (id < 0 || id > 100)
136 323180ed 2021-09-05 xhr snprintf(oracle_plot_twist[id], MAX_PLOT_LEN, "%s", value);
138 29889142 2021-09-05 xhr case ORACLE_MYSTIC_BACKSLASH:
139 d49e0a78 2021-09-05 xhr if (id < 0 || id > 100)
141 d49e0a78 2021-09-05 xhr snprintf(oracle_mystic_backslash[id], MAX_MYSTIC_LEN, "%s", value);
143 1a26b5c7 2021-09-06 xhr /* -------------------------------------------------------------------- */
144 1a26b5c7 2021-09-06 xhr case ORACLE_REGION:
145 1a26b5c7 2021-09-06 xhr if (id < 0 || id > 100)
147 1a26b5c7 2021-09-06 xhr snprintf(oracle_regions[id], MAX_PLACES_LEN, "%s", value);
149 1a26b5c7 2021-09-06 xhr case ORACLE_LOCATION:
150 1a26b5c7 2021-09-06 xhr if (id < 0 || id > 100)
152 1a26b5c7 2021-09-06 xhr snprintf(oracle_locations[id], MAX_PLACES_LEN, "%s", value);
154 3ea4b207 2021-09-09 xhr case ORACLE_COASTAL:
155 1a26b5c7 2021-09-06 xhr if (id < 0 || id > 100)
157 3ea4b207 2021-09-09 xhr snprintf(oracle_coastal_locations[id], MAX_PLACES_LEN, "%s", value);
159 1a26b5c7 2021-09-06 xhr case ORACLE_DESCRIPTION:
160 1a26b5c7 2021-09-06 xhr if (id < 0 || id > 100)
162 1a26b5c7 2021-09-06 xhr snprintf(oracle_location_descriptions[id], MAX_PLACES_LEN, "%s", value);
164 3ad507cb 2021-09-13 xhr /* -------------------------------------------------------------------- */
165 3ad507cb 2021-09-13 xhr case ORACLE_PAYTHEPRICE:
166 3ad507cb 2021-09-13 xhr if (id < 0 || id > 100)
168 3ad507cb 2021-09-13 xhr snprintf(oracle_pay_the_price[id], MAX_PTP_LEN, "%s", value);
171 64d52bc9 2021-09-16 xhr log_errx(1, "add_to_array: This should not happen\n");
177 ce559d58 2021-09-05 xhr read_names_from_json()
179 7f1d5406 2021-09-06 xhr char path[_POSIX_PATH_MAX];
180 37902866 2021-09-05 xhr json_object *root, *oracles, *temp, *table, *name, *desc, *chance;
181 ce559d58 2021-09-05 xhr int n_oracles, n_entries, i, j, what;
183 7f1d5406 2021-09-06 xhr snprintf(path, sizeof(path), "%s/ironsworn_oracles_names.json", _PATH_SHARE_DIR);
185 ce559d58 2021-09-05 xhr if ((root = json_object_from_file(path)) == NULL) {
186 90849b35 2021-09-05 xhr log_errx(1, "Cannot open %s\n", path);
189 a1c776dd 2021-09-16 xhr if (!json_object_object_get_ex(root, "Oracles", &oracles)) {
190 a1c776dd 2021-09-16 xhr log_debug("Cannot find a [Oracles] array in %s\n", path);
194 ce559d58 2021-09-05 xhr n_oracles = json_object_array_length(oracles);
196 ce559d58 2021-09-05 xhr log_debug("number of oracles: %d\n", n_oracles);
197 ce559d58 2021-09-05 xhr for (i = 0; i < n_oracles; i++) {
198 ce559d58 2021-09-05 xhr temp = json_object_array_get_idx(oracles, i);
199 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Oracle Table", &table);
200 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Name", &name);
201 ce559d58 2021-09-05 xhr log_debug("Name %s\n", json_object_get_string(name));
203 ce559d58 2021-09-05 xhr if ((strcmp(json_object_get_string(name), "Ironlander Names") == 0))
204 29889142 2021-09-05 xhr what = ORACLE_IS_NAMES;
205 ce559d58 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Elf Names") == 0))
206 29889142 2021-09-05 xhr what = ORACLE_ELF_NAMES;
207 ce559d58 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Giant Names") == 0))
208 29889142 2021-09-05 xhr what = ORACLE_GIANT_NAMES;
209 ce559d58 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Varou Names") == 0))
210 29889142 2021-09-05 xhr what = ORACLE_VAROU_NAMES;
211 ce559d58 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Troll Names") == 0))
212 29889142 2021-09-05 xhr what = ORACLE_TROLL_NAMES;
218 ce559d58 2021-09-05 xhr n_entries = json_object_array_length(table);
219 ce559d58 2021-09-05 xhr for (j = 0; j < n_entries; j++) {
220 ce559d58 2021-09-05 xhr temp = json_object_array_get_idx(table, j);
221 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Description", &desc);
222 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Chance", &chance);
223 37902866 2021-09-05 xhr add_to_array(what, json_object_get_int(chance), json_object_get_string(desc));
227 743ad35d 2021-09-06 xhr /* Decrement the reference count of json_object and free if it reaches zero. */
228 743ad35d 2021-09-06 xhr json_object_put(root);
230 89da551e 2021-09-05 xhr read_names = 1;
234 3ad507cb 2021-09-13 xhr read_moves_from_json()
236 3ad507cb 2021-09-13 xhr char path[_POSIX_PATH_MAX];
237 3ad507cb 2021-09-13 xhr json_object *root, *oracles, *temp, *table, *name, *desc, *chance;
238 3ad507cb 2021-09-13 xhr int n_oracles, n_entries, i, j, what;
240 3ad507cb 2021-09-13 xhr snprintf(path, sizeof(path), "%s/ironsworn_move_oracles.json", _PATH_SHARE_DIR);
242 3ad507cb 2021-09-13 xhr if ((root = json_object_from_file(path)) == NULL) {
243 3ad507cb 2021-09-13 xhr log_errx(1, "Cannot open %s\n", path);
246 a1c776dd 2021-09-16 xhr if (!json_object_object_get_ex(root, "Oracles", &oracles)) {
247 a1c776dd 2021-09-16 xhr log_debug("Cannot find a [Oracles] array in %s\n", path);
251 3ad507cb 2021-09-13 xhr n_oracles = json_object_array_length(oracles);
253 3ad507cb 2021-09-13 xhr log_debug("number of oracles: %d\n", n_oracles);
254 3ad507cb 2021-09-13 xhr for (i = 0; i < n_oracles; i++) {
255 3ad507cb 2021-09-13 xhr temp = json_object_array_get_idx(oracles, i);
256 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Oracle Table", &table);
257 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Name", &name);
258 3ad507cb 2021-09-13 xhr log_debug("Name %s\n", json_object_get_string(name));
260 3ad507cb 2021-09-13 xhr if ((strcmp(json_object_get_string(name), "Pay the Price") == 0))
261 3ad507cb 2021-09-13 xhr what = ORACLE_PAYTHEPRICE;
267 3ad507cb 2021-09-13 xhr n_entries = json_object_array_length(table);
268 3ad507cb 2021-09-13 xhr for (j = 0; j < n_entries; j++) {
269 3ad507cb 2021-09-13 xhr temp = json_object_array_get_idx(table, j);
270 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Description", &desc);
271 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Chance", &chance);
272 90922303 2021-09-16 xhr add_to_array(what, json_object_get_int(chance), json_object_get_string(desc));
276 3ad507cb 2021-09-13 xhr /* Decrement the reference count of json_object and free if it reaches zero. */
277 3ad507cb 2021-09-13 xhr json_object_put(root);
279 e8d826b7 2021-09-16 xhr read_moves = 1;
283 89da551e 2021-09-05 xhr read_action_from_json()
285 7f1d5406 2021-09-06 xhr char path[_POSIX_PATH_MAX];
286 89da551e 2021-09-05 xhr json_object *root, *oracles, *temp, *table, *name, *desc, *chance;
287 89da551e 2021-09-05 xhr int n_oracles, n_entries, i, j, what;
289 7f1d5406 2021-09-06 xhr snprintf(path, sizeof(path), "%s/ironsworn_oracles_prompts.json", _PATH_SHARE_DIR);
291 89da551e 2021-09-05 xhr if ((root = json_object_from_file(path)) == NULL) {
292 90849b35 2021-09-05 xhr log_errx(1, "Cannot open %s\n", path);
295 a1c776dd 2021-09-16 xhr if (!json_object_object_get_ex(root, "Oracles", &oracles)) {
296 a1c776dd 2021-09-16 xhr log_debug("Cannot find a [Oracles] array in %s\n", path);
300 89da551e 2021-09-05 xhr n_oracles = json_object_array_length(oracles);
302 89da551e 2021-09-05 xhr log_debug("number of oracles: %d\n", n_oracles);
303 89da551e 2021-09-05 xhr for (i = 0; i < n_oracles; i++) {
304 89da551e 2021-09-05 xhr temp = json_object_array_get_idx(oracles, i);
305 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Oracle Table", &table);
306 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Name", &name);
307 89da551e 2021-09-05 xhr log_debug("Name %s\n", json_object_get_string(name));
309 89da551e 2021-09-05 xhr if ((strcmp(json_object_get_string(name), "Action") == 0))
310 29889142 2021-09-05 xhr what = ORACLE_ACTIONS;
311 89da551e 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Theme") == 0))
312 29889142 2021-09-05 xhr what = ORACLE_THEMES;
313 89da551e 2021-09-05 xhr /* The following oracles are not yet supported */
314 89da551e 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Feature") == 0))
316 89da551e 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Focus") == 0))
318 89da551e 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Trap") == 0))
320 89da551e 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Combat Event") == 0))
327 90849b35 2021-09-05 xhr n_entries = json_object_array_length(table);
328 90849b35 2021-09-05 xhr for (j = 0; j < n_entries; j++) {
329 90849b35 2021-09-05 xhr temp = json_object_array_get_idx(table, j);
330 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Description", &desc);
331 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Chance", &chance);
332 90922303 2021-09-16 xhr add_to_array(what, json_object_get_int(chance), json_object_get_string(desc));
336 743ad35d 2021-09-06 xhr /* Decrement the reference count of json_object and free if it reaches zero. */
337 743ad35d 2021-09-06 xhr json_object_put(root);
339 90849b35 2021-09-05 xhr read_action = 1;
343 90849b35 2021-09-05 xhr read_turning_from_json()
345 af65c79f 2021-09-06 xhr char path[_POSIX_PATH_MAX];
346 90849b35 2021-09-05 xhr json_object *root, *oracles, *temp, *table, *name, *desc, *chance;
347 90849b35 2021-09-05 xhr int n_oracles, n_entries, i, j, what;
349 af65c79f 2021-09-06 xhr snprintf(path, sizeof(path), "%s/ironsworn_oracles_turning_point.json", _PATH_SHARE_DIR);
351 90849b35 2021-09-05 xhr if ((root = json_object_from_file(path)) == NULL) {
352 90849b35 2021-09-05 xhr log_errx(1, "Cannot open %s\n", path);
355 a1c776dd 2021-09-16 xhr if (!json_object_object_get_ex(root, "Oracles", &oracles)) {
356 a1c776dd 2021-09-16 xhr log_debug("Cannot find a [Oracles] array in %s\n", path);
360 90849b35 2021-09-05 xhr n_oracles = json_object_array_length(oracles);
362 90849b35 2021-09-05 xhr log_debug("number of oracles: %d\n", n_oracles);
363 90849b35 2021-09-05 xhr for (i = 0; i < n_oracles; i++) {
364 90849b35 2021-09-05 xhr temp = json_object_array_get_idx(oracles, i);
365 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Oracle Table", &table);
366 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Name", &name);
367 90849b35 2021-09-05 xhr log_debug("Name %s\n", json_object_get_string(name));
369 90849b35 2021-09-05 xhr if ((strcmp(json_object_get_string(name), "Challenge Rank") == 0))
370 29889142 2021-09-05 xhr what = ORACLE_RANKS;
371 90849b35 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Combat Action") == 0))
372 29889142 2021-09-05 xhr what = ORACLE_COMBAT_ACTIONS;
373 90849b35 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Major Plot Twist") == 0))
374 29889142 2021-09-05 xhr what = ORACLE_PLOT_TWISTS;
375 90849b35 2021-09-05 xhr else if ((strcmp(json_object_get_string(name), "Mystic Backlash") == 0))
376 29889142 2021-09-05 xhr what = ORACLE_MYSTIC_BACKSLASH;
382 89da551e 2021-09-05 xhr n_entries = json_object_array_length(table);
383 89da551e 2021-09-05 xhr for (j = 0; j < n_entries; j++) {
384 89da551e 2021-09-05 xhr temp = json_object_array_get_idx(table, j);
385 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Description", &desc);
386 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Chance", &chance);
387 90922303 2021-09-16 xhr add_to_array(what, json_object_get_int(chance), json_object_get_string(desc));
391 743ad35d 2021-09-06 xhr /* Decrement the reference count of json_object and free if it reaches zero. */
392 743ad35d 2021-09-06 xhr json_object_put(root);
394 323180ed 2021-09-05 xhr read_turning = 1;
398 1a26b5c7 2021-09-06 xhr read_places_from_json()
400 1a26b5c7 2021-09-06 xhr char path[_POSIX_PATH_MAX];
401 1a26b5c7 2021-09-06 xhr json_object *root, *oracles, *temp, *table, *name, *desc, *chance;
402 1a26b5c7 2021-09-06 xhr int n_oracles, n_entries, i, j, what;
404 1a26b5c7 2021-09-06 xhr snprintf(path, sizeof(path), "%s/ironsworn_oracles_place.json", _PATH_SHARE_DIR);
406 1a26b5c7 2021-09-06 xhr if ((root = json_object_from_file(path)) == NULL) {
407 1a26b5c7 2021-09-06 xhr log_errx(1, "Cannot open %s\n", path);
410 a1c776dd 2021-09-16 xhr if (!json_object_object_get_ex(root, "Oracles", &oracles)) {
411 a1c776dd 2021-09-16 xhr log_debug("Cannot find a [Oracles] array in %s\n", path);
415 1a26b5c7 2021-09-06 xhr n_oracles = json_object_array_length(oracles);
417 1a26b5c7 2021-09-06 xhr log_debug("number of oracles: %d\n", n_oracles);
418 1a26b5c7 2021-09-06 xhr for (i = 0; i < n_oracles; i++) {
419 1a26b5c7 2021-09-06 xhr temp = json_object_array_get_idx(oracles, i);
420 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Oracle Table", &table);
421 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Name", &name);
422 1a26b5c7 2021-09-06 xhr log_debug("Name %s\n", json_object_get_string(name));
424 1a26b5c7 2021-09-06 xhr if ((strcmp(json_object_get_string(name), "Region") == 0))
425 1a26b5c7 2021-09-06 xhr what = ORACLE_REGION;
426 1a26b5c7 2021-09-06 xhr else if ((strcmp(json_object_get_string(name), "Location") == 0))
427 1a26b5c7 2021-09-06 xhr what = ORACLE_LOCATION;
428 1a26b5c7 2021-09-06 xhr else if ((strcmp(json_object_get_string(name), "Coastal Waters Location") == 0))
429 3ea4b207 2021-09-09 xhr what = ORACLE_COASTAL;
430 1a26b5c7 2021-09-06 xhr else if ((strcmp(json_object_get_string(name), "Location Descriptors") == 0))
431 1a26b5c7 2021-09-06 xhr what = ORACLE_DESCRIPTION;
437 1a26b5c7 2021-09-06 xhr n_entries = json_object_array_length(table);
438 1a26b5c7 2021-09-06 xhr for (j = 0; j < n_entries; j++) {
439 1a26b5c7 2021-09-06 xhr temp = json_object_array_get_idx(table, j);
440 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Description", &desc);
441 90922303 2021-09-16 xhr json_object_object_get_ex(temp, "Chance", &chance);
442 90922303 2021-09-16 xhr add_to_array(what, json_object_get_int(chance), json_object_get_string(desc));
446 1a26b5c7 2021-09-06 xhr /* Decrement the reference count of json_object and free if it reaches zero. */
447 1a26b5c7 2021-09-06 xhr json_object_put(root);
449 1a26b5c7 2021-09-06 xhr read_places = 1;
453 ce559d58 2021-09-05 xhr cmd_show_iron_name(__attribute__((unused))char *unused)
455 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_IS_NAMES, 200);
459 ce559d58 2021-09-05 xhr cmd_show_elf_name(__attribute__((unused))char *unused)
461 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_ELF_NAMES, 100);
465 ce559d58 2021-09-05 xhr cmd_show_giant_name(__attribute__((unused))char *unused)
467 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_GIANT_NAMES, 100);
471 ce559d58 2021-09-05 xhr cmd_show_varou_name(__attribute__((unused))char *unused)
473 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_VAROU_NAMES, 100);
477 ce559d58 2021-09-05 xhr cmd_show_troll_name(__attribute__((unused))char *unused)
479 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_TROLL_NAMES, 100);
483 89da551e 2021-09-05 xhr cmd_show_action(__attribute__((unused))char *unused)
485 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_ACTIONS, 100);
489 89da551e 2021-09-05 xhr cmd_show_theme(__attribute__((unused))char *unused)
491 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_THEMES, 100);
495 90849b35 2021-09-05 xhr cmd_show_rank(__attribute__((unused))char *unused)
497 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_RANKS, 100);
501 323180ed 2021-09-05 xhr cmd_show_combat_action(__attribute__((unused))char *unused)
503 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_COMBAT_ACTIONS, 100);
507 323180ed 2021-09-05 xhr cmd_show_plot_twist(__attribute__((unused))char *unused)
509 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_PLOT_TWISTS, 100);
513 d49e0a78 2021-09-05 xhr cmd_show_mystic_backshlash(__attribute__((unused))char *unused)
515 29889142 2021-09-05 xhr show_info_from_oracle(ORACLE_MYSTIC_BACKSLASH, 100);
519 1a26b5c7 2021-09-06 xhr cmd_show_location(__attribute__((unused))char *unused)
521 1a26b5c7 2021-09-06 xhr show_info_from_oracle(ORACLE_LOCATION, 100);
525 1a26b5c7 2021-09-06 xhr cmd_show_location_description(__attribute__((unused))char *unused)
527 1a26b5c7 2021-09-06 xhr show_info_from_oracle(ORACLE_DESCRIPTION, 100);
531 3ea4b207 2021-09-09 xhr cmd_show_coastal_location(__attribute__((unused))char *unused)
533 3ea4b207 2021-09-09 xhr show_info_from_oracle(ORACLE_COASTAL, 100);
537 1a26b5c7 2021-09-06 xhr cmd_show_region(__attribute__((unused))char *unused)
539 1a26b5c7 2021-09-06 xhr show_info_from_oracle(ORACLE_REGION, 100);
543 3ad507cb 2021-09-13 xhr cmd_show_pay_the_price(__attribute__((unused))char *unused)
545 3ad507cb 2021-09-13 xhr show_info_from_oracle(ORACLE_PAYTHEPRICE, 100);
549 29889142 2021-09-05 xhr show_info_from_oracle(int what, int max)
551 29889142 2021-09-05 xhr char temp[255];
552 8c090849 2021-09-09 xhr long die, die2, saved_die;
554 8c090849 2021-09-09 xhr die = saved_die = roll_oracle_die();
555 29889142 2021-09-05 xhr if (die < 0 || die >= max)
558 29889142 2021-09-05 xhr memset(temp, 0, sizeof(temp));
560 7c7a71d6 2021-09-06 xhr if (read_names == 0)
561 7c7a71d6 2021-09-06 xhr read_names_from_json();
562 7c7a71d6 2021-09-06 xhr if (read_action == 0)
563 7c7a71d6 2021-09-06 xhr read_action_from_json();
564 7c7a71d6 2021-09-06 xhr if (read_turning == 0)
565 7c7a71d6 2021-09-06 xhr read_turning_from_json();
566 1a26b5c7 2021-09-06 xhr if (read_places == 0)
567 1a26b5c7 2021-09-06 xhr read_places_from_json();
568 3ad507cb 2021-09-13 xhr if (read_moves == 0)
569 3ad507cb 2021-09-13 xhr read_moves_from_json();
571 29889142 2021-09-05 xhr switch(what) {
572 29889142 2021-09-05 xhr case ORACLE_IS_NAMES:
573 29889142 2021-09-05 xhr die2 = roll_oracle_die();
574 29889142 2021-09-05 xhr die += die2;
575 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_is_names[die]);
577 29889142 2021-09-05 xhr case ORACLE_ELF_NAMES:
578 996f1345 2021-09-06 xhr while (strlen(oracle_elf_names[die]) == 0)
580 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_elf_names[die]);
582 29889142 2021-09-05 xhr case ORACLE_GIANT_NAMES:
583 29889142 2021-09-05 xhr while (strlen(oracle_giant_names[die]) == 0)
585 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_giant_names[die]);
587 29889142 2021-09-05 xhr case ORACLE_VAROU_NAMES:
588 29889142 2021-09-05 xhr while (strlen(oracle_varou_names[die]) == 0)
590 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_varou_names[die]);
592 29889142 2021-09-05 xhr case ORACLE_TROLL_NAMES:
593 29889142 2021-09-05 xhr while (strlen(oracle_troll_names[die]) == 0)
595 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_troll_names[die]);
597 29889142 2021-09-05 xhr case ORACLE_ACTIONS:
598 29889142 2021-09-05 xhr while (strlen(oracle_action[die]) == 0)
600 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_action[die]);
602 29889142 2021-09-05 xhr case ORACLE_THEMES:
603 29889142 2021-09-05 xhr while (strlen(oracle_theme[die]) == 0)
605 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_theme[die]);
607 29889142 2021-09-05 xhr case ORACLE_RANKS:
608 29889142 2021-09-05 xhr while (strlen(oracle_rank[die]) == 0)
610 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_rank[die]);
612 29889142 2021-09-05 xhr case ORACLE_COMBAT_ACTIONS:
613 29889142 2021-09-05 xhr while (strlen(oracle_combat_action[die]) == 0)
615 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_combat_action[die]);
617 29889142 2021-09-05 xhr case ORACLE_PLOT_TWISTS:
618 29889142 2021-09-05 xhr while (strlen(oracle_plot_twist[die]) == 0)
620 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_plot_twist[die]);
622 29889142 2021-09-05 xhr case ORACLE_MYSTIC_BACKSLASH:
623 29889142 2021-09-05 xhr while (strlen(oracle_mystic_backslash[die]) == 0)
625 29889142 2021-09-05 xhr snprintf(temp, sizeof(temp), "%s", oracle_mystic_backslash[die]);
627 1a26b5c7 2021-09-06 xhr case ORACLE_REGION:
628 1a26b5c7 2021-09-06 xhr while (strlen(oracle_regions[die]) == 0)
630 1a26b5c7 2021-09-06 xhr snprintf(temp, sizeof(temp), "%s", oracle_regions[die]);
632 1a26b5c7 2021-09-06 xhr case ORACLE_LOCATION:
633 1a26b5c7 2021-09-06 xhr while (strlen(oracle_locations[die]) == 0)
635 1a26b5c7 2021-09-06 xhr snprintf(temp, sizeof(temp), "%s", oracle_locations[die]);
637 3ea4b207 2021-09-09 xhr case ORACLE_COASTAL:
638 3ea4b207 2021-09-09 xhr while (strlen(oracle_coastal_locations[die]) == 0)
640 3ea4b207 2021-09-09 xhr snprintf(temp, sizeof(temp), "%s", oracle_coastal_locations[die]);
642 1a26b5c7 2021-09-06 xhr case ORACLE_DESCRIPTION:
643 1a26b5c7 2021-09-06 xhr while (strlen(oracle_location_descriptions[die]) == 0)
645 1a26b5c7 2021-09-06 xhr snprintf(temp, sizeof(temp), "%s", oracle_location_descriptions[die]);
647 3ad507cb 2021-09-13 xhr case ORACLE_PAYTHEPRICE:
648 3ad507cb 2021-09-13 xhr while (strlen(oracle_pay_the_price[die]) == 0)
650 3ad507cb 2021-09-13 xhr snprintf(temp, sizeof(temp), "%s", oracle_pay_the_price[die]);
654 8c090849 2021-09-09 xhr printf("%s (%ld)\n", temp, saved_die);