diff --git a/include/extern.h b/include/extern.h index bd22f7826..22df5471b 100644 --- a/include/extern.h +++ b/include/extern.h @@ -971,6 +971,7 @@ E struct monst *FDECL(find_mid, (unsigned, unsigned)); E void FDECL(save_light_sources, (int, int, int)); E void FDECL(restore_light_sources, (int)); E void FDECL(relink_light_sources, (BOOLEAN_P)); +E void NDECL(light_sources_sanity_check); E void FDECL(obj_move_light_source, (struct obj *, struct obj *)); E boolean NDECL(any_light_source); E void FDECL(snuff_light_source, (int, int)); diff --git a/src/cmd.c b/src/cmd.c index ee37e94b6..6cf2363a3 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -3069,6 +3069,7 @@ sanity_check() obj_sanity_check(); timer_sanity_check(); mon_sanity_check(); + light_sources_sanity_check(); } #ifdef DEBUG_MIGRATING_MONS diff --git a/src/light.c b/src/light.c index a0961315b..7f2f6355b 100644 --- a/src/light.c +++ b/src/light.c @@ -383,6 +383,31 @@ boolean write_it; return count; } +void +light_sources_sanity_check() +{ + light_source *ls; + unsigned int auint; + + for (ls = light_base; ls; ls = ls->next) { + if (!ls->id.a_monst) + panic("insane light source: no id!"); + if (ls->type == LS_OBJECT) { + struct obj *otmp = (struct obj *) ls->id.a_obj; + auint = otmp->o_id; + if (find_oid(auint) != otmp) + panic("insane light source: can't find obj #%u!", auint); + } else if (ls->type == LS_MONSTER) { + struct monst *mtmp = (struct monst *) ls->id.a_monst; + auint = mtmp->m_id; + if (find_mid(auint, FM_EVERYWHERE) != mtmp) + panic("insane light source: can't find mon #%u!", auint); + } else { + panic("insane light source: bad ls type %d", ls->type); + } + } +} + /* Write a light source structure to disk. */ STATIC_OVL void write_ls(fd, ls)