* Part of the light source save routine. Count up the number of light * sources that would be written. If write_it is true, actually write * the light source out. */
| 568 | * the light source out. |
| 569 | */ |
| 570 | staticfn int |
| 571 | maybe_write_ls(NHFILE *nhfp, int range, boolean write_it) |
| 572 | { |
| 573 | int count = 0, is_global; |
| 574 | light_source *ls; |
| 575 | |
| 576 | for (ls = gl.light_base; ls; ls = ls->next) { |
| 577 | if (!ls->id.a_monst) { |
| 578 | impossible("maybe_write_ls: no id! [range=%d]", range); |
| 579 | continue; |
| 580 | } |
| 581 | switch (ls->type) { |
| 582 | case LS_OBJECT: |
| 583 | is_global = !obj_is_local(ls->id.a_obj); |
| 584 | break; |
| 585 | case LS_MONSTER: |
| 586 | is_global = !mon_is_local(ls->id.a_monst); |
| 587 | break; |
| 588 | default: |
| 589 | is_global = 0; |
| 590 | impossible("maybe_write_ls: bad type (%d) [range=%d]", ls->type, |
| 591 | range); |
| 592 | break; |
| 593 | } |
| 594 | /* if global and not doing local, or vice versa, count it */ |
| 595 | if (is_global ^ (range == RANGE_LEVEL)) { |
| 596 | count++; |
| 597 | if (write_it) |
| 598 | write_ls(nhfp, ls); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return count; |
| 603 | } |
| 604 | |
| 605 | void |
| 606 | light_sources_sanity_check(void) |
no test coverage detected