-+-+-+-+-+-+-+-+ START OF PART 58 -+-+-+-+-+-+-+-+
X`09`09`7D
X`09      /* don't let him starve to death immediately */
X`09      if (py.flags.food < 0)
X`09`09py.flags.food = 0;
X`09      /* don't let him die of poison again immediately */
X`09      if (py.flags.poisoned > 1)
X`09`09py.flags.poisoned = 1;
X`09      dun_level = 0; /* Resurrect on the town level. */
X`09      character_generated = 1;
X`09      /* set noscore to indicate a resurrection, and don't enter
X`09`09 wizard mode */
X`09      to_be_wizard = FALSE;
X`09      noscore `7C= 0x1;
X`09    `7D
X`09  else
X`09    `7B
X`09      /* Make sure that this message is seen, since it is a bit
X`09`09 more interesting than the other messages.  */
X`09      msg_print("Restoring Memory of a departed spirit...");
X`09      turn = -1;
X`09    `7D
X`09  put_qio();
X`09  goto closefiles;
X`09`7D
X      if (ungetc(c, fileptr) == EOF)
X`09goto error;
X
X      prt("Restoring Character...", 0, 0);
X      put_qio();
X
X      /* only level specific info should follow, not present for dead
X         characters */
X
X      rd_short((int16u *)&dun_level);
X      rd_short((int16u *)&char_row);
X      rd_short((int16u *)&char_col);
X      rd_short((int16u *)&mon_tot_mult);
X      rd_short((int16u *)&cur_height);
X      rd_short((int16u *)&cur_width);
X      rd_short((int16u *)&max_panel_rows);
X      rd_short((int16u *)&max_panel_cols);
X
X      /* read in the creature ptr info */
X      rd_byte(&char_tmp);
X      while (char_tmp != 0xFF)
X`09`7B
X`09  ychar = char_tmp;
X`09  rd_byte(&xchar);
X`09  rd_byte(&char_tmp);
X`09  if (xchar > MAX_WIDTH `7C`7C ychar > MAX_HEIGHT)
X`09    goto error;
X`09  cave`5Bychar`5D`5Bxchar`5D.cptr = char_tmp;
X`09  rd_byte(&char_tmp);
X`09`7D
X      /* read in the treasure ptr info */
X      rd_byte(&char_tmp);
X      while (char_tmp != 0xFF)
X`09`7B
X`09  ychar = char_tmp;
X`09  rd_byte(&xchar);
X`09  rd_byte(&char_tmp);
X`09  if (xchar > MAX_WIDTH `7C`7C ychar > MAX_HEIGHT)
X`09    goto error;
X`09  cave`5Bychar`5D`5Bxchar`5D.tptr = char_tmp;
X`09  rd_byte(&char_tmp);
X`09`7D
X      /* read in the rest of the cave info */
X      c_ptr = &cave`5B0`5D`5B0`5D;
X      total_count = 0;
X      while (total_count != MAX_HEIGHT*MAX_WIDTH)
X`09`7B
X`09  rd_byte(&count);
X`09  rd_byte(&char_tmp);
X`09  for (i = count; i > 0; i--)
X`09    `7B
X#ifndef ATARIST_MWC
X`09      if (c_ptr >= &cave`5BMAX_HEIGHT`5D`5B0`5D)
X`09`09goto error;
X#endif
X`09      c_ptr->fval = char_tmp & 0xF;
X`09      c_ptr->lr = (char_tmp >> 4) & 0x1;
X`09      c_ptr->fm = (char_tmp >> 5) & 0x1;
X`09      c_ptr->pl = (char_tmp >> 6) & 0x1;
X`09      c_ptr->tl = (char_tmp >> 7) & 0x1;
X`09      c_ptr++;
X`09    `7D
X`09  total_count += count;
X`09`7D
X
X      rd_short((int16u *)&tcptr);
X      if (tcptr > MAX_TALLOC)
X`09goto error;
X      for (i = MIN_TRIX; i < tcptr; i++)
X`09rd_item(&t_list`5Bi`5D);
X      rd_short((int16u *)&mfptr);
X      if (mfptr > MAX_MALLOC)
X`09goto error;
X      for (i = MIN_MONIX; i < mfptr; i++)
X`09rd_monster(&m_list`5Bi`5D);
X
X#if defined(MSDOS) `7C`7C defined(ATARI_ST)
X      /* change walls and floors to graphic symbols */
X      t_ptr = &t_list`5Btcptr - 1`5D;
X      for (i = tcptr - 1; i >= MIN_TRIX; i--)
X`09`7B
X#ifdef MSDOS
X`09  if (t_ptr->tchar == '#')
X`09    t_ptr->tchar = wallsym;
X#endif
X#ifdef ATARI_ST
X`09  if (t_ptr->tchar == '#')
X`09    t_ptr->tchar = (unsigned char) 240;
X#endif
X`09  t_ptr--;
X`09`7D
X#endif
X
X      *generate = FALSE;  /* We have restored a cave - no need to generate.
V */
X
X      if ((version_min == 1 && patch_level < 3)
X`09  `7C`7C (version_min == 0))
X`09for (i = 0; i < MAX_STORES; i++)
X`09  `7B
X`09    st_ptr = &store`5Bi`5D;
X`09    rd_long((int32u *)&st_ptr->store_open);
X`09    rd_short((int16u *)&st_ptr->insult_cur);
X`09    rd_byte(&st_ptr->owner);
X`09    rd_byte(&st_ptr->store_ctr);
X`09    rd_short(&st_ptr->good_buy);
X`09    rd_short(&st_ptr->bad_buy);
X`09    if (st_ptr->store_ctr > STORE_INVEN_MAX)
X`09      goto error;
X`09    for (j = 0; j < st_ptr->store_ctr; j++)
X`09      `7B
X`09`09rd_long((int32u *)&st_ptr->store_inven`5Bj`5D.scost);
X`09`09rd_item(&st_ptr->store_inven`5Bj`5D.sitem);
X`09      `7D
X`09  `7D
X
X      /* read the time that the file was saved */
X      if (version_min == 0 && patch_level < 16)
X`09time_saved = 0; /* no time in file, clear to zero */
X      else if (version_min == 1 && patch_level < 3)
X`09rd_long(&time_saved);
X
X      if (ferror(fileptr))
X`09goto error;
X
X      if (turn < 0)
X      error:
X`09ok = FALSE;`09/* Assume bad data. */
X      else
X`09`7B
X`09  /* don't overwrite the killed by string if character is dead */
X`09  if (py.misc.chp >= 0)
X`09    (void) strcpy(died_from, "(alive and well)");
X`09  character_generated = 1;
X`09`7D
X
X    closefiles:
X
X      DEBUG(fclose (logfile));
X
X      if (fileptr != NULL)
X`09`7B
X`09  if (fclose(fileptr) < 0)
X`09    ok = FALSE;
X`09`7D
X      if (fd >= 0)
X`09(void) close(fd);
X
X#ifdef MAC
X      macendwait ();
X#endif
X
X      if (!ok)
X`09msg_print("Error during reading of file.");
X      else
X`09`7B
X`09  /* let the user overwrite the old savefile when save/quit */
X`09  from_savefile = 1;
X
X`09  signals();
X
X`09  if (panic_save == 1)
X`09    `7B
X`09      (void) sprintf(temp, "This game is from a panic save.  \
XScore will not be added to scoreboard.");
X`09      msg_print (temp);
X`09    `7D
X`09  else if ((!noscore & 0x04) && duplicate_character ())
X`09    `7B
X`09      (void) sprintf (temp, "This character is already on the \
Xscoreboard; it will not be scored again.");
X`09      msg_print (temp);
X`09      noscore `7C= 0x4;
X`09    `7D
X
X`09  if (turn >= 0)
X`09    `7B`09/* Only if a full restoration. */
X`09      weapon_heavy = FALSE;
X`09      pack_heavy = 0;
X`09      check_strength();
X
X`09      /* rotate store inventory, depending on how old the save file */
X`09      /* is foreach day old (rounded up), call store_maint */
X`09      /* calculate age in seconds */
X#ifdef MAC
X`09      start_time = time((time_t *)0);
X#else
X`09      start_time = time((long *)0);
X#endif
X`09      /* check for reasonable values of time here ... */
X`09      if (start_time < time_saved)
X`09`09age = 0;
X`09      else
X`09`09age = start_time - time_saved;
X
X`09      age = (age + 43200L) / 86400L;  /* age in days */
X`09      if (age > 10) age = 10; /* in case savefile is very old */
X`09      for (i = 0; i < age; i++)
X`09`09store_maint();
X`09    `7D
X
X`09  if (noscore)
X`09    msg_print("This save file cannot be used to get on the score board.")
V;
X
X`09  if (version_maj != CUR_VERSION_MAJ
X`09      `7C`7C version_min != CUR_VERSION_MIN)
X`09    `7B
X`09      (void) sprintf(temp,
X`09`09`09     "Save file version %d.%d %s on game version %d.%d.",
X`09`09`09     version_maj, version_min,
X`09`09`09     version_min <= CUR_VERSION_MIN
X`09`09`09     ? "accepted" : "risky" ,
X`09`09`09     CUR_VERSION_MAJ, CUR_VERSION_MIN);
X`09      msg_print(temp);
X`09    `7D
X
X`09  if (turn >= 0)
X`09    return TRUE;
X`09  else
X`09    return FALSE;`09/* Only restored options and monster memory. */
X`09`7D
X    `7D
X  turn = -1;
X  prt("Please try again without that savefile.", 1, 0);
X  signals();
X#ifdef MAC
X  *exit_flag = TRUE;
X#else
X  exit_game();
X#endif
X
X  return FALSE;`09/* not reached, unless on mac */
X`7D
X
Xstatic void wr_byte(c)
Xint8u c;
X`7B
X  xor_byte `5E= c;
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, "BYTE:  %02X = %d\n", (int) xor_byte, (int) c));
X`7D
X
Xstatic void wr_short(s)
Xint16u s;
X`7B
X  xor_byte `5E= (s & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, "SHORT: %02X", (int) xor_byte));
X  xor_byte `5E= ((s >> 8) & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, " %02X = %d\n", (int) xor_byte, (int) s));
X`7D
X
Xstatic void wr_long(l)
Xregister int32u l;
X`7B
X  xor_byte `5E= (l & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, "LONG:  %02X", (int) xor_byte));
X  xor_byte `5E= ((l >> 8) & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, " %02X", (int) xor_byte));
X  xor_byte `5E= ((l >> 16) & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, " %02X", (int) xor_byte));
X  xor_byte `5E= ((l >> 24) & 0xFF);
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, " %02X = %ld\n", (int) xor_byte, (long) l));
X`7D
X
Xstatic void wr_bytes(c, count)
Xint8u *c;
Xregister int count;
X`7B
X  register int i;
X  register int8u *ptr;
X
X  DEBUG(fprintf (logfile, "%d BYTES:", count));
X  ptr = c;
X  for (i = 0; i < count; i++)
X    `7B
X      xor_byte `5E= *ptr++;
X      (void) putc((int)xor_byte, fileptr);
X      DEBUG(fprintf (logfile, "  %02X = %d", (int) xor_byte,
X`09`09     (int) (ptr`5B-1`5D)));
X    `7D
X  DEBUG(fprintf (logfile, "\n"));
X`7D
X
Xstatic void wr_string(str)
Xregister char *str;
X`7B
X  DEBUG(char *s = str);
X  DEBUG(fprintf (logfile, "STRING:"));
X  while (*str != '\0')
X    `7B
X      xor_byte `5E= *str++;
X      (void) putc((int)xor_byte, fileptr);
X      DEBUG(fprintf (logfile, " %02X", (int) xor_byte));
X    `7D
X  xor_byte `5E= *str;
X  (void) putc((int)xor_byte, fileptr);
X  DEBUG(fprintf (logfile, " %02X = \"%s\"\n", (int) xor_byte, s));
X`7D
X
Xstatic void wr_shorts(s, count)
Xint16u *s;
Xregister int count;
X`7B
X  register int i;
X  register int16u *sptr;
X
X  DEBUG(fprintf (logfile, "%d SHORTS:", count));
X  sptr = s;
X  for (i = 0; i < count; i++)
X    `7B
X      xor_byte `5E= (*sptr & 0xFF);
X      (void) putc((int)xor_byte, fileptr);
X      DEBUG(fprintf (logfile, "  %02X", (int) xor_byte));
X      xor_byte `5E= ((*sptr++ >> 8) & 0xFF);
X      (void) putc((int)xor_byte, fileptr);
X      DEBUG(fprintf (logfile, " %02X = %d", (int) xor_byte, (int) sptr`5B-1`
V5D));
X    `7D
X  DEBUG(fprintf (logfile, "\n"));
X`7D
X
Xstatic void wr_item(item)
Xregister inven_type *item;
X`7B
X  DEBUG(fprintf (logfile, "ITEM:\n"));
X  wr_short(item->index);
X  wr_byte(item->name2);
X  wr_string(item->inscrip);
X  wr_long(item->flags);
X  wr_byte(item->tval);
X  wr_byte(item->tchar);
X  wr_short((int16u)item->p1);
X  wr_long((int32u)item->cost);
X  wr_byte(item->subval);
X  wr_byte(item->number);
X  wr_short(item->weight);
X  wr_short((int16u)item->tohit);
X  wr_short((int16u)item->todam);
X  wr_short((int16u)item->ac);
X  wr_short((int16u)item->toac);
X  wr_bytes(item->damage, 2);
X  wr_byte(item->level);
X  wr_byte(item->ident);
X`7D
X
Xstatic void wr_monster(mon)
Xregister monster_type *mon;
X`7B
X  DEBUG(fprintf (logfile, "MONSTER:\n"));
X  wr_short((int16u)mon->hp);
X  wr_short((int16u)mon->csleep);
X  wr_short((int16u)mon->cspeed);
X  wr_short(mon->mptr);
X  wr_byte(mon->fy);
X  wr_byte(mon->fx);
X  wr_byte(mon->cdis);
X  wr_byte(mon->ml);
X  wr_byte(mon->stunned);
X  wr_byte(mon->confused);
X`7D
X
Xstatic void rd_byte(ptr)
Xint8u *ptr;
X`7B
X  int8u c;
X
X  c = getc(fileptr) & 0xFF;
X  *ptr = c `5E xor_byte;
X  xor_byte = c;
X  DEBUG(fprintf (logfile, "BYTE:  %02X = %d\n", (int) c, (int) *ptr));
X`7D
X
Xstatic void rd_short(ptr)
Xint16u *ptr;
X`7B
X  int8u c;
X  int16u s;
X
X  c = (getc(fileptr) & 0xFF);
X  s = c `5E xor_byte;
X  xor_byte = (getc(fileptr) & 0xFF);
X  s `7C= (int16u)(c `5E xor_byte) << 8;
X  *ptr = s;
X  DEBUG(fprintf (logfile, "SHORT: %02X %02X = %d\n", (int) c, (int) xor_byte
V,\
X`09`09 (int) s));
X`7D
X
Xstatic void rd_long(ptr)
Xint32u *ptr;
X`7B
X  register int32u l;
X  register int8u c;
X
X  c = (getc(fileptr) & 0xFF);
X  l = c `5E xor_byte;
X  xor_byte = (getc(fileptr) & 0xFF);
X  l `7C= (int32u)(c `5E xor_byte) << 8;
X  DEBUG(fprintf (logfile, "LONG:  %02X %02X ", (int) c, (int) xor_byte));
X  c = (getc(fileptr) & 0xFF);
X  l `7C= (int32u)(c `5E xor_byte) << 16;
X  xor_byte = (getc(fileptr) & 0xFF);
X  l `7C= (int32u)(c `5E xor_byte) << 24;
X  *ptr = l;
X  DEBUG(fprintf (logfile, "%02X %02X = %ld\n", (int) c, (int) xor_byte,\
X`09`09 (long) l));
X`7D
X
Xstatic void rd_bytes(ch_ptr, count)
Xint8u *ch_ptr;
Xregister int count;
X`7B
X  register int i;
X  register int8u *ptr;
X  register int8u c;
X
X  DEBUG(fprintf (logfile, "%d BYTES:", count));
X  ptr = ch_ptr;
X  for (i = 0; i < count; i++)
X    `7B
X      c = (getc(fileptr) & 0xFF);
X      *ptr++ = c `5E xor_byte;
X      xor_byte = c;
X      DEBUG(fprintf (logfile, "  %02X = %d", (int) c, (int) ptr`5B-1`5D));
X    `7D
X  DEBUG(fprintf (logfile, "\n"));
X`7D
X
Xstatic void rd_string(str)
Xchar *str;
X`7B
X  register int8u c;
X
X  DEBUG(char *s = str);
X  DEBUG(fprintf (logfile, "STRING: "));
X  do
X    `7B
X      c = (getc(fileptr) & 0xFF);
X      *str = c `5E xor_byte;
X      xor_byte = c;
X      DEBUG(fprintf (logfile, "%02X ", (int) c));
X    `7D
X  while (*str++ != '\0');
X  DEBUG(fprintf (logfile, "= \"%s\"\n", s));
X`7D
X
Xstatic void rd_shorts(ptr, count)
Xint16u *ptr;
Xregister int count;
X`7B
X  register int i;
X  register int16u *sptr;
X  register int16u s;
X  int8u c;
X
X  DEBUG(fprintf (logfile, "%d SHORTS:", count));
X  sptr = ptr;
X  for (i = 0; i < count; i++)
X    `7B
X      c = (getc(fileptr) & 0xFF);
X      s = c `5E xor_byte;
X      xor_byte = (getc(fileptr) & 0xFF);
X      s `7C= (int16u)(c `5E xor_byte) << 8;
X      *sptr++ = s;
X      DEBUG(fprintf (logfile, "  %02X %02X = %d", (int) c, (int) xor_byte,\
X`09`09     (int) s));
X    `7D
X  DEBUG(fprintf (logfile, "\n"));
X`7D
X
Xstatic void rd_item(item)
Xregister inven_type *item;
X`7B
X  DEBUG(fprintf (logfile, "ITEM:\n"));
X  rd_short(&item->index);
X  rd_byte(&item->name2);
X  rd_string(item->inscrip);
X  rd_long(&item->flags);
X  rd_byte(&item->tval);
X  rd_byte(&item->tchar);
X  rd_short((int16u *)&item->p1);
X  rd_long((int32u *)&item->cost);
X  rd_byte(&item->subval);
X  rd_byte(&item->number);
X  rd_short(&item->weight);
X  rd_short((int16u *)&item->tohit);
X  rd_short((int16u *)&item->todam);
X  rd_short((int16u *)&item->ac);
X  rd_short((int16u *)&item->toac);
X  rd_bytes(item->damage, 2);
X  rd_byte(&item->level);
X  rd_byte(&item->ident);
X`7D
X
Xstatic void rd_monster(mon)
Xregister monster_type *mon;
X`7B
X  DEBUG(fprintf (logfile, "MONSTER:\n"));
+-+-+-+-+-+-+-+-  END  OF PART 58 +-+-+-+-+-+-+-+-
