| 511 | } |
| 512 | |
| 513 | RESTORE_WARNING_FORMAT_NONLITERAL |
| 514 | |
| 515 | /* Relink all lights that are so marked. */ |
| 516 | void |
| 517 | relink_light_sources(boolean ghostly) |
| 518 | { |
| 519 | char which; |
| 520 | unsigned nid; |
| 521 | light_source *ls; |
| 522 | |
| 523 | /* |
| 524 | * Caveat: |
| 525 | * There has been at least one instance during to-be-5.0 development |
| 526 | * where the light_base linked list ended up with a circular link. |
| 527 | * If that happens, then once all the traversed elements have their |
| 528 | * LSF_NEEDS_FIXUP flag cleared, the traversal attempt will run wild. |
| 529 | * |
| 530 | * The circular list instance was blamed on attempting to restore |
| 531 | * a save file which should have been invalidated by version/patch/ |
| 532 | * editlevel verification, but wasn't rejected because EDITLEVEL |
| 533 | * didn't get incremented when it should have been. Valid data should |
| 534 | * never produce the problem and it isn't possible in general to guard |
| 535 | * against code updates that neglect to set the verification info up |
| 536 | * to date. |
| 537 | */ |
| 538 | |
| 539 | for (ls = gl.light_base; ls; ls = ls->next) { |
| 540 | if (ls->flags & LSF_NEEDS_FIXUP) { |
| 541 | if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { |
| 542 | nid = ls->id.a_uint; |
| 543 | if (ghostly && !lookup_id_mapping(nid, &nid)) |
| 544 | panic("relink_light_sources: no id mapping"); |
| 545 | |
| 546 | which = '\0'; |
| 547 | if (ls->type == LS_OBJECT) { |
| 548 | if ((ls->id.a_obj = find_oid(nid)) == 0) |
| 549 | which = 'o'; |
| 550 | } else { |
| 551 | if ((ls->id.a_monst = find_mid(nid, FM_EVERYWHERE)) == 0) |
| 552 | which = 'm'; |
| 553 | } |
| 554 | if (which != '\0') |
| 555 | panic("relink_light_sources: can't find %c_id %u", |
| 556 | which, nid); |
| 557 | } else { |
| 558 | panic("relink_light_sources: bad type (%d)", ls->type); |
| 559 | } |
| 560 | ls->flags &= ~LSF_NEEDS_FIXUP; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /* |
| 566 | * Part of the light source save routine. Count up the number of light |
no test coverage detected