Blame


1 7ea8226e 2021-09-06 xhr /*
2 7ea8226e 2021-09-06 xhr * Copyright (c) 2021 Matthias Schmidt <xhr@giessen.ccc.de>
3 7ea8226e 2021-09-06 xhr *
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.
7 7ea8226e 2021-09-06 xhr *
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.
15 7ea8226e 2021-09-06 xhr */
16 7ea8226e 2021-09-06 xhr
17 ffb14e6a 2021-09-02 xhr #include <errno.h>
18 ffb14e6a 2021-09-02 xhr #include <limits.h>
19 63354cc5 2021-09-01 xhr #include <stdio.h>
20 63354cc5 2021-09-01 xhr #include <stdlib.h>
21 63354cc5 2021-09-01 xhr #include <string.h>
22 ffb14e6a 2021-09-02 xhr #include <stdlib.h>
23 63354cc5 2021-09-01 xhr
24 63354cc5 2021-09-01 xhr #include "isscrolls.h"
25 63354cc5 2021-09-01 xhr
26 d548c131 2021-09-02 xhr #define MAXTOKENS 3
27 d548c131 2021-09-02 xhr
28 1e9e9b0b 2021-09-01 xhr static const char *odds[] = {
29 1e9e9b0b 2021-09-01 xhr "Almost certain",
30 1e9e9b0b 2021-09-01 xhr "Likely",
31 1e9e9b0b 2021-09-01 xhr "50/50",
32 1e9e9b0b 2021-09-01 xhr "Unlikely",
33 1e9e9b0b 2021-09-01 xhr "Small chance",
34 1e9e9b0b 2021-09-01 xhr NULL
35 1e9e9b0b 2021-09-01 xhr };
36 1e9e9b0b 2021-09-01 xhr
37 63354cc5 2021-09-01 xhr void
38 f267c8e7 2021-09-08 xhr cmd_gather_information(char *cmd)
39 f267c8e7 2021-09-08 xhr {
40 f267c8e7 2021-09-08 xhr struct character *curchar = get_current_character();
41 f267c8e7 2021-09-08 xhr int ival[2] = { -1, -1 };
42 f267c8e7 2021-09-08 xhr int ret;
43 f267c8e7 2021-09-08 xhr
44 f267c8e7 2021-09-08 xhr if (curchar == NULL) {
45 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
46 f267c8e7 2021-09-08 xhr return;
47 f267c8e7 2021-09-08 xhr }
48 f267c8e7 2021-09-08 xhr
49 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
50 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
51 f267c8e7 2021-09-08 xhr
52 f267c8e7 2021-09-08 xhr ret = action_roll(ival);
53 f267c8e7 2021-09-08 xhr if (ret == 8) { /* strong hit */
54 f267c8e7 2021-09-08 xhr change_char_value("momentum", INCREASE, 2);
55 f267c8e7 2021-09-08 xhr } else if (ret == 4) { /* weak hit */
56 f267c8e7 2021-09-08 xhr change_char_value("momentum", INCREASE, 1);
57 704a3bbf 2021-09-09 xhr } else
58 704a3bbf 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
59 704a3bbf 2021-09-09 xhr }
60 704a3bbf 2021-09-09 xhr
61 704a3bbf 2021-09-09 xhr void
62 80379fca 2021-09-09 xhr cmd_sojourn(char *cmd)
63 704a3bbf 2021-09-09 xhr {
64 704a3bbf 2021-09-09 xhr struct character *curchar = get_current_character();
65 704a3bbf 2021-09-09 xhr int ival[2] = { -1, -1 };
66 704a3bbf 2021-09-09 xhr int ret;
67 704a3bbf 2021-09-09 xhr
68 704a3bbf 2021-09-09 xhr if (curchar == NULL) {
69 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
70 704a3bbf 2021-09-09 xhr return;
71 704a3bbf 2021-09-09 xhr }
72 704a3bbf 2021-09-09 xhr
73 704a3bbf 2021-09-09 xhr ival[0] = curchar->heart;
74 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
75 704a3bbf 2021-09-09 xhr
76 704a3bbf 2021-09-09 xhr ret = action_roll(ival);
77 704a3bbf 2021-09-09 xhr if (ret == 8) { /* strong hit */
78 3501467d 2021-09-09 xhr printf("You may choose two optionsresults -> Rulebook\n");
79 704a3bbf 2021-09-09 xhr } else if (ret == 4) { /* weak hit */
80 704a3bbf 2021-09-09 xhr printf("You may choose one result -> Rulebook\n");
81 2231141b 2021-09-09 xhr } else
82 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
83 f267c8e7 2021-09-08 xhr }
84 f267c8e7 2021-09-08 xhr
85 f267c8e7 2021-09-08 xhr void
86 9c58a078 2021-09-09 xhr cmd_draw_the_circle(char *cmd)
87 9c58a078 2021-09-09 xhr {
88 9c58a078 2021-09-09 xhr struct character *curchar = get_current_character();
89 9c58a078 2021-09-09 xhr int ival[2] = { -1, -1 };
90 9c58a078 2021-09-09 xhr int ret;
91 9c58a078 2021-09-09 xhr
92 9c58a078 2021-09-09 xhr if (curchar == NULL) {
93 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
94 9c58a078 2021-09-09 xhr return;
95 9c58a078 2021-09-09 xhr }
96 9c58a078 2021-09-09 xhr
97 9c58a078 2021-09-09 xhr ival[0] = curchar->heart;
98 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
99 9c58a078 2021-09-09 xhr
100 9c58a078 2021-09-09 xhr ret = action_roll(ival);
101 9c58a078 2021-09-09 xhr if (ret == 8) {
102 9c58a078 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
103 9c58a078 2021-09-09 xhr printf("You may choose even more boasts -> Rulebook\n");
104 9c58a078 2021-09-09 xhr } else if (ret == 4) {
105 9c58a078 2021-09-09 xhr printf("You may choose one boasts -> Rulebook\n");
106 9c58a078 2021-09-09 xhr } else
107 9c58a078 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
108 8cc30b28 2021-09-09 xhr }
109 8cc30b28 2021-09-09 xhr
110 8cc30b28 2021-09-09 xhr void
111 8cc30b28 2021-09-09 xhr cmd_swear_an_iron_vow(char *cmd)
112 8cc30b28 2021-09-09 xhr {
113 8cc30b28 2021-09-09 xhr struct character *curchar = get_current_character();
114 8cc30b28 2021-09-09 xhr int ival[2] = { -1, -1 };
115 8cc30b28 2021-09-09 xhr int ret;
116 8cc30b28 2021-09-09 xhr
117 8cc30b28 2021-09-09 xhr if (curchar == NULL) {
118 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
119 8cc30b28 2021-09-09 xhr return;
120 8cc30b28 2021-09-09 xhr }
121 8cc30b28 2021-09-09 xhr
122 8cc30b28 2021-09-09 xhr ival[0] = curchar->heart;
123 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
124 8cc30b28 2021-09-09 xhr
125 8cc30b28 2021-09-09 xhr ret = action_roll(ival);
126 8cc30b28 2021-09-09 xhr if (ret == 8) {
127 8cc30b28 2021-09-09 xhr change_char_value("momentum", INCREASE, 2);
128 8cc30b28 2021-09-09 xhr printf("You are emboldened and know what you must do next\n");
129 8cc30b28 2021-09-09 xhr } else if (ret == 4) {
130 8cc30b28 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
131 8cc30b28 2021-09-09 xhr printf("You are determined but begin your quest with questions\n");
132 8cc30b28 2021-09-09 xhr } else
133 8cc30b28 2021-09-09 xhr printf("You face a significant obstacle -> Rulebook\n");
134 9c58a078 2021-09-09 xhr }
135 9c58a078 2021-09-09 xhr
136 9c58a078 2021-09-09 xhr void
137 319d4050 2021-09-16 xhr cmd_forge_a_bond(char *cmd)
138 86c8a615 2021-09-09 xhr {
139 86c8a615 2021-09-09 xhr struct character *curchar = get_current_character();
140 86c8a615 2021-09-09 xhr int ival[2] = { -1, -1 };
141 86c8a615 2021-09-09 xhr int ret;
142 86c8a615 2021-09-09 xhr
143 86c8a615 2021-09-09 xhr if (curchar == NULL) {
144 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
145 86c8a615 2021-09-09 xhr return;
146 86c8a615 2021-09-09 xhr }
147 86c8a615 2021-09-09 xhr
148 86c8a615 2021-09-09 xhr ival[0] = curchar->heart;
149 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
150 86c8a615 2021-09-09 xhr
151 86c8a615 2021-09-09 xhr ret = action_roll(ival);
152 86c8a615 2021-09-09 xhr if (ret == 8) {
153 be9e9b67 2021-09-13 xhr printf("You forge a bind and choose one option -> Rulebook\n");
154 be9e9b67 2021-09-13 xhr curchar->bonds += 0.25;
155 86c8a615 2021-09-09 xhr } else if (ret == 4) {
156 86c8a615 2021-09-09 xhr printf("They ask something from you first -> Rulebook\n");
157 86c8a615 2021-09-09 xhr } else
158 be9e9b67 2021-09-13 xhr printf("You are refused. Pay the price -> Rulebook\n");
159 86c8a615 2021-09-09 xhr }
160 86c8a615 2021-09-09 xhr
161 86c8a615 2021-09-09 xhr void
162 319d4050 2021-09-16 xhr cmd_test_your_bond(char *cmd)
163 34ed03e1 2021-09-09 xhr {
164 34ed03e1 2021-09-09 xhr struct character *curchar = get_current_character();
165 34ed03e1 2021-09-09 xhr int ival[2] = { -1, -1 };
166 34ed03e1 2021-09-09 xhr int ret;
167 34ed03e1 2021-09-09 xhr
168 34ed03e1 2021-09-09 xhr if (curchar == NULL) {
169 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
170 34ed03e1 2021-09-09 xhr return;
171 34ed03e1 2021-09-09 xhr }
172 34ed03e1 2021-09-09 xhr
173 cc1c1bd6 2021-09-13 xhr if (curchar->bonds == 0) {
174 cc1c1bd6 2021-09-13 xhr printf("You have no bonds forged. Please do so first\n");
175 cc1c1bd6 2021-09-13 xhr return;
176 cc1c1bd6 2021-09-13 xhr }
177 cc1c1bd6 2021-09-13 xhr
178 34ed03e1 2021-09-09 xhr ival[0] = curchar->heart;
179 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
180 34ed03e1 2021-09-09 xhr
181 34ed03e1 2021-09-09 xhr ret = action_roll(ival);
182 34ed03e1 2021-09-09 xhr if (ret == 8) {
183 34ed03e1 2021-09-09 xhr printf("You may choose one boost -> Rulebook\n");
184 34ed03e1 2021-09-09 xhr } else if (ret == 4) {
185 34ed03e1 2021-09-09 xhr printf("Your bond is fragile -> Rulebook\n");
186 cc1c1bd6 2021-09-13 xhr } else {
187 cc1c1bd6 2021-09-13 xhr printf("Your bond is cleared. Pay the price -> Rulebook\n");
188 cc1c1bd6 2021-09-13 xhr curchar->bonds -= 0.25;
189 80a35657 2021-09-13 xhr }
190 80a35657 2021-09-13 xhr }
191 80a35657 2021-09-13 xhr
192 80a35657 2021-09-13 xhr void
193 80a35657 2021-09-13 xhr cmd_endure_stress(char *cmd)
194 80a35657 2021-09-13 xhr {
195 80a35657 2021-09-13 xhr struct character *curchar = get_current_character();
196 80a35657 2021-09-13 xhr int ival[2] = { -1, -1 };
197 80a35657 2021-09-13 xhr int ret, hr;
198 80a35657 2021-09-13 xhr
199 80a35657 2021-09-13 xhr if (curchar == NULL) {
200 80a35657 2021-09-13 xhr printf("No character loaded. Use 'cd' to load a character\n");
201 80a35657 2021-09-13 xhr return;
202 80a35657 2021-09-13 xhr }
203 80a35657 2021-09-13 xhr
204 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
205 319d4050 2021-09-16 xhr if (ival[1] == -1) {
206 80a35657 2021-09-13 xhr printf("Please provide a number as argument\n\n");
207 80a35657 2021-09-13 xhr printf("The number is the amount of stress you suffer\n");
208 80a35657 2021-09-13 xhr printf("Example: endurestress 2\n");
209 80a35657 2021-09-13 xhr return;
210 cc1c1bd6 2021-09-13 xhr }
211 80a35657 2021-09-13 xhr
212 80a35657 2021-09-13 xhr hr = curchar->spirit - ival[1];
213 80a35657 2021-09-13 xhr if (hr >= 0) {
214 80a35657 2021-09-13 xhr curchar->spirit -= ival[1];
215 80a35657 2021-09-13 xhr printf("You suffer -%d spirit and it is down to %d\n",
216 80a35657 2021-09-13 xhr ival[1], curchar->spirit);
217 80a35657 2021-09-13 xhr } else if (hr < 0) {
218 80a35657 2021-09-13 xhr /* Spirit is 0, so suffer -momentum equal to remaining health */
219 80a35657 2021-09-13 xhr log_debug("hr < 0: %d\n", hr);
220 80a35657 2021-09-13 xhr curchar->spirit = 0;
221 80a35657 2021-09-13 xhr curchar->momentum -= (hr * (-1));
222 80a35657 2021-09-13 xhr printf("You suffer -%d spirt and since your spirit is 0, your "\
223 80a35657 2021-09-13 xhr "momentum is down to %d\n", ival[1], curchar->momentum);
224 80a35657 2021-09-13 xhr }
225 80a35657 2021-09-13 xhr
226 80a35657 2021-09-13 xhr /* Reset ival[1] since we need no bonus for the roll */
227 80a35657 2021-09-13 xhr ival[1] = -1;
228 80a35657 2021-09-13 xhr ival[0] = curchar->heart;
229 80a35657 2021-09-13 xhr if (curchar->spirit > curchar->heart) {
230 80a35657 2021-09-13 xhr ival[0] = curchar->spirit;
231 80a35657 2021-09-13 xhr }
232 80a35657 2021-09-13 xhr
233 80a35657 2021-09-13 xhr ret = action_roll(ival);
234 80a35657 2021-09-13 xhr if (ret == 8) {
235 80a35657 2021-09-13 xhr printf("You need to choose one option -> Rulebook\n");
236 80a35657 2021-09-13 xhr } else if (ret == 4) {
237 80a35657 2021-09-13 xhr printf("You press on\n");
238 80a35657 2021-09-13 xhr } else {
239 80a35657 2021-09-13 xhr change_char_value("momentum", DECREASE, 1);
240 80a35657 2021-09-13 xhr if (curchar->health == 0)
241 80a35657 2021-09-13 xhr printf("Mark either shaken or corrupted or roll on the oracle table -> Rulebook\n");
242 80a35657 2021-09-13 xhr }
243 34ed03e1 2021-09-09 xhr }
244 34ed03e1 2021-09-09 xhr
245 34ed03e1 2021-09-09 xhr void
246 319d4050 2021-09-16 xhr cmd_face_death(char *cmd)
247 d2b9d86f 2021-09-13 xhr {
248 d2b9d86f 2021-09-13 xhr struct character *curchar = get_current_character();
249 d2b9d86f 2021-09-13 xhr int ival[2] = { -1, -1 };
250 d2b9d86f 2021-09-13 xhr int ret;
251 d2b9d86f 2021-09-13 xhr
252 d2b9d86f 2021-09-13 xhr if (curchar == NULL) {
253 d2b9d86f 2021-09-13 xhr printf("No character loaded. Use 'cd' to load a character\n");
254 d2b9d86f 2021-09-13 xhr return;
255 d2b9d86f 2021-09-13 xhr }
256 d2b9d86f 2021-09-13 xhr
257 d2b9d86f 2021-09-13 xhr ival[0] = curchar->heart;
258 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
259 d2b9d86f 2021-09-13 xhr
260 d2b9d86f 2021-09-13 xhr ret = action_roll(ival);
261 d2b9d86f 2021-09-13 xhr if (ret == 8) {
262 d2b9d86f 2021-09-13 xhr printf("Death rejects you.\n");
263 d2b9d86f 2021-09-13 xhr } else if (ret == 4) {
264 d2b9d86f 2021-09-13 xhr printf("Your must choose one option -> Rulebook\n");
265 d2b9d86f 2021-09-13 xhr } else {
266 d2b9d86f 2021-09-13 xhr printf("You are dead\n");
267 d2b9d86f 2021-09-13 xhr curchar->dead = 1;
268 d2b9d86f 2021-09-13 xhr }
269 d2b9d86f 2021-09-13 xhr }
270 d2b9d86f 2021-09-13 xhr
271 d2b9d86f 2021-09-13 xhr void
272 f267c8e7 2021-09-08 xhr cmd_heal(char *who)
273 f267c8e7 2021-09-08 xhr {
274 f267c8e7 2021-09-08 xhr struct character *curchar = get_current_character();
275 f267c8e7 2021-09-08 xhr int ival[2] = { -1, -1 };
276 f267c8e7 2021-09-08 xhr int ret;
277 f267c8e7 2021-09-08 xhr
278 f267c8e7 2021-09-08 xhr if (curchar == NULL) {
279 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
280 f267c8e7 2021-09-08 xhr return;
281 f267c8e7 2021-09-08 xhr }
282 f267c8e7 2021-09-08 xhr
283 f267c8e7 2021-09-08 xhr if (strlen(who) == 0) {
284 f267c8e7 2021-09-08 xhr info:
285 f267c8e7 2021-09-08 xhr printf("Please specify who to heal\n\n");
286 f267c8e7 2021-09-08 xhr printf("me\t- heal yourself (roll against Iron or Wits (whatever is lower))\n");
287 f267c8e7 2021-09-08 xhr printf("others\t- heal others (roll against Wits)\n\n");
288 f267c8e7 2021-09-08 xhr printf("Example: heal me\n");
289 f267c8e7 2021-09-08 xhr return;
290 f267c8e7 2021-09-08 xhr }
291 f267c8e7 2021-09-08 xhr
292 a14b5708 2021-09-16 xhr if (strcasecmp(who, "me") == 0) {
293 f267c8e7 2021-09-08 xhr if (curchar->iron < curchar->wits)
294 f267c8e7 2021-09-08 xhr ival[0] = curchar->iron;
295 f267c8e7 2021-09-08 xhr else if (curchar->iron > curchar->wits)
296 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
297 f267c8e7 2021-09-08 xhr else
298 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
299 a14b5708 2021-09-16 xhr } else if (strcasecmp(who, "others") == 0) {
300 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
301 f267c8e7 2021-09-08 xhr } else
302 f267c8e7 2021-09-08 xhr goto info;
303 f267c8e7 2021-09-08 xhr
304 f267c8e7 2021-09-08 xhr ret = action_roll(ival);
305 f267c8e7 2021-09-08 xhr if (ret == 8) { /* strong hit */
306 f267c8e7 2021-09-08 xhr change_char_value("health", INCREASE, 2);
307 f267c8e7 2021-09-08 xhr } else if (ret == 4) { /* weak hit */
308 f267c8e7 2021-09-08 xhr change_char_value("health", INCREASE, 1);
309 f267c8e7 2021-09-08 xhr change_char_value("momentum", DECREASE, 1);
310 2231141b 2021-09-09 xhr } else
311 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
312 f267c8e7 2021-09-08 xhr }
313 f267c8e7 2021-09-08 xhr
314 f267c8e7 2021-09-08 xhr void
315 63354cc5 2021-09-01 xhr cmd_roll_action_dice(char *cmd)
316 63354cc5 2021-09-01 xhr {
317 ffb14e6a 2021-09-02 xhr char *ep;
318 d548c131 2021-09-02 xhr char *tokens[MAXTOKENS];
319 d548c131 2021-09-02 xhr char *p, *last;
320 d548c131 2021-09-02 xhr int i = 0;
321 d548c131 2021-09-02 xhr long lval[2];
322 d548c131 2021-09-02 xhr int ival[2] = { -1, -1 };
323 ffb14e6a 2021-09-02 xhr
324 ffb14e6a 2021-09-02 xhr if (cmd == NULL || strlen(cmd) == 0) {
325 d548c131 2021-09-02 xhr printf("Please provide at least one attribute value\n\n");
326 d548c131 2021-09-02 xhr printf("> action <attribute value> [bonus value]\n\n");
327 d548c131 2021-09-02 xhr printf("Examples:\n");
328 8f2dede1 2021-09-02 xhr printf("> action 3\t- Add 3 to the D6 die\n");
329 295637c6 2021-09-09 xhr printf("> action 4 1\t- Add 4 and additionally 1 to the D6 die\n\n");
330 d548c131 2021-09-02 xhr
331 ffb14e6a 2021-09-02 xhr return;
332 ffb14e6a 2021-09-02 xhr }
333 ffb14e6a 2021-09-02 xhr
334 d548c131 2021-09-02 xhr log_debug("cmd: %s\n", cmd);
335 d548c131 2021-09-02 xhr
336 d548c131 2021-09-02 xhr /* Parse the argument line into 2 tokens, separated by space */
337 d548c131 2021-09-02 xhr for ((p = strtok_r(cmd, " ", &last)); p;
338 d548c131 2021-09-02 xhr (p = strtok_r(NULL, " ", &last))) {
339 d548c131 2021-09-02 xhr if (i < MAXTOKENS - 1)
340 d548c131 2021-09-02 xhr tokens[i++] = p;
341 ffb14e6a 2021-09-02 xhr }
342 d548c131 2021-09-02 xhr tokens[i] = NULL;
343 d548c131 2021-09-02 xhr
344 d548c131 2021-09-02 xhr for (i=0; tokens[i] != NULL; i++) {
345 d548c131 2021-09-02 xhr log_debug("token %d: %s\n", i, tokens[i]);
346 d548c131 2021-09-02 xhr
347 d548c131 2021-09-02 xhr errno = 0;
348 d548c131 2021-09-02 xhr lval[i] = strtol(tokens[i], &ep, 10);
349 d548c131 2021-09-02 xhr if (cmd[0] == '\0' || *ep != '\0') {
350 d548c131 2021-09-02 xhr printf("Please provide a number as argument\n");
351 d548c131 2021-09-02 xhr return;
352 d548c131 2021-09-02 xhr }
353 d548c131 2021-09-02 xhr if ((errno == ERANGE || lval[i] <= 0 || lval[i] > 10)) {
354 d548c131 2021-09-02 xhr printf("Please provide a number between 1 and 10\n");
355 d548c131 2021-09-02 xhr return;
356 d548c131 2021-09-02 xhr }
357 d548c131 2021-09-02 xhr ival[i] = lval[i];
358 ffb14e6a 2021-09-02 xhr }
359 ffb14e6a 2021-09-02 xhr
360 ffb14e6a 2021-09-02 xhr action_roll(ival);
361 63354cc5 2021-09-01 xhr }
362 63354cc5 2021-09-01 xhr
363 63354cc5 2021-09-01 xhr void
364 319d4050 2021-09-16 xhr cmd_resupply(char *cmd)
365 a5abbb50 2021-09-09 xhr {
366 a5abbb50 2021-09-09 xhr struct character *curchar = get_current_character();
367 a5abbb50 2021-09-09 xhr int ival[2] = { -1, -1 };
368 a5abbb50 2021-09-09 xhr int ret;
369 a5abbb50 2021-09-09 xhr
370 a5abbb50 2021-09-09 xhr if (curchar == NULL) {
371 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
372 a5abbb50 2021-09-09 xhr return;
373 a5abbb50 2021-09-09 xhr }
374 a5abbb50 2021-09-09 xhr
375 a5abbb50 2021-09-09 xhr ival[0] = curchar->wits;
376 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
377 a5abbb50 2021-09-09 xhr
378 a5abbb50 2021-09-09 xhr ret = action_roll(ival);
379 a5abbb50 2021-09-09 xhr if (ret == 8) { /* strong hit */
380 a5abbb50 2021-09-09 xhr change_char_value("momentum", INCREASE, 2);
381 a5abbb50 2021-09-09 xhr } else if (ret == 4) { /* weak hit */
382 a5abbb50 2021-09-09 xhr printf("Take up to +2 supply, but suffer -1 momentum for each\n");
383 2231141b 2021-09-09 xhr } else
384 60bf4095 2021-09-11 xhr printf("Pay the price -> Rulebook\n");
385 1c9cf51f 2021-09-09 xhr
386 1c9cf51f 2021-09-09 xhr }
387 1c9cf51f 2021-09-09 xhr
388 1c9cf51f 2021-09-09 xhr void
389 319d4050 2021-09-16 xhr cmd_make_camp(char *cmd)
390 7317e41e 2021-09-09 xhr {
391 7317e41e 2021-09-09 xhr struct character *curchar = get_current_character();
392 7317e41e 2021-09-09 xhr int ival[2] = { -1, -1 };
393 7317e41e 2021-09-09 xhr int ret;
394 7317e41e 2021-09-09 xhr
395 7317e41e 2021-09-09 xhr if (curchar == NULL) {
396 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
397 7317e41e 2021-09-09 xhr return;
398 7317e41e 2021-09-09 xhr }
399 7317e41e 2021-09-09 xhr
400 7317e41e 2021-09-09 xhr ival[0] = curchar->supply;
401 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
402 7317e41e 2021-09-09 xhr
403 7317e41e 2021-09-09 xhr ret = action_roll(ival);
404 7317e41e 2021-09-09 xhr if (ret == 8)
405 3501467d 2021-09-09 xhr printf("Choose two options-> Rulebook\n");
406 7317e41e 2021-09-09 xhr else if (ret == 4)
407 3501467d 2021-09-09 xhr printf("Choose one option-> Rulebook\n");
408 7317e41e 2021-09-09 xhr else
409 7317e41e 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
410 7317e41e 2021-09-09 xhr }
411 7317e41e 2021-09-09 xhr
412 7317e41e 2021-09-09 xhr void
413 1c9cf51f 2021-09-09 xhr cmd_face_danger(char *stat)
414 1c9cf51f 2021-09-09 xhr {
415 1c9cf51f 2021-09-09 xhr struct character *curchar = get_current_character();
416 1c9cf51f 2021-09-09 xhr int ival[2] = { -1, -1 };
417 1c9cf51f 2021-09-09 xhr int ret;
418 1c9cf51f 2021-09-09 xhr
419 1c9cf51f 2021-09-09 xhr if (curchar == NULL) {
420 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
421 1c9cf51f 2021-09-09 xhr return;
422 1c9cf51f 2021-09-09 xhr }
423 1c9cf51f 2021-09-09 xhr
424 1c9cf51f 2021-09-09 xhr if (strlen(stat) == 0) {
425 1c9cf51f 2021-09-09 xhr info:
426 1c9cf51f 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
427 1c9cf51f 2021-09-09 xhr printf("edge\t- Act with speed, agility, or precision\n");
428 1c9cf51f 2021-09-09 xhr printf("heart\t- Act with charm, loyalty, or courage\n");
429 1c9cf51f 2021-09-09 xhr printf("iron\t- Act with aggressive action, forceful defense, strength\n");
430 1c9cf51f 2021-09-09 xhr printf("shadow\t- Act with deception, stealth, or trickery\n");
431 1c9cf51f 2021-09-09 xhr printf("wits\t- Act with expertise, insight, or observation\n\n");
432 1c9cf51f 2021-09-09 xhr printf("Example: facedanger iron\n");
433 1c9cf51f 2021-09-09 xhr return;
434 a5abbb50 2021-09-09 xhr }
435 a5abbb50 2021-09-09 xhr
436 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
437 1c9cf51f 2021-09-09 xhr ival[0] = curchar->iron;
438 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "wits") == 0) {
439 1c9cf51f 2021-09-09 xhr ival[0] = curchar->wits;
440 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "edge") == 0) {
441 1c9cf51f 2021-09-09 xhr ival[0] = curchar->edge;
442 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
443 1c9cf51f 2021-09-09 xhr ival[0] = curchar->shadow;
444 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
445 1c9cf51f 2021-09-09 xhr ival[0] = curchar->heart;
446 1c9cf51f 2021-09-09 xhr } else
447 1c9cf51f 2021-09-09 xhr goto info;
448 1c9cf51f 2021-09-09 xhr
449 1c9cf51f 2021-09-09 xhr ret = action_roll(ival);
450 1c9cf51f 2021-09-09 xhr if (ret == 8) /* strong hit */
451 1c9cf51f 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
452 1c9cf51f 2021-09-09 xhr else if (ret == 4) /* weak hit */
453 1c9cf51f 2021-09-09 xhr printf("Face a troublesome cost -> Rulebook\n");
454 2231141b 2021-09-09 xhr else
455 dab8f6b9 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
456 dab8f6b9 2021-09-09 xhr }
457 dab8f6b9 2021-09-09 xhr
458 dab8f6b9 2021-09-09 xhr void
459 ad0031e7 2021-09-16 xhr cmd_compel(char *cmd)
460 dab8f6b9 2021-09-09 xhr {
461 dab8f6b9 2021-09-09 xhr struct character *curchar = get_current_character();
462 ad0031e7 2021-09-16 xhr char stat[MAX_STAT_LEN];
463 dab8f6b9 2021-09-09 xhr int ival[2] = { -1, -1 };
464 dab8f6b9 2021-09-09 xhr int ret;
465 dab8f6b9 2021-09-09 xhr
466 dab8f6b9 2021-09-09 xhr if (curchar == NULL) {
467 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
468 dab8f6b9 2021-09-09 xhr return;
469 dab8f6b9 2021-09-09 xhr }
470 dab8f6b9 2021-09-09 xhr
471 ad0031e7 2021-09-16 xhr ret = get_args_from_cmd(cmd, stat, &ival[1]);
472 219a93cc 2021-09-16 xhr if (ret >= 10) {
473 dab8f6b9 2021-09-09 xhr info:
474 dab8f6b9 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
475 dab8f6b9 2021-09-09 xhr printf("heart\t- You charm, pacify, barter, or convince\n");
476 dab8f6b9 2021-09-09 xhr printf("iron\t- You threaten or incite\n");
477 dab8f6b9 2021-09-09 xhr printf("shadow\t- You lie or swindle\n");
478 dab8f6b9 2021-09-09 xhr printf("Example: compel iron\n");
479 dab8f6b9 2021-09-09 xhr return;
480 ad0031e7 2021-09-16 xhr } else if (ret <= -20)
481 ad0031e7 2021-09-16 xhr return;
482 dab8f6b9 2021-09-09 xhr
483 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
484 dab8f6b9 2021-09-09 xhr ival[0] = curchar->iron;
485 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
486 dab8f6b9 2021-09-09 xhr ival[0] = curchar->shadow;
487 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
488 dab8f6b9 2021-09-09 xhr ival[0] = curchar->heart;
489 dab8f6b9 2021-09-09 xhr } else
490 dab8f6b9 2021-09-09 xhr goto info;
491 dab8f6b9 2021-09-09 xhr
492 dab8f6b9 2021-09-09 xhr ret = action_roll(ival);
493 dab8f6b9 2021-09-09 xhr if (ret == 8) {
494 dab8f6b9 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
495 dab8f6b9 2021-09-09 xhr printf("You might get +1 for your next move -> Rulebook\n");
496 dab8f6b9 2021-09-09 xhr } else if (ret == 4) {
497 dab8f6b9 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
498 dab8f6b9 2021-09-09 xhr printf("You might be asked for something in return -> Rulebook\n");
499 1edc302f 2021-09-09 xhr } else
500 1edc302f 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
501 1edc302f 2021-09-09 xhr }
502 1edc302f 2021-09-09 xhr
503 1edc302f 2021-09-09 xhr void
504 ad0031e7 2021-09-16 xhr cmd_secure_an_advantage(char *cmd)
505 5f0cab5f 2021-09-09 xhr {
506 5f0cab5f 2021-09-09 xhr struct character *curchar = get_current_character();
507 ad0031e7 2021-09-16 xhr char stat[MAX_STAT_LEN];
508 5f0cab5f 2021-09-09 xhr int ival[2] = { -1, -1 };
509 5f0cab5f 2021-09-09 xhr int ret;
510 5f0cab5f 2021-09-09 xhr
511 5f0cab5f 2021-09-09 xhr if (curchar == NULL) {
512 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
513 5f0cab5f 2021-09-09 xhr return;
514 5f0cab5f 2021-09-09 xhr }
515 5f0cab5f 2021-09-09 xhr
516 ad0031e7 2021-09-16 xhr ret = get_args_from_cmd(cmd, stat, &ival[1]);
517 219a93cc 2021-09-16 xhr if (ret >= 10) {
518 5f0cab5f 2021-09-09 xhr info:
519 5f0cab5f 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
520 5f0cab5f 2021-09-09 xhr printf("edge\t- Act with speed, agility, or precision\n");
521 5f0cab5f 2021-09-09 xhr printf("heart\t- Act with charm, loyalty, or courage\n");
522 5f0cab5f 2021-09-09 xhr printf("iron\t- Act with aggressive action, forceful defense, strength\n");
523 5f0cab5f 2021-09-09 xhr printf("shadow\t- Act with deception, stealth, or trickery\n");
524 5f0cab5f 2021-09-09 xhr printf("wits\t- Act with expertise, insight, or observation\n\n");
525 5f0cab5f 2021-09-09 xhr printf("Example: secureanadvantage iron\n");
526 5f0cab5f 2021-09-09 xhr return;
527 ad0031e7 2021-09-16 xhr } else if (ret <= -20)
528 ad0031e7 2021-09-16 xhr return;
529 5f0cab5f 2021-09-09 xhr
530 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
531 5f0cab5f 2021-09-09 xhr ival[0] = curchar->iron;
532 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "wits") == 0) {
533 5f0cab5f 2021-09-09 xhr ival[0] = curchar->wits;
534 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "edge") == 0) {
535 5f0cab5f 2021-09-09 xhr ival[0] = curchar->edge;
536 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
537 5f0cab5f 2021-09-09 xhr ival[0] = curchar->shadow;
538 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
539 5f0cab5f 2021-09-09 xhr ival[0] = curchar->heart;
540 5f0cab5f 2021-09-09 xhr } else
541 5f0cab5f 2021-09-09 xhr goto info;
542 5f0cab5f 2021-09-09 xhr
543 5f0cab5f 2021-09-09 xhr ret = action_roll(ival);
544 5f0cab5f 2021-09-09 xhr if (ret == 8)
545 5f0cab5f 2021-09-09 xhr printf("Gain an advantage -> Rulebook\n");
546 5f0cab5f 2021-09-09 xhr else if (ret == 4)
547 5f0cab5f 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
548 2231141b 2021-09-09 xhr else
549 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
550 a5abbb50 2021-09-09 xhr }
551 a5abbb50 2021-09-09 xhr
552 a5abbb50 2021-09-09 xhr void
553 a844ca20 2021-09-05 xhr cmd_roll_challenge_die(__attribute__((unused)) char *unused)
554 63354cc5 2021-09-01 xhr {
555 8f2dede1 2021-09-02 xhr printf("%ld\n", roll_challenge_die());
556 63354cc5 2021-09-01 xhr }
557 63354cc5 2021-09-01 xhr
558 63354cc5 2021-09-01 xhr void
559 a844ca20 2021-09-05 xhr cmd_roll_oracle_die(__attribute__((unused)) char *unused)
560 63354cc5 2021-09-01 xhr {
561 8f2dede1 2021-09-02 xhr printf("%ld\n", roll_oracle_die());
562 63354cc5 2021-09-01 xhr }
563 63354cc5 2021-09-01 xhr
564 63354cc5 2021-09-01 xhr long
565 8f2dede1 2021-09-02 xhr roll_action_die()
566 63354cc5 2021-09-01 xhr {
567 63354cc5 2021-09-01 xhr long ret = random() % 6;
568 63354cc5 2021-09-01 xhr
569 63354cc5 2021-09-01 xhr return ret == 0 ? 6 : ret;
570 63354cc5 2021-09-01 xhr }
571 63354cc5 2021-09-01 xhr
572 63354cc5 2021-09-01 xhr long
573 8f2dede1 2021-09-02 xhr roll_challenge_die()
574 63354cc5 2021-09-01 xhr {
575 63354cc5 2021-09-01 xhr return random() % 10;
576 63354cc5 2021-09-01 xhr }
577 63354cc5 2021-09-01 xhr
578 63354cc5 2021-09-01 xhr long
579 8f2dede1 2021-09-02 xhr roll_oracle_die()
580 63354cc5 2021-09-01 xhr {
581 63354cc5 2021-09-01 xhr return random() % 100;
582 63354cc5 2021-09-01 xhr }
583 63354cc5 2021-09-01 xhr
584 63354cc5 2021-09-01 xhr void
585 63354cc5 2021-09-01 xhr cmd_yes_or_no(char *args)
586 63354cc5 2021-09-01 xhr {
587 63354cc5 2021-09-01 xhr int num = atoi(args);
588 1e9e9b0b 2021-09-01 xhr int i;
589 63354cc5 2021-09-01 xhr
590 1e9e9b0b 2021-09-01 xhr log_debug("Argument %d\n", num);
591 63354cc5 2021-09-01 xhr if (num <= 0 || num > 5) {
592 1e9e9b0b 2021-09-01 xhr printf("Provide a number between 1-5 as argument, i.e. yesorno 2\n\n");
593 1e9e9b0b 2021-09-01 xhr for (i=0; odds[i] != NULL; i++)
594 1e9e9b0b 2021-09-01 xhr printf("%d - %s\n", i+1, odds[i]);
595 1e9e9b0b 2021-09-01 xhr
596 63354cc5 2021-09-01 xhr return;
597 63354cc5 2021-09-01 xhr }
598 63354cc5 2021-09-01 xhr
599 63354cc5 2021-09-01 xhr yes_or_no(num);
600 63354cc5 2021-09-01 xhr }
601 63354cc5 2021-09-01 xhr
602 63354cc5 2021-09-01 xhr void
603 63354cc5 2021-09-01 xhr yes_or_no(int num)
604 63354cc5 2021-09-01 xhr {
605 63354cc5 2021-09-01 xhr long a1, c1, c2;
606 63354cc5 2021-09-01 xhr
607 8f2dede1 2021-09-02 xhr a1 = roll_challenge_die();
608 8f2dede1 2021-09-02 xhr c2 = roll_challenge_die();
609 63354cc5 2021-09-01 xhr c1 = (a1 * 10) + c2;
610 63354cc5 2021-09-01 xhr
611 63354cc5 2021-09-01 xhr if (a1 == c2)
612 d12dcdd5 2021-09-05 xhr printf("W10: match %ld -> ", a1);
613 63354cc5 2021-09-01 xhr else {
614 d12dcdd5 2021-09-05 xhr printf("W10: %ld, %ld -> ", a1, c2);
615 63354cc5 2021-09-01 xhr }
616 63354cc5 2021-09-01 xhr
617 63354cc5 2021-09-01 xhr if (num == 1 && c1 >= 11)
618 63354cc5 2021-09-01 xhr printf("yes\n");
619 63354cc5 2021-09-01 xhr else if (num == 2 && c1 >= 26)
620 63354cc5 2021-09-01 xhr printf("yes\n");
621 63354cc5 2021-09-01 xhr else if (num == 3 && c1 >= 51)
622 63354cc5 2021-09-01 xhr printf("yes\n");
623 63354cc5 2021-09-01 xhr else if (num == 4 && c1 >= 76)
624 63354cc5 2021-09-01 xhr printf("yes\n");
625 63354cc5 2021-09-01 xhr else if (num == 5 && c1 >= 91)
626 63354cc5 2021-09-01 xhr printf("yes\n");
627 63354cc5 2021-09-01 xhr else
628 63354cc5 2021-09-01 xhr printf("no\n");
629 63354cc5 2021-09-01 xhr }
630 63354cc5 2021-09-01 xhr
631 04d8c7d3 2021-09-08 xhr int
632 d548c131 2021-09-02 xhr action_roll(int args[2])
633 63354cc5 2021-09-01 xhr {
634 d548c131 2021-09-02 xhr long c1, c2, a1, b;
635 04d8c7d3 2021-09-08 xhr int ret = 0;
636 63354cc5 2021-09-01 xhr
637 d548c131 2021-09-02 xhr log_debug("Action args: %d, %d\n", args[0], args[1]);
638 63354cc5 2021-09-01 xhr
639 64d52bc9 2021-09-16 xhr if (args[0] == -1) {
640 d548c131 2021-09-02 xhr log_errx(1, "No attribute value provided. This should not happen!");
641 64d52bc9 2021-09-16 xhr }
642 d548c131 2021-09-02 xhr
643 8f2dede1 2021-09-02 xhr a1 = b = roll_action_die();
644 d548c131 2021-09-02 xhr /* Add attribute and maybe a bonus value */
645 d548c131 2021-09-02 xhr b += args[0];
646 d548c131 2021-09-02 xhr if (args[1] != -1)
647 d548c131 2021-09-02 xhr b += args[1];
648 d548c131 2021-09-02 xhr
649 d548c131 2021-09-02 xhr if (args[1] == -1)
650 d12dcdd5 2021-09-05 xhr printf("D6: %ld+%d=%ld ", a1, args[0], b);
651 d548c131 2021-09-02 xhr else
652 d12dcdd5 2021-09-05 xhr printf("D6: %ld+%d+%d=%ld ", a1, args[0], args[1], b);
653 d548c131 2021-09-02 xhr
654 8f2dede1 2021-09-02 xhr c1 = roll_challenge_die();
655 8f2dede1 2021-09-02 xhr c2 = roll_challenge_die();
656 d548c131 2021-09-02 xhr c1 = (c1 == 0 ? 10 : c1);
657 d548c131 2021-09-02 xhr c2 = (c2 == 0 ? 10 : c2);
658 63354cc5 2021-09-01 xhr
659 63354cc5 2021-09-01 xhr if (c1 == c2) {
660 d12dcdd5 2021-09-05 xhr printf("D10: %ld match -> ", c1);
661 63354cc5 2021-09-01 xhr } else {
662 d12dcdd5 2021-09-05 xhr printf("D10: %ld, %ld -> ", c1, c2);
663 63354cc5 2021-09-01 xhr }
664 63354cc5 2021-09-01 xhr
665 04d8c7d3 2021-09-08 xhr if (b <= c1 && b <= c2) {
666 af92ffb1 2021-09-15 xhr pm(RED, "miss\n");
667 04d8c7d3 2021-09-08 xhr ret = 2;
668 04d8c7d3 2021-09-08 xhr } else if (b <= c1 || b <= c2) {
669 af92ffb1 2021-09-15 xhr pm(YELLOW, "weak hit\n");
670 04d8c7d3 2021-09-08 xhr ret = 4;
671 04d8c7d3 2021-09-08 xhr } else if (b > c1 && b > c2) {
672 af92ffb1 2021-09-15 xhr pm(GREEN, "strong hit\n");
673 04d8c7d3 2021-09-08 xhr ret = 8;
674 04d8c7d3 2021-09-08 xhr }
675 04d8c7d3 2021-09-08 xhr
676 04d8c7d3 2021-09-08 xhr return ret;
677 63354cc5 2021-09-01 xhr }
678 63354cc5 2021-09-01 xhr
679 60bf4095 2021-09-11 xhr int
680 319d4050 2021-09-16 xhr progress_roll(double args[2])
681 60bf4095 2021-09-11 xhr {
682 319d4050 2021-09-16 xhr double b;
683 60bf4095 2021-09-11 xhr long c1, c2;
684 60bf4095 2021-09-11 xhr int ret = 0;
685 60bf4095 2021-09-11 xhr
686 319d4050 2021-09-16 xhr if (args[0] == -1) {
687 319d4050 2021-09-16 xhr log_errx(1, "No attribute value provided. This should not happen!");
688 319d4050 2021-09-16 xhr }
689 319d4050 2021-09-16 xhr
690 60bf4095 2021-09-11 xhr c1 = roll_challenge_die();
691 60bf4095 2021-09-11 xhr c2 = roll_challenge_die();
692 60bf4095 2021-09-11 xhr c1 = (c1 == 0 ? 10 : c1);
693 60bf4095 2021-09-11 xhr c2 = (c2 == 0 ? 10 : c2);
694 60bf4095 2021-09-11 xhr
695 319d4050 2021-09-16 xhr log_debug("args[0] %.2lf args[1] %.2lf\n", args[0], args[1]);
696 319d4050 2021-09-16 xhr
697 319d4050 2021-09-16 xhr b = args[0];
698 319d4050 2021-09-16 xhr if (args[1] != -1)
699 319d4050 2021-09-16 xhr b += args[1];
700 319d4050 2021-09-16 xhr
701 319d4050 2021-09-16 xhr if (c1 == c2) {
702 319d4050 2021-09-16 xhr printf("D10: %ld match vs ", c1);
703 60bf4095 2021-09-11 xhr } else {
704 319d4050 2021-09-16 xhr printf("D10: %ld, %ld vs ", c1, c2);
705 60bf4095 2021-09-11 xhr }
706 60bf4095 2021-09-11 xhr
707 319d4050 2021-09-16 xhr printf("Progress: %.2lf -> ", b);
708 319d4050 2021-09-16 xhr
709 60bf4095 2021-09-11 xhr if (b <= c1 && b <= c2) {
710 af92ffb1 2021-09-15 xhr pm(RED, "miss\n");
711 60bf4095 2021-09-11 xhr ret = 2;
712 60bf4095 2021-09-11 xhr } else if (b <= c1 || b <= c2) {
713 af92ffb1 2021-09-15 xhr pm(YELLOW, "weak hit\n");
714 60bf4095 2021-09-11 xhr ret = 4;
715 60bf4095 2021-09-11 xhr } else if (b > c1 && b > c2) {
716 af92ffb1 2021-09-15 xhr pm(GREEN, "strong hit\n");
717 60bf4095 2021-09-11 xhr ret = 8;
718 60bf4095 2021-09-11 xhr }
719 60bf4095 2021-09-11 xhr
720 60bf4095 2021-09-11 xhr return ret;
721 60bf4095 2021-09-11 xhr }
722 60bf4095 2021-09-11 xhr
723 319d4050 2021-09-16 xhr int
724 319d4050 2021-09-16 xhr get_int_from_cmd(const char *cmd)
725 319d4050 2021-09-16 xhr {
726 319d4050 2021-09-16 xhr char *ep;
727 319d4050 2021-09-16 xhr long lval;
728 319d4050 2021-09-16 xhr int ival = -1;
729 319d4050 2021-09-16 xhr
730 319d4050 2021-09-16 xhr if (strlen(cmd) > 0) {
731 319d4050 2021-09-16 xhr errno = 0;
732 319d4050 2021-09-16 xhr lval = strtol(cmd, &ep, 10);
733 319d4050 2021-09-16 xhr if (cmd[0] == '\0' || *ep != '\0') {
734 319d4050 2021-09-16 xhr printf("Please provide a number as argument\n");
735 319d4050 2021-09-16 xhr return ival;
736 319d4050 2021-09-16 xhr }
737 319d4050 2021-09-16 xhr if ((errno == ERANGE || lval <= 0 || lval > 10)) {
738 319d4050 2021-09-16 xhr printf("Please provide a number between 1 and 10\n");
739 319d4050 2021-09-16 xhr return ival;
740 319d4050 2021-09-16 xhr }
741 319d4050 2021-09-16 xhr
742 319d4050 2021-09-16 xhr ival = lval;
743 319d4050 2021-09-16 xhr log_debug("Arg provided %d\n", ival);
744 319d4050 2021-09-16 xhr }
745 319d4050 2021-09-16 xhr
746 319d4050 2021-09-16 xhr return ival;
747 319d4050 2021-09-16 xhr }
748 c0c6ae4a 2021-09-16 xhr
749 c0c6ae4a 2021-09-16 xhr int
750 c0c6ae4a 2021-09-16 xhr get_args_from_cmd(char *cmd, char *stat, int *ival)
751 c0c6ae4a 2021-09-16 xhr {
752 c0c6ae4a 2021-09-16 xhr char *tokens[MAXTOKENS];
753 c0c6ae4a 2021-09-16 xhr char *ep;
754 c0c6ae4a 2021-09-16 xhr char *p, *last;
755 c0c6ae4a 2021-09-16 xhr int i = 0;
756 c0c6ae4a 2021-09-16 xhr long lval = -1;
757 c0c6ae4a 2021-09-16 xhr
758 c0c6ae4a 2021-09-16 xhr /* Parse the argument line into max tokens, separated by space */
759 c0c6ae4a 2021-09-16 xhr for ((p = strtok_r(cmd, " ", &last)); p;
760 c0c6ae4a 2021-09-16 xhr (p = strtok_r(NULL, " ", &last))) {
761 c0c6ae4a 2021-09-16 xhr if (i < MAXTOKENS - 1)
762 c0c6ae4a 2021-09-16 xhr tokens[i++] = p;
763 c0c6ae4a 2021-09-16 xhr }
764 c0c6ae4a 2021-09-16 xhr tokens[i] = NULL;
765 319d4050 2021-09-16 xhr
766 c0c6ae4a 2021-09-16 xhr /* First token is a stat */
767 c0c6ae4a 2021-09-16 xhr i = 0;
768 c0c6ae4a 2021-09-16 xhr if (tokens[i] == NULL)
769 219a93cc 2021-09-16 xhr return 10;
770 c0c6ae4a 2021-09-16 xhr else if (strlen(tokens[i]) == 0)
771 219a93cc 2021-09-16 xhr return 11;
772 c0c6ae4a 2021-09-16 xhr
773 c0c6ae4a 2021-09-16 xhr log_debug("stat token: %s\n", tokens[i]);
774 c0c6ae4a 2021-09-16 xhr snprintf(stat, MAX_STAT_LEN, "%s", tokens[i]);
775 c0c6ae4a 2021-09-16 xhr
776 c0c6ae4a 2021-09-16 xhr /* Second token is a bonus value*/
777 c0c6ae4a 2021-09-16 xhr errno = 0;
778 c0c6ae4a 2021-09-16 xhr i++;
779 c0c6ae4a 2021-09-16 xhr /* It's OK to have no bonus, so the token can be NULL and we can return */
780 c0c6ae4a 2021-09-16 xhr if (tokens[i] == NULL)
781 c0c6ae4a 2021-09-16 xhr return 0;
782 c0c6ae4a 2021-09-16 xhr else
783 c0c6ae4a 2021-09-16 xhr log_debug("bonus token: %s\n", tokens[i]);
784 c0c6ae4a 2021-09-16 xhr
785 c0c6ae4a 2021-09-16 xhr lval = strtol(tokens[i], &ep, 10);
786 c0c6ae4a 2021-09-16 xhr if (cmd[0] == '\0' || *ep != '\0') {
787 c0c6ae4a 2021-09-16 xhr printf("Please provide a number as argument\n");
788 c0c6ae4a 2021-09-16 xhr return -20;
789 c0c6ae4a 2021-09-16 xhr }
790 c0c6ae4a 2021-09-16 xhr if ((errno == ERANGE || lval <= 0 || lval > 10)) {
791 c0c6ae4a 2021-09-16 xhr printf("Please provide a number between 1 and 10\n");
792 c0c6ae4a 2021-09-16 xhr return -22;
793 c0c6ae4a 2021-09-16 xhr }
794 c0c6ae4a 2021-09-16 xhr *ival = lval;
795 c0c6ae4a 2021-09-16 xhr
796 c0c6ae4a 2021-09-16 xhr return 0;
797 c0c6ae4a 2021-09-16 xhr }