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

Function shuffle_customizations

src/glyphs.c:590–642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588
589#if 0
590staticfn void
591shuffle_customizations(void)
592{
593 static const int offsets[2] = { GLYPH_OBJ_OFF, GLYPH_OBJ_PILETOP_OFF };
594 int j;
595
596 for (j = 0; j < SIZE(offsets); j++) {
597 glyph_map *obj_glyphs = glyphmap + offsets[j];
598 int i;
599 struct unicode_representation *tmp_u[NUM_OBJECTS];
600 int duplicate[NUM_OBJECTS];
601
602 for (i = 0; i < NUM_OBJECTS; i++) {
603 duplicate[i] = -1;
604 tmp_u[i] = (struct unicode_representation *) 0;
605 }
606 for (i = 0; i < NUM_OBJECTS; i++) {
607 int idx = objects[i].oc_descr_idx;
608
609 /*
610 * Shuffling gem appearances can cause the same oc_descr_idx to
611 * appear more than once. Detect this condition and ensure that
612 * each pointer points to a unique allocation.
613 */
614 if (duplicate[idx] >= 0) {
615 /* Current structure already appears in tmp_u */
616 struct unicode_representation *other = tmp_u[duplicate[idx]];
617
618 tmp_u[i] = (struct unicode_representation *)
619 alloc(sizeof *tmp_u[i]);
620 *tmp_u[i] = *other;
621 if (other->utf8str != NULL) {
622 tmp_u[i]->utf8str = (uint8 *)
623 dupstr((const char *) other->utf8str);
624 }
625 } else {
626 tmp_u[i] = obj_glyphs[idx].u;
627 if (obj_glyphs[idx].u != NULL) {
628 duplicate[idx] = i;
629 obj_glyphs[idx].u = NULL;
630 }
631 }
632 }
633 for (i = 0; i < NUM_OBJECTS; i++) {
634 /* Some glyphmaps may not have been transferred */
635 if (obj_glyphs[i].u != NULL) {
636 free(obj_glyphs[i].u->utf8str);
637 free(obj_glyphs[i].u);
638 }
639 obj_glyphs[i].u = tmp_u[i];
640 }
641 }
642}
643
644#else
645staticfn void

Callers 1

Calls 2

dupstrFunction · 0.85
allocFunction · 0.70

Tested by

no test coverage detected