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

Function save_light_sources

src/light.c:420–471  ·  view source on GitHub ↗

Save all light sources of the given range. */

Source from the content-addressed store, hash-verified

418
419/* Save all light sources of the given range. */
420void
421save_light_sources(NHFILE *nhfp, int range)
422{
423 int count, actual, is_global;
424 light_source **prev, *curr;
425
426 /* camera flash light sources have Null object and would trigger
427 impossible("no id!") below; they can only happen here if we're
428 in the midst of a panic save and they wouldn't be useful after
429 restore so just throw any that are present away */
430 discard_flashes();
431 gv.vision_full_recalc = 0;
432
433 if (update_file(nhfp)) {
434 count = maybe_write_ls(nhfp, range, FALSE);
435 Sfo_int(nhfp, &count, "lightsource-count");
436 actual = maybe_write_ls(nhfp, range, TRUE);
437 if (actual != count)
438 panic("counted %d light sources, wrote %d! [range=%d]", count,
439 actual, range);
440 }
441
442 if (release_data(nhfp)) {
443 for (prev = &gl.light_base; (curr = *prev) != 0; ) {
444 if (!curr->id.a_monst) {
445 impossible("save_light_sources: no id! [range=%d]", range);
446 is_global = 0;
447 } else
448 switch (curr->type) {
449 case LS_OBJECT:
450 is_global = !obj_is_local(curr->id.a_obj);
451 break;
452 case LS_MONSTER:
453 is_global = !mon_is_local(curr->id.a_monst);
454 break;
455 default:
456 is_global = 0;
457 impossible("save_light_sources: bad type (%d) [range=%d]",
458 curr->type, range);
459 break;
460 }
461 /* if global and not doing local, or vice versa, remove it */
462 if (is_global ^ (range == RANGE_LEVEL)) {
463 *prev = curr->next;
464 (void) memset((genericptr_t) curr, 0, sizeof(light_source));
465 free((genericptr_t) curr);
466 } else {
467 prev = &(*prev)->next;
468 }
469 }
470 }
471}
472#endif /* !SFCTOOL */
473
474/*

Callers 2

savegamestateFunction · 0.85
savelev_coreFunction · 0.85

Calls 7

discard_flashesFunction · 0.85
update_fileFunction · 0.85
maybe_write_lsFunction · 0.85
obj_is_localFunction · 0.85
mon_is_localFunction · 0.85
impossibleFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected