… | |
… | |
200 | } |
200 | } |
201 | |
201 | |
202 | /* convert materialname to materialtype_t */ |
202 | /* convert materialname to materialtype_t */ |
203 | |
203 | |
204 | materialtype_t * |
204 | materialtype_t * |
205 | name_to_material (const shstr &name) |
205 | name_to_material (const shstr_cmp name) |
206 | { |
206 | { |
207 | for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next) |
207 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
208 | if (name == mt->name) |
208 | if (name == mt->name) |
209 | return mt; |
209 | return mt; |
210 | |
210 | |
211 | return 0; |
211 | return 0; |
212 | } |
212 | } |
… | |
… | |
218 | transmute_materialname (object *op, const object *change) |
218 | transmute_materialname (object *op, const object *change) |
219 | { |
219 | { |
220 | materialtype_t *mt; |
220 | materialtype_t *mt; |
221 | int j; |
221 | int j; |
222 | |
222 | |
223 | if (op->materialname == NULL) |
223 | if (!op->materialname) |
224 | return; |
224 | return; |
225 | |
225 | |
226 | if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) |
226 | if (change->materialname && strcmp (op->materialname, change->materialname)) |
227 | return; |
227 | return; |
228 | |
228 | |
229 | if (!op->is_armor ()) |
229 | if (!op->is_armor ()) |
230 | return; |
230 | return; |
231 | |
231 | |
… | |
… | |
251 | void |
251 | void |
252 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
252 | set_materialname (object *op, int difficulty, materialtype_t *nmt) |
253 | { |
253 | { |
254 | materialtype_t *mt, *lmt; |
254 | materialtype_t *mt, *lmt; |
255 | |
255 | |
256 | if (op->materialname != NULL) |
256 | if (!op->materialname) |
257 | return; |
257 | return; |
258 | |
258 | |
259 | if (nmt == NULL) |
259 | if (nmt) |
|
|
260 | lmt = nmt; |
|
|
261 | else |
260 | { |
262 | { |
261 | lmt = NULL; |
263 | lmt = 0; |
262 | |
264 | |
263 | for (mt = materialt; mt && mt->next; mt = mt->next) |
265 | for (mt = materialt; mt; mt = mt->next) |
264 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
266 | if (op->materials & mt->material && rndm (1, 100) <= mt->chance && |
265 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
267 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
266 | { |
268 | { |
267 | lmt = mt; |
269 | lmt = mt; |
268 | if (!(op->is_weapon () || op->is_armor ())) |
270 | if (!(op->is_weapon () || op->is_armor ())) |
269 | break; |
271 | break; |
270 | } |
272 | } |
271 | } |
273 | } |
272 | else |
|
|
273 | lmt = nmt; |
|
|
274 | |
274 | |
275 | if (lmt != NULL) |
275 | if (lmt) |
276 | { |
276 | { |
277 | if (op->stats.dam && op->is_weapon ()) |
277 | if (op->stats.dam && op->is_weapon ()) |
278 | { |
278 | { |
279 | op->stats.dam += lmt->damage; |
279 | op->stats.dam += lmt->damage; |
280 | if (op->stats.dam < 1) |
280 | if (op->stats.dam < 1) |
… | |
… | |
453 | { |
453 | { |
454 | signal (SIGINT , SIG_IGN); |
454 | signal (SIGINT , SIG_IGN); |
455 | signal (SIGTERM, SIG_IGN); |
455 | signal (SIGTERM, SIG_IGN); |
456 | signal (SIGABRT, SIG_IGN); |
456 | signal (SIGABRT, SIG_IGN); |
457 | |
457 | |
|
|
458 | signal (SIGSEGV, SIG_DFL); |
|
|
459 | signal (SIGBUS , SIG_DFL); |
|
|
460 | signal (SIGILL , SIG_DFL); |
|
|
461 | signal (SIGTRAP, SIG_DFL); |
|
|
462 | |
458 | // try to put corefiles into a subdirectory, if existing, to allow |
463 | // try to put corefiles into a subdirectory, if existing, to allow |
459 | // an administrator to reduce the I/O load. |
464 | // an administrator to reduce the I/O load. |
460 | chdir ("cores"); |
465 | chdir ("cores"); |
461 | |
466 | |
462 | // try to detach us from as many external dependencies as possible |
467 | // try to detach us from as many external dependencies as possible |
… | |
… | |
469 | |
474 | |
470 | for (int i = 0; i < lim.rlim_cur; ++i) |
475 | for (int i = 0; i < lim.rlim_cur; ++i) |
471 | close (i); |
476 | close (i); |
472 | } |
477 | } |
473 | |
478 | |
|
|
479 | { |
|
|
480 | sigset_t empty; |
|
|
481 | sigemptyset (&empty); |
|
|
482 | sigprocmask (SIG_SETMASK, &empty, 0); |
|
|
483 | } |
|
|
484 | |
|
|
485 | // try to coredump with SIGTRAP |
|
|
486 | kill (getpid (), SIGTRAP); |
474 | abort (); |
487 | abort (); |
475 | } |
488 | } |
476 | |
489 | |
477 | LOG (llevError, "fork abort: %s\n", msg); |
490 | LOG (llevError, "fork abort: %s\n", msg); |
478 | } |
491 | } |