1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
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 | |
… | |
… | |
365 | src++; |
365 | src++; |
366 | } |
366 | } |
367 | *dest = '\0'; |
367 | *dest = '\0'; |
368 | } |
368 | } |
369 | |
369 | |
370 | const char * |
|
|
371 | strrstr (const char *haystack, const char *needle) |
|
|
372 | { |
|
|
373 | const char *lastneedle; |
|
|
374 | |
|
|
375 | lastneedle = NULL; |
|
|
376 | while ((haystack = strstr (haystack, needle)) != NULL) |
|
|
377 | { |
|
|
378 | lastneedle = haystack; |
|
|
379 | haystack++; |
|
|
380 | } |
|
|
381 | return lastneedle; |
|
|
382 | |
|
|
383 | } |
|
|
384 | |
|
|
385 | #define EOL_SIZE (sizeof("\n")-1) |
370 | #define EOL_SIZE (sizeof("\n")-1) |
386 | void |
371 | void |
387 | strip_endline (char *buf) |
372 | strip_endline (char *buf) |
388 | { |
373 | { |
389 | if (strlen (buf) < sizeof ("\n")) |
374 | if (strlen (buf) < sizeof ("\n")) |