… | |
… | |
51 | state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; |
51 | state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; |
52 | state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; |
52 | state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; |
53 | state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; |
53 | state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; |
54 | |
54 | |
55 | for (int i = 11; --i; ) |
55 | for (int i = 11; --i; ) |
56 | operator ()(); |
56 | next (); |
57 | } |
57 | } |
58 | |
58 | |
59 | uint32_t |
59 | uint32_t |
60 | tausworthe_random_generator::next () |
60 | tausworthe_random_generator::next () |
61 | { |
61 | { |
… | |
… | |
65 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
65 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
66 | |
66 | |
67 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
67 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
68 | } |
68 | } |
69 | |
69 | |
|
|
70 | template<class generator> |
70 | uint32_t |
71 | uint32_t |
71 | tausworthe_random_generator::get_range (uint32_t num) |
72 | random_number_generator<generator>::get_range (uint32_t num) |
72 | { |
73 | { |
73 | return (next () * (uint64_t)num) >> 32U; |
74 | return (this->next () * (uint64_t)num) >> 32U; |
74 | } |
75 | } |
75 | |
76 | |
76 | // return a number within (min .. max) |
77 | // return a number within (min .. max) |
|
|
78 | template<class generator> |
77 | int |
79 | int |
78 | tausworthe_random_generator::get_range (int r_min, int r_max) |
80 | random_number_generator<generator>::get_range (int r_min, int r_max) |
79 | { |
81 | { |
80 | return r_min + get_range (max (r_max - r_min + 1, 0)); |
82 | return r_min + get_range (max (r_max - r_min + 1, 0)); |
81 | } |
83 | } |
|
|
84 | |
|
|
85 | template struct random_number_generator<tausworthe_random_generator>; |
|
|
86 | template struct random_number_generator<xorshift_random_generator>; |
82 | |
87 | |
83 | /* |
88 | /* |
84 | * The random functions here take luck into account when rolling random |
89 | * The random functions here take luck into account when rolling random |
85 | * dice or numbers. This function has less of an impact the larger the |
90 | * dice or numbers. This function has less of an impact the larger the |
86 | * difference becomes in the random numbers. IE, the effect is lessened |
91 | * difference becomes in the random numbers. IE, the effect is lessened |
… | |
… | |
200 | } |
205 | } |
201 | |
206 | |
202 | /* convert materialname to materialtype_t */ |
207 | /* convert materialname to materialtype_t */ |
203 | |
208 | |
204 | materialtype_t * |
209 | materialtype_t * |
205 | name_to_material (const shstr &name) |
210 | name_to_material (const shstr_cmp name) |
206 | { |
211 | { |
207 | for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next) |
212 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
208 | if (name == mt->name) |
213 | if (name == mt->name) |
209 | return mt; |
214 | return mt; |
210 | |
215 | |
211 | return 0; |
216 | return 0; |
212 | } |
217 | } |
… | |
… | |
218 | transmute_materialname (object *op, const object *change) |
223 | transmute_materialname (object *op, const object *change) |
219 | { |
224 | { |
220 | materialtype_t *mt; |
225 | materialtype_t *mt; |
221 | int j; |
226 | int j; |
222 | |
227 | |
223 | if (op->materialname == NULL) |
228 | if (!op->materialname) |
224 | return; |
229 | return; |
225 | |
230 | |
226 | if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) |
231 | if (op->materialname != change->materialname) |
227 | return; |
232 | return; |
228 | |
233 | |
229 | if (!op->is_armor ()) |
234 | if (!op->is_armor ()) |
230 | return; |
235 | return; |
231 | |
236 | |
… | |
… | |
251 | void |
256 | void |
252 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
257 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
253 | { |
258 | { |
254 | materialtype_t *mt, *lmt; |
259 | materialtype_t *mt, *lmt; |
255 | |
260 | |
256 | if (op->materialname != NULL) |
261 | if (!op->materialname) |
257 | return; |
262 | return; |
258 | |
263 | |
259 | if (nmt == NULL) |
264 | if (nmt) |
|
|
265 | lmt = nmt; |
|
|
266 | else |
260 | { |
267 | { |
261 | lmt = NULL; |
268 | lmt = 0; |
262 | |
269 | |
263 | for (mt = materialt; mt && mt->next; mt = mt->next) |
270 | for (mt = materialt; mt; mt = mt->next) |
264 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
271 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
265 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
272 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
266 | { |
273 | { |
267 | lmt = mt; |
274 | lmt = mt; |
268 | if (!(op->is_weapon () || op->is_armor ())) |
275 | if (!(op->is_weapon () || op->is_armor ())) |
269 | break; |
276 | break; |
270 | } |
277 | } |
271 | } |
278 | } |
272 | else |
|
|
273 | lmt = nmt; |
|
|
274 | |
279 | |
275 | if (lmt != NULL) |
280 | if (lmt) |
276 | { |
281 | { |
277 | if (op->stats.dam && op->is_weapon ()) |
282 | if (op->stats.dam && op->is_weapon ()) |
278 | { |
283 | { |
279 | op->stats.dam += lmt->damage; |
284 | op->stats.dam += lmt->damage; |
280 | if (op->stats.dam < 1) |
285 | if (op->stats.dam < 1) |
… | |
… | |
449 | void |
454 | void |
450 | fork_abort (const char *msg) |
455 | fork_abort (const char *msg) |
451 | { |
456 | { |
452 | if (!fork ()) |
457 | if (!fork ()) |
453 | { |
458 | { |
454 | fprintf (stderr, "background fork_abort in progress, remove me when debugged.\n");//D |
|
|
455 | |
|
|
456 | signal (SIGINT , SIG_IGN); |
459 | signal (SIGINT , SIG_IGN); |
457 | signal (SIGTERM, SIG_IGN); |
460 | signal (SIGTERM, SIG_IGN); |
458 | signal (SIGABRT, SIG_IGN); |
461 | signal (SIGABRT, SIG_IGN); |
459 | |
462 | |
460 | signal (SIGSEGV, SIG_DFL); |
463 | signal (SIGSEGV, SIG_DFL); |