void transfer_lights(struct level *oldlev, struct level *newlev) { light_source **prev, *curr; boolean is_global; for (prev = &oldlev->lev_lights; (curr = *prev) != 0; ) { switch (curr->type) { case LS_OBJECT: is_global = !obj_is_local((struct obj *)curr->id); break; case LS_MONSTER: is_global = !mon_is_local((struct monst *)curr->id); break; default: is_global = FALSE; break; } /* associate all global light sources with the new level */ if (is_global) { *prev = curr->next; curr->next = newlev->lev_lights; newlev->lev_lights = curr; } else { prev = &(*prev)->next; } } }
/* * 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. */ static int maybe_write_ls(struct memfile *mf, struct level *lev, int range, boolean write_it) { int count = 0, is_global; light_source *ls; for (ls = lev->lev_lights; ls; ls = ls->next) { if (!ls->id) { impossible("maybe_write_ls: no id! [range=%d]", range); continue; } switch (ls->type) { case LS_OBJECT: is_global = !obj_is_local((struct obj *)ls->id); break; case LS_MONSTER: is_global = !mon_is_local((struct monst *)ls->id); break; default: is_global = 0; impossible("maybe_write_ls: bad type (%d) [range=%d]", ls->type, range); break; } /* if global and not doing local, or vice versa, count it */ if (is_global ^ (range == RANGE_LEVEL)) { count++; if (write_it) write_ls(mf, ls); } } return count; }
void transfer_lights(struct level *oldlev, struct level *newlev, unsigned int obj_id) { light_source **prev, *curr; boolean transfer; if (newlev == oldlev) return; for (prev = &oldlev->lev_lights; (curr = *prev) != 0;) { switch (curr->type) { case LS_OBJECT: if (obj_id) transfer = (((struct obj *)curr->id)->o_id == obj_id); else transfer = !obj_is_local((struct obj *)curr->id); break; case LS_MONSTER: if (obj_id) transfer = FALSE; else transfer = !mon_is_local((struct monst *)curr->id); break; default: transfer = FALSE; break; } /* associate light sources with the new level */ if (transfer) { *prev = curr->next; curr->next = newlev->lev_lights; newlev->lev_lights = curr; } else { prev = &(*prev)->next; } } }