MCPcopy Create free account
hub / github.com/NetHack/NetHack / maybe_write_ls

Function maybe_write_ls

src/light.c:570–603  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

568 * the light source out.
569 */
570staticfn int
571maybe_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
605void
606light_sources_sanity_check(void)

Callers 1

save_light_sourcesFunction · 0.85

Calls 4

obj_is_localFunction · 0.85
mon_is_localFunction · 0.85
write_lsFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected