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

Function store_plname_in_file

src/save.c:998–1027  ·  view source on GitHub ↗

write "name-role-race-gend-algn" into save file for menu-based restore; the first dash is actually stored as '\0' instead of '-' */

Source from the content-addressed store, hash-verified

996/* write "name-role-race-gend-algn" into save file for menu-based restore;
997 the first dash is actually stored as '\0' instead of '-' */
998void
999store_plname_in_file(NHFILE *nhfp)
1000{
1001 char hero[PL_NSIZ_PLUS]; /* [PL_NSIZ + 4*(1+3) + 1] */
1002 int plsiztmp = (int) sizeof hero;
1003
1004 (void) memset((genericptr_t) hero, '\0', sizeof hero);
1005 /* augment svp.plname[]; the gender and alignment values reflect those
1006 in effect at time of saving rather than at start of game */
1007 Snprintf(hero, sizeof hero, "%s-%.3s-%.3s-%.3s-%.3s",
1008 svp.plname, gu.urole.filecode,
1009 gu.urace.filecode, genders[flags.female].filecode,
1010 aligns[1 - u.ualign.type].filecode);
1011 /* replace "-role-race..." with "\0role-race..." so that we can include
1012 or exclude the role-&c suffix easily, without worrying about whether
1013 plname contains any dashes; but don't rely on snprintf() for this */
1014 hero[strlen(svp.plname)] = '\0';
1015 /* insert playmode into final slot of hero[];
1016 'D','X','-' are the same characters as are used for paniclog entries */
1017 assert(hero[PL_NSIZ_PLUS - 1 - 1] == '\0');
1018 hero[PL_NSIZ_PLUS - 1] = wizard ? 'D' : discover ? 'X' : '-';
1019
1020 if (nhfp->structlevel)
1021 bufoff(nhfp->fd); /* bwrite() before bufon() uses plain write() */
1022 Sfo_int(nhfp, &plsiztmp, "plname-size");
1023 Sfo_char(nhfp, hero, "plname", plsiztmp);
1024 if (nhfp->structlevel)
1025 bufon(nhfp->fd);
1026 return;
1027}
1028
1029staticfn void
1030save_msghistory(NHFILE *nhfp)

Callers 2

dosave0Function · 0.85
savestateinlockFunction · 0.85

Calls 2

bufoffFunction · 0.85
bufonFunction · 0.85

Tested by

no test coverage detected