… | |
… | |
160 | * The args are num D size (ie 4d6) [garbled 20010916] |
160 | * The args are num D size (ie 4d6) [garbled 20010916] |
161 | */ |
161 | */ |
162 | int |
162 | int |
163 | die_roll (int num, int size, const object *op, int goodbad) |
163 | die_roll (int num, int size, const object *op, int goodbad) |
164 | { |
164 | { |
165 | int min, luck, total, i, gotlucky; |
165 | int min_roll, luck, total, i, gotlucky; |
166 | |
166 | |
167 | int diff = size; |
167 | int diff = size; |
168 | min = 1; |
168 | min_roll = 1; |
169 | luck = total = gotlucky = 0; |
169 | luck = total = gotlucky = 0; |
170 | int base = diff > 2 ? 20 : 50; /* d2 and d3 are corner cases */ |
170 | int base = diff > 2 ? 20 : 50; /* d2 and d3 are corner cases */ |
171 | |
171 | |
172 | if (size < 2 || diff < 1) |
172 | if (size < 2 || diff < 1) |
173 | { |
173 | { |
… | |
… | |
178 | if (op->type == PLAYER) |
178 | if (op->type == PLAYER) |
179 | luck = op->stats.luck; |
179 | luck = op->stats.luck; |
180 | |
180 | |
181 | for (i = 0; i < num; i++) |
181 | for (i = 0; i < num; i++) |
182 | { |
182 | { |
183 | if (rndm (base) < MIN (10, abs (luck)) && !gotlucky) |
183 | if (rndm (base) < min (10, abs (luck)) && !gotlucky) |
184 | { |
184 | { |
185 | /* we have a winner */ |
185 | /* we have a winner */ |
186 | gotlucky++; |
186 | gotlucky++; |
187 | ((luck > 0) ? (luck = 1) : (luck = -1)); |
187 | ((luck > 0) ? (luck = 1) : (luck = -1)); |
188 | diff -= luck; |
188 | diff -= luck; |
189 | if (diff < 1) |
189 | if (diff < 1) |
190 | return (num); /*check again */ |
190 | return (num); /*check again */ |
191 | ((goodbad) ? (min += luck) : (diff)); |
191 | ((goodbad) ? (min_roll += luck) : (diff)); |
192 | total += MAX (1, MIN (size, rndm (diff) + min)); |
192 | total += max (1, min (size, rndm (diff) + min_roll)); |
193 | } |
193 | } |
194 | else |
194 | else |
195 | total += rndm (size) + 1; |
195 | total += rndm (size) + 1; |
196 | } |
196 | } |
197 | |
197 | |
… | |
… | |
233 | } |
233 | } |
234 | |
234 | |
235 | return path; |
235 | return path; |
236 | } |
236 | } |
237 | |
237 | |
238 | void |
238 | static void |
239 | path_normalize (char *path) |
239 | path_normalize (char *path) |
240 | { |
240 | { |
241 | char *p; /* points to the beginning of the path not yet processed; this is |
241 | char *p; /* points to the beginning of the path not yet processed; this is |
242 | either a path component or a path separator character */ |
242 | either a path component or a path separator character */ |
243 | char *q; /* points to the end of the path component p points to */ |
243 | char *q; /* points to the end of the path component p points to */ |
… | |
… | |
314 | path = path_combine (src, dst); |
314 | path = path_combine (src, dst); |
315 | path_normalize (path); |
315 | path_normalize (path); |
316 | return (path); |
316 | return (path); |
317 | } |
317 | } |
318 | |
318 | |
319 | char * |
|
|
320 | strcasestr_local (const char *s, const char *find) |
|
|
321 | { |
|
|
322 | char c, sc; |
|
|
323 | size_t len; |
|
|
324 | |
|
|
325 | if ((c = *find++) != 0) |
|
|
326 | { |
|
|
327 | c = tolower (c); |
|
|
328 | len = strlen (find); |
|
|
329 | do |
|
|
330 | { |
|
|
331 | do |
|
|
332 | { |
|
|
333 | if ((sc = *s++) == 0) |
|
|
334 | return NULL; |
|
|
335 | } |
|
|
336 | while (tolower (sc) != c); |
|
|
337 | } |
|
|
338 | while (strncasecmp (s, find, len) != 0); |
|
|
339 | s--; |
|
|
340 | } |
|
|
341 | return (char *) s; |
|
|
342 | } |
|
|
343 | |
|
|
344 | /** |
319 | /** |
345 | * open_and_uncompress() first searches for the original filename. If it exist, |
320 | * open_and_uncompress() first searches for the original filename. If it exist, |
346 | * then it opens it and returns the file-pointer. |
321 | * then it opens it and returns the file-pointer. |
347 | */ |
322 | */ |
348 | FILE * |
323 | FILE * |
… | |
… | |
388 | dest++; |
363 | dest++; |
389 | } |
364 | } |
390 | src++; |
365 | src++; |
391 | } |
366 | } |
392 | *dest = '\0'; |
367 | *dest = '\0'; |
393 | } |
|
|
394 | |
|
|
395 | const char * |
|
|
396 | strrstr (const char *haystack, const char *needle) |
|
|
397 | { |
|
|
398 | const char *lastneedle; |
|
|
399 | |
|
|
400 | lastneedle = NULL; |
|
|
401 | while ((haystack = strstr (haystack, needle)) != NULL) |
|
|
402 | { |
|
|
403 | lastneedle = haystack; |
|
|
404 | haystack++; |
|
|
405 | } |
|
|
406 | return lastneedle; |
|
|
407 | |
|
|
408 | } |
368 | } |
409 | |
369 | |
410 | #define EOL_SIZE (sizeof("\n")-1) |
370 | #define EOL_SIZE (sizeof("\n")-1) |
411 | void |
371 | void |
412 | strip_endline (char *buf) |
372 | strip_endline (char *buf) |