Annotation of early-roguelike/arogue7/state.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: state.c - Portable Rogue Save State Code
! 3:
! 4: Copyright (C) 1999, 2000, 2005 Nicholas J. Kisseberth
! 5: All rights reserved.
! 6:
! 7: Redistribution and use in source and binary forms, with or without
! 8: modification, are permitted provided that the following conditions
! 9: are met:
! 10: 1. Redistributions of source code must retain the above copyright
! 11: notice, this list of conditions and the following disclaimer.
! 12: 2. Redistributions in binary form must reproduce the above copyright
! 13: notice, this list of conditions and the following disclaimer in the
! 14: documentation and/or other materials provided with the distribution.
! 15: 3. Neither the name(s) of the author(s) nor the names of other contributors
! 16: may be used to endorse or promote products derived from this software
! 17: without specific prior written permission.
! 18:
! 19: THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
! 20: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 21: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 22: ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
! 23: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 24: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 25: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 26: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 27: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 28: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 29: SUCH DAMAGE.
! 30: */
! 31:
! 32: /************************************************************************/
! 33: /* Save State Code */
! 34: /************************************************************************/
! 35:
! 36: #define RSID_STATS 0xABCD0001
! 37: #define RSID_MSTATS 0xABCD0002
! 38: #define RSID_THING 0xABCD0003
! 39: #define RSID_OBJECT 0xABCD0004
! 40: #define RSID_MAGICITEMS 0xABCD0005
! 41: #define RSID_KNOWS 0xABCD0006
! 42: #define RSID_GUESSES 0xABCD0007
! 43: #define RSID_OBJECTLIST 0xABCD0008
! 44: #define RSID_BAGOBJECT 0xABCD0009
! 45: #define RSID_MONSTERLIST 0xABCD000A
! 46: #define RSID_MONSTERSTATS 0xABCD000B
! 47: #define RSID_MONSTERS 0xABCD000C
! 48: #define RSID_TRAP 0xABCD000D
! 49: #define RSID_WINDOW 0xABCD000E
! 50: #define RSID_DAEMONS 0xABCD000F
! 51: #define RSID_STICKS 0xABCD0010
! 52: #define RSID_IARMOR 0xABCD0011
! 53: #define RSID_SPELLS 0xABCD0012
! 54: #define RSID_ILIST 0xABCD0013
! 55: #define RSID_HLIST 0xABCD0014
! 56: #define RSID_DEATHTYPE 0xABCD0015
! 57: #define RSID_CTYPES 0XABCD0016
! 58: #define RSID_COORDLIST 0XABCD0017
! 59: #define RSID_ROOMS 0XABCD0018
! 60:
! 61: #include <curses.h>
! 62: #include <stdio.h>
! 63: #include <stdlib.h>
! 64: #include <string.h>
! 65: #include "rogue.h"
! 66:
! 67: #define READSTAT (format_error || read_error )
! 68: #define WRITESTAT (write_error)
! 69:
! 70: static int read_error = FALSE;
! 71: static int write_error = FALSE;
! 72: static int format_error = FALSE;
! 73: static int endian = 0x01020304;
! 74: #define big_endian ( *((char *)&endian) == 0x01 )
! 75:
! 76: int list_size(struct linked_list *l);
! 77: int rs_write_int(FILE *savef, int c);
! 78: int rs_read_int(FILE *inf, int *i);
! 79: int rs_write_object_list(FILE *savef, struct linked_list *l);
! 80: int rs_read_object_list(FILE *inf, struct linked_list **list);
! 81:
! 82: int
! 83: rs_write(FILE *savef, void *ptr, size_t size)
! 84: {
! 85: if (write_error)
! 86: return(WRITESTAT);
! 87:
! 88: if (encwrite(ptr, size, savef) != size)
! 89: write_error = 1;
! 90:
! 91: return(WRITESTAT);
! 92: }
! 93:
! 94: int
! 95: rs_read(FILE *inf, void *ptr, size_t size)
! 96: {
! 97: if (read_error || format_error)
! 98: return(READSTAT);
! 99:
! 100: if (encread(ptr, size, inf) != size)
! 101: read_error = 1;
! 102:
! 103: return(READSTAT);
! 104: }
! 105:
! 106: int
! 107: rs_write_uchar(FILE *savef, unsigned char c)
! 108: {
! 109: if (write_error)
! 110: return(WRITESTAT);
! 111:
! 112: rs_write(savef, &c, 1);
! 113:
! 114: return(WRITESTAT);
! 115: }
! 116:
! 117: int
! 118: rs_read_uchar(FILE *inf, unsigned char *c)
! 119: {
! 120: if (read_error || format_error)
! 121: return(READSTAT);
! 122:
! 123: rs_read(inf, c, 1);
! 124:
! 125: return(READSTAT);
! 126: }
! 127:
! 128: int
! 129: rs_write_char(FILE *savef, char c)
! 130: {
! 131: if (write_error)
! 132: return(WRITESTAT);
! 133:
! 134: rs_write(savef, &c, 1);
! 135:
! 136: return(WRITESTAT);
! 137: }
! 138:
! 139: int
! 140: rs_read_char(FILE *inf, char *c)
! 141: {
! 142: if (read_error || format_error)
! 143: return(READSTAT);
! 144:
! 145: rs_read(inf, c, 1);
! 146:
! 147: return(READSTAT);
! 148: }
! 149:
! 150: int
! 151: rs_write_chars(FILE *savef, char *c, int count)
! 152: {
! 153: if (write_error)
! 154: return(WRITESTAT);
! 155:
! 156: rs_write_int(savef, count);
! 157: rs_write(savef, c, count);
! 158:
! 159: return(WRITESTAT);
! 160: }
! 161:
! 162: int
! 163: rs_read_chars(FILE *inf, char *i, int count)
! 164: {
! 165: int value = 0;
! 166:
! 167: if (read_error || format_error)
! 168: return(READSTAT);
! 169:
! 170: rs_read_int(inf, &value);
! 171:
! 172: if (value != count)
! 173: format_error = TRUE;
! 174:
! 175: rs_read(inf, i, count);
! 176:
! 177: return(READSTAT);
! 178: }
! 179:
! 180: int
! 181: rs_write_int(FILE *savef, int c)
! 182: {
! 183: unsigned char bytes[4];
! 184: unsigned char *buf = (unsigned char *) &c;
! 185:
! 186: if (write_error)
! 187: return(WRITESTAT);
! 188:
! 189: if (big_endian)
! 190: {
! 191: bytes[3] = buf[0];
! 192: bytes[2] = buf[1];
! 193: bytes[1] = buf[2];
! 194: bytes[0] = buf[3];
! 195: buf = bytes;
! 196: }
! 197:
! 198: rs_write(savef, buf, 4);
! 199:
! 200: return(WRITESTAT);
! 201: }
! 202:
! 203: int
! 204: rs_read_int(FILE *inf, int *i)
! 205: {
! 206: unsigned char bytes[4];
! 207: int input = 0;
! 208: unsigned char *buf = (unsigned char *)&input;
! 209:
! 210: if (read_error || format_error)
! 211: return(READSTAT);
! 212:
! 213: rs_read(inf, &input, 4);
! 214:
! 215: if (big_endian)
! 216: {
! 217: bytes[3] = buf[0];
! 218: bytes[2] = buf[1];
! 219: bytes[1] = buf[2];
! 220: bytes[0] = buf[3];
! 221: buf = bytes;
! 222: }
! 223:
! 224: *i = *((int *) buf);
! 225:
! 226: return(READSTAT);
! 227: }
! 228:
! 229: int
! 230: rs_write_ints(FILE *savef, int *c, int count)
! 231: {
! 232: int n = 0;
! 233:
! 234: if (write_error)
! 235: return(WRITESTAT);
! 236:
! 237: rs_write_int(savef, count);
! 238:
! 239: for(n = 0; n < count; n++)
! 240: if( rs_write_int(savef,c[n]) != 0)
! 241: break;
! 242:
! 243: return(WRITESTAT);
! 244: }
! 245:
! 246: int
! 247: rs_read_ints(FILE *inf, int *i, int count)
! 248: {
! 249: int n, value;
! 250:
! 251: if (read_error || format_error)
! 252: return(READSTAT);
! 253:
! 254: rs_read_int(inf,&value);
! 255:
! 256: if (value != count)
! 257: format_error = TRUE;
! 258:
! 259: for(n = 0; n < count; n++)
! 260: if (rs_read_int(inf, &i[n]) != 0)
! 261: break;
! 262:
! 263: return(READSTAT);
! 264: }
! 265:
! 266: int
! 267: rs_write_boolean(FILE *savef, bool c)
! 268: {
! 269: unsigned char buf = (c == 0) ? 0 : 1;
! 270:
! 271: if (write_error)
! 272: return(WRITESTAT);
! 273:
! 274: rs_write(savef, &buf, 1);
! 275:
! 276: return(WRITESTAT);
! 277: }
! 278:
! 279: int
! 280: rs_read_boolean(FILE *inf, bool *i)
! 281: {
! 282: unsigned char buf = 0;
! 283:
! 284: if (read_error || format_error)
! 285: return(READSTAT);
! 286:
! 287: rs_read(inf, &buf, 1);
! 288:
! 289: *i = (buf != 0);
! 290:
! 291: return(READSTAT);
! 292: }
! 293:
! 294: int
! 295: rs_write_booleans(FILE *savef, bool *c, int count)
! 296: {
! 297: int n = 0;
! 298:
! 299: if (write_error)
! 300: return(WRITESTAT);
! 301:
! 302: rs_write_int(savef, count);
! 303:
! 304: for(n = 0; n < count; n++)
! 305: if (rs_write_boolean(savef, c[n]) != 0)
! 306: break;
! 307:
! 308: return(WRITESTAT);
! 309: }
! 310:
! 311: int
! 312: rs_read_booleans(FILE *inf, bool *i, int count)
! 313: {
! 314: int n = 0, value = 0;
! 315:
! 316: if (read_error || format_error)
! 317: return(READSTAT);
! 318:
! 319: rs_read_int(inf,&value);
! 320:
! 321: if (value != count)
! 322: format_error = TRUE;
! 323:
! 324: for(n = 0; n < count; n++)
! 325: if (rs_read_boolean(inf, &i[n]) != 0)
! 326: break;
! 327:
! 328: return(READSTAT);
! 329: }
! 330:
! 331: int
! 332: rs_write_short(FILE *savef, short c)
! 333: {
! 334: unsigned char bytes[2];
! 335: unsigned char *buf = (unsigned char *) &c;
! 336:
! 337: if (write_error)
! 338: return(WRITESTAT);
! 339:
! 340: if (big_endian)
! 341: {
! 342: bytes[1] = buf[0];
! 343: bytes[0] = buf[1];
! 344: buf = bytes;
! 345: }
! 346:
! 347: rs_write(savef, buf, 2);
! 348:
! 349: return(WRITESTAT);
! 350: }
! 351:
! 352: int
! 353: rs_read_short(FILE *inf, short *i)
! 354: {
! 355: unsigned char bytes[2];
! 356: short input;
! 357: unsigned char *buf = (unsigned char *)&input;
! 358:
! 359: if (read_error || format_error)
! 360: return(READSTAT);
! 361:
! 362: rs_read(inf, &input, 2);
! 363:
! 364: if (big_endian)
! 365: {
! 366: bytes[1] = buf[0];
! 367: bytes[0] = buf[1];
! 368: buf = bytes;
! 369: }
! 370:
! 371: *i = *((short *) buf);
! 372:
! 373: return(READSTAT);
! 374: }
! 375:
! 376: int
! 377: rs_write_shorts(FILE *savef, short *c, int count)
! 378: {
! 379: int n = 0;
! 380:
! 381: if (write_error)
! 382: return(WRITESTAT);
! 383:
! 384: rs_write_int(savef, count);
! 385:
! 386: for(n = 0; n < count; n++)
! 387: if (rs_write_short(savef, c[n]) != 0)
! 388: break;
! 389:
! 390: return(WRITESTAT);
! 391: }
! 392:
! 393: int
! 394: rs_read_shorts(FILE *inf, short *i, int count)
! 395: {
! 396: int n = 0, value = 0;
! 397:
! 398: if (read_error || format_error)
! 399: return(READSTAT);
! 400:
! 401: rs_read_int(inf,&value);
! 402:
! 403: if (value != count)
! 404: format_error = TRUE;
! 405:
! 406: for(n = 0; n < value; n++)
! 407: if (rs_read_short(inf, &i[n]) != 0)
! 408: break;
! 409:
! 410: return(READSTAT);
! 411: }
! 412:
! 413: int
! 414: rs_write_ushort(FILE *savef, unsigned short c)
! 415: {
! 416: unsigned char bytes[2];
! 417: unsigned char *buf = (unsigned char *) &c;
! 418:
! 419: if (write_error)
! 420: return(WRITESTAT);
! 421:
! 422: if (big_endian)
! 423: {
! 424: bytes[1] = buf[0];
! 425: bytes[0] = buf[1];
! 426: buf = bytes;
! 427: }
! 428:
! 429: rs_write(savef, buf, 2);
! 430:
! 431: return(WRITESTAT);
! 432: }
! 433:
! 434: int
! 435: rs_read_ushort(FILE *inf, unsigned short *i)
! 436: {
! 437: unsigned char bytes[2];
! 438: unsigned short input;
! 439: unsigned char *buf = (unsigned char *)&input;
! 440:
! 441: if (read_error || format_error)
! 442: return(READSTAT);
! 443:
! 444: rs_read(inf, &input, 2);
! 445:
! 446: if (big_endian)
! 447: {
! 448: bytes[1] = buf[0];
! 449: bytes[0] = buf[1];
! 450: buf = bytes;
! 451: }
! 452:
! 453: *i = *((unsigned short *) buf);
! 454:
! 455: return(READSTAT);
! 456: }
! 457:
! 458: int
! 459: rs_write_uint(FILE *savef, unsigned int c)
! 460: {
! 461: unsigned char bytes[4];
! 462: unsigned char *buf = (unsigned char *) &c;
! 463:
! 464: if (write_error)
! 465: return(WRITESTAT);
! 466:
! 467: if (big_endian)
! 468: {
! 469: bytes[3] = buf[0];
! 470: bytes[2] = buf[1];
! 471: bytes[1] = buf[2];
! 472: bytes[0] = buf[3];
! 473: buf = bytes;
! 474: }
! 475:
! 476: rs_write(savef, buf, 4);
! 477:
! 478: return(WRITESTAT);
! 479: }
! 480:
! 481: int
! 482: rs_read_uint(FILE *inf, unsigned int *i)
! 483: {
! 484: unsigned char bytes[4];
! 485: int input;
! 486: unsigned char *buf = (unsigned char *)&input;
! 487:
! 488: if (read_error || format_error)
! 489: return(READSTAT);
! 490:
! 491: rs_read(inf, &input, 4);
! 492:
! 493: if (big_endian)
! 494: {
! 495: bytes[3] = buf[0];
! 496: bytes[2] = buf[1];
! 497: bytes[1] = buf[2];
! 498: bytes[0] = buf[3];
! 499: buf = bytes;
! 500: }
! 501:
! 502: *i = *((unsigned int *) buf);
! 503:
! 504: return(READSTAT);
! 505: }
! 506:
! 507: int
! 508: rs_write_long(FILE *savef, long c)
! 509: {
! 510: int c2;
! 511: unsigned char bytes[4];
! 512: unsigned char *buf = (unsigned char *)&c;
! 513:
! 514: if (write_error)
! 515: return(WRITESTAT);
! 516:
! 517: if (sizeof(long) == 8)
! 518: {
! 519: c2 = c;
! 520: buf = (unsigned char *) &c2;
! 521: }
! 522:
! 523: if (big_endian)
! 524: {
! 525: bytes[3] = buf[0];
! 526: bytes[2] = buf[1];
! 527: bytes[1] = buf[2];
! 528: bytes[0] = buf[3];
! 529: buf = bytes;
! 530: }
! 531:
! 532: rs_write(savef, buf, 4);
! 533:
! 534: return(WRITESTAT);
! 535: }
! 536:
! 537: int
! 538: rs_read_long(FILE *inf, long *i)
! 539: {
! 540: unsigned char bytes[4];
! 541: long input;
! 542: unsigned char *buf = (unsigned char *) &input;
! 543:
! 544: if (read_error || format_error)
! 545: return(READSTAT);
! 546:
! 547: rs_read(inf, &input, 4);
! 548:
! 549: if (big_endian)
! 550: {
! 551: bytes[3] = buf[0];
! 552: bytes[2] = buf[1];
! 553: bytes[1] = buf[2];
! 554: bytes[0] = buf[3];
! 555: buf = bytes;
! 556: }
! 557:
! 558: if (sizeof(long) == 8)
! 559: *i = *((int *) buf);
! 560: else
! 561: *i = *((long *) buf);
! 562:
! 563: return(READSTAT);
! 564: }
! 565:
! 566: int
! 567: rs_write_longs(FILE *savef, long *c, int count)
! 568: {
! 569: int n = 0;
! 570:
! 571: if (write_error)
! 572: return(WRITESTAT);
! 573:
! 574: rs_write_int(savef,count);
! 575:
! 576: for(n = 0; n < count; n++)
! 577: rs_write_long(savef, c[n]);
! 578:
! 579: return(WRITESTAT);
! 580: }
! 581:
! 582: int
! 583: rs_read_longs(FILE *inf, long *i, int count)
! 584: {
! 585: int n = 0, value = 0;
! 586:
! 587: if (read_error || format_error)
! 588: return(READSTAT);
! 589:
! 590: rs_read_int(inf,&value);
! 591:
! 592: if (value != count)
! 593: format_error = TRUE;
! 594:
! 595: for(n = 0; n < value; n++)
! 596: if (rs_read_long(inf, &i[n]) != 0)
! 597: break;
! 598:
! 599: return(READSTAT);
! 600: }
! 601:
! 602: int
! 603: rs_write_ulong(FILE *savef, unsigned long c)
! 604: {
! 605: unsigned int c2;
! 606: unsigned char bytes[4];
! 607: unsigned char *buf = (unsigned char *)&c;
! 608:
! 609: if (write_error)
! 610: return(WRITESTAT);
! 611:
! 612: if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
! 613: {
! 614: c2 = c;
! 615: buf = (unsigned char *) &c2;
! 616: }
! 617:
! 618: if (big_endian)
! 619: {
! 620: bytes[3] = buf[0];
! 621: bytes[2] = buf[1];
! 622: bytes[1] = buf[2];
! 623: bytes[0] = buf[3];
! 624: buf = bytes;
! 625: }
! 626:
! 627: rs_write(savef, buf, 4);
! 628:
! 629: return(WRITESTAT);
! 630: }
! 631:
! 632: int
! 633: rs_read_ulong(FILE *inf, unsigned long *i)
! 634: {
! 635: unsigned char bytes[4];
! 636: unsigned long input;
! 637: unsigned char *buf = (unsigned char *) &input;
! 638:
! 639: if (read_error || format_error)
! 640: return(READSTAT);
! 641:
! 642: rs_read(inf, &input, 4);
! 643:
! 644: if (big_endian)
! 645: {
! 646: bytes[3] = buf[0];
! 647: bytes[2] = buf[1];
! 648: bytes[1] = buf[2];
! 649: bytes[0] = buf[3];
! 650: buf = bytes;
! 651: }
! 652:
! 653: if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
! 654: *i = *((unsigned int *) buf);
! 655: else
! 656: *i = *((unsigned long *) buf);
! 657:
! 658: return(READSTAT);
! 659: }
! 660:
! 661: int
! 662: rs_write_ulongs(FILE *savef, unsigned long *c, int count)
! 663: {
! 664: int n = 0;
! 665:
! 666: if (write_error)
! 667: return(WRITESTAT);
! 668:
! 669: rs_write_int(savef,count);
! 670:
! 671: for(n = 0; n < count; n++)
! 672: if (rs_write_ulong(savef,c[n]) != 0)
! 673: break;
! 674:
! 675: return(WRITESTAT);
! 676: }
! 677:
! 678: int
! 679: rs_read_ulongs(FILE *inf, unsigned long *i, int count)
! 680: {
! 681: int n = 0, value = 0;
! 682:
! 683: if (read_error || format_error)
! 684: return(READSTAT);
! 685:
! 686: rs_read_int(inf,&value);
! 687:
! 688: if (value != count)
! 689: format_error = TRUE;
! 690:
! 691: for(n = 0; n < count; n++)
! 692: if (rs_read_ulong(inf, &i[n]) != 0)
! 693: break;
! 694:
! 695: return(READSTAT);
! 696: }
! 697:
! 698: int
! 699: rs_write_marker(FILE *savef, int id)
! 700: {
! 701: if (write_error)
! 702: return(WRITESTAT);
! 703:
! 704: rs_write_int(savef, id);
! 705:
! 706: return(WRITESTAT);
! 707: }
! 708:
! 709: int
! 710: rs_read_marker(FILE *inf, int id)
! 711: {
! 712: int nid;
! 713:
! 714: if (read_error || format_error)
! 715: return(READSTAT);
! 716:
! 717: if (rs_read_int(inf, &nid) == 0)
! 718: if (id != nid)
! 719: format_error = 1;
! 720:
! 721: return(READSTAT);
! 722: }
! 723:
! 724:
! 725:
! 726: /******************************************************************************/
! 727:
! 728: int
! 729: rs_write_string(FILE *savef, char *s)
! 730: {
! 731: int len = 0;
! 732:
! 733: if (write_error)
! 734: return(WRITESTAT);
! 735:
! 736: len = (s == NULL) ? 0 : (int) strlen(s) + 1;
! 737:
! 738: rs_write_int(savef, len);
! 739: rs_write_chars(savef, s, len);
! 740:
! 741: return(WRITESTAT);
! 742: }
! 743:
! 744: int
! 745: rs_read_string(FILE *inf, char *s, int max)
! 746: {
! 747: int len = 0;
! 748:
! 749: if (read_error || format_error)
! 750: return(READSTAT);
! 751:
! 752: rs_read_int(inf, &len);
! 753:
! 754: if (len > max)
! 755: format_error = TRUE;
! 756:
! 757: rs_read_chars(inf, s, len);
! 758:
! 759: return(READSTAT);
! 760: }
! 761:
! 762: int
! 763: rs_read_new_string(FILE *inf, char **s)
! 764: {
! 765: int len=0;
! 766: char *buf=0;
! 767:
! 768: if (read_error || format_error)
! 769: return(READSTAT);
! 770:
! 771: rs_read_int(inf, &len);
! 772:
! 773: if (len == 0)
! 774: buf = NULL;
! 775: else
! 776: {
! 777: buf = malloc(len);
! 778:
! 779: if (buf == NULL)
! 780: read_error = TRUE;
! 781: }
! 782:
! 783: rs_read_chars(inf, buf, len);
! 784:
! 785: *s = buf;
! 786:
! 787: return(READSTAT);
! 788: }
! 789:
! 790: int
! 791: rs_write_strings(FILE *savef, char *s[], int count)
! 792: {
! 793: int n = 0;
! 794:
! 795: if (write_error)
! 796: return(WRITESTAT);
! 797:
! 798: rs_write_int(savef, count);
! 799:
! 800: for(n = 0; n < count; n++)
! 801: if (rs_write_string(savef, s[n]) != 0)
! 802: break;
! 803:
! 804: return(WRITESTAT);
! 805: }
! 806:
! 807: int
! 808: rs_read_strings(FILE *inf, char **s, int count, int max)
! 809: {
! 810: int n = 0;
! 811: int value = 0;
! 812:
! 813: if (read_error || format_error)
! 814: return(READSTAT);
! 815:
! 816: rs_read_int(inf, &value);
! 817:
! 818: if (value != count)
! 819: format_error = TRUE;
! 820:
! 821: for(n = 0; n < count; n++)
! 822: if (rs_read_string(inf, s[n], max) != 0)
! 823: break;
! 824:
! 825: return(READSTAT);
! 826: }
! 827:
! 828: int
! 829: rs_read_new_strings(FILE *inf, char **s, int count)
! 830: {
! 831: int n = 0;
! 832: int value = 0;
! 833:
! 834: if (read_error || format_error)
! 835: return(READSTAT);
! 836:
! 837: rs_read_int(inf, &value);
! 838:
! 839: if (value != count)
! 840: format_error = TRUE;
! 841:
! 842: for(n = 0; n < count; n++)
! 843: if (rs_read_new_string(inf, &s[n]) != 0)
! 844: break;
! 845:
! 846: return(READSTAT);
! 847: }
! 848:
! 849: int
! 850: rs_write_string_index(FILE *savef, char *master[], int max, const char *str)
! 851: {
! 852: int i;
! 853:
! 854: if (write_error)
! 855: return(WRITESTAT);
! 856:
! 857: for(i = 0; i < max; i++)
! 858: if (str == master[i])
! 859: return( rs_write_int(savef, i) );
! 860:
! 861: return( rs_write_int(savef,-1) );
! 862: }
! 863:
! 864: int
! 865: rs_read_string_index(FILE *inf, char *master[], int maxindex, char **str)
! 866: {
! 867: int i;
! 868:
! 869: if (read_error || format_error)
! 870: return(READSTAT);
! 871:
! 872: rs_read_int(inf, &i);
! 873:
! 874: if (i > maxindex)
! 875: format_error = TRUE;
! 876: else if (i >= 0)
! 877: *str = master[i];
! 878: else
! 879: *str = NULL;
! 880:
! 881: return(READSTAT);
! 882: }
! 883:
! 884: int
! 885: rs_write_coord(FILE *savef, coord c)
! 886: {
! 887: if (write_error)
! 888: return(WRITESTAT);
! 889:
! 890: rs_write_int(savef, c.x);
! 891: rs_write_int(savef, c.y);
! 892:
! 893: return(WRITESTAT);
! 894: }
! 895:
! 896: int
! 897: rs_read_coord(FILE *inf, coord *c)
! 898: {
! 899: coord in;
! 900:
! 901: if (read_error || format_error)
! 902: return(READSTAT);
! 903:
! 904: rs_read_int(inf,&in.x);
! 905: rs_read_int(inf,&in.y);
! 906:
! 907: if (READSTAT == 0)
! 908: {
! 909: c->x = in.x;
! 910: c->y = in.y;
! 911: }
! 912:
! 913: return(READSTAT);
! 914: }
! 915:
! 916: int
! 917: rs_write_coord_list(FILE *savef, struct linked_list *l)
! 918: {
! 919: rs_write_marker(savef, RSID_COORDLIST);
! 920: rs_write_int(savef, list_size(l));
! 921:
! 922: while (l != NULL)
! 923: {
! 924: rs_write_coord(savef, *(coord *) l->l_data);
! 925: l = l->l_next;
! 926: }
! 927:
! 928: return(WRITESTAT);
! 929: }
! 930:
! 931: int
! 932: rs_read_coord_list(FILE *inf, struct linked_list **list)
! 933: {
! 934: int i, cnt;
! 935: struct linked_list *l = NULL, *previous = NULL, *head = NULL;
! 936:
! 937: rs_read_marker(inf, RSID_COORDLIST);
! 938:
! 939: if (rs_read_int(inf,&cnt) != 0)
! 940: return(READSTAT);
! 941:
! 942: for (i = 0; i < cnt; i++)
! 943: {
! 944: l = new_item(sizeof(coord));
! 945: l->l_prev = previous;
! 946:
! 947: if (previous != NULL)
! 948: previous->l_next = l;
! 949:
! 950: rs_read_coord(inf,(coord *) l->l_data);
! 951:
! 952: if (previous == NULL)
! 953: head = l;
! 954:
! 955: previous = l;
! 956: }
! 957:
! 958: if (l != NULL)
! 959: l->l_next = NULL;
! 960:
! 961: *list = head;
! 962:
! 963: return(READSTAT);
! 964: }
! 965:
! 966: int
! 967: rs_write_window(FILE *savef, WINDOW *win)
! 968: {
! 969: int row,col,height,width;
! 970:
! 971: if (write_error)
! 972: return(WRITESTAT);
! 973:
! 974: width = getmaxx(win);
! 975: height = getmaxy(win);
! 976:
! 977: rs_write_marker(savef,RSID_WINDOW);
! 978: rs_write_int(savef,height);
! 979: rs_write_int(savef,width);
! 980:
! 981: for(row=0;row<height;row++)
! 982: for(col=0;col<width;col++)
! 983: if (rs_write_int(savef, mvwinch(win,row,col)) != 0)
! 984: return(WRITESTAT);
! 985:
! 986: return(WRITESTAT);
! 987: }
! 988:
! 989: int
! 990: rs_read_window(FILE *inf, WINDOW *win)
! 991: {
! 992: int row,col,maxlines,maxcols,value,width,height;
! 993:
! 994: if (read_error || format_error)
! 995: return(READSTAT);
! 996:
! 997: width = getmaxx(win);
! 998: height = getmaxy(win);
! 999:
! 1000: rs_read_marker(inf, RSID_WINDOW);
! 1001:
! 1002: rs_read_int(inf, &maxlines);
! 1003: rs_read_int(inf, &maxcols);
! 1004:
! 1005: for(row = 0; row < maxlines; row++)
! 1006: for(col = 0; col < maxcols; col++)
! 1007: {
! 1008: if (rs_read_int(inf, &value) != 0)
! 1009: return(READSTAT);
! 1010:
! 1011: if ((row < height) && (col < width))
! 1012: mvwaddch(win,row,col,value);
! 1013: }
! 1014:
! 1015: return(READSTAT);
! 1016: }
! 1017:
! 1018: /******************************************************************************/
! 1019:
! 1020: void *
! 1021: get_list_item(struct linked_list *l, int i)
! 1022: {
! 1023: int count;
! 1024:
! 1025: for(count = 0; l != NULL; count++, l = l->l_next)
! 1026: if (count == i)
! 1027: return(l->l_data);
! 1028:
! 1029: return(NULL);
! 1030: }
! 1031:
! 1032: int
! 1033: find_list_ptr(struct linked_list *l, void *ptr)
! 1034: {
! 1035: int count;
! 1036:
! 1037: for(count = 0; l != NULL; count++, l = l->l_next)
! 1038: if (l->l_data == ptr)
! 1039: return(count);
! 1040:
! 1041: return(-1);
! 1042: }
! 1043:
! 1044: int
! 1045: list_size(struct linked_list *l)
! 1046: {
! 1047: int count;
! 1048:
! 1049: for(count = 0; l != NULL; count++, l = l->l_next)
! 1050: ;
! 1051:
! 1052: return(count);
! 1053: }
! 1054:
! 1055: /******************************************************************************/
! 1056:
! 1057: int
! 1058: rs_write_levtype(FILE *savef, LEVTYPE c)
! 1059: {
! 1060: int lt;
! 1061:
! 1062: switch(c)
! 1063: {
! 1064: case NORMLEV: lt = 1; break;
! 1065: case POSTLEV: lt = 2; break;
! 1066: case MAZELEV: lt = 3; break;
! 1067: case OUTSIDE: lt = 4; break;
! 1068: case STARTLEV: lt = 5; break;
! 1069: default: lt = -1; break;
! 1070: }
! 1071:
! 1072: rs_write_int(savef,lt);
! 1073:
! 1074: return(WRITESTAT);
! 1075: }
! 1076:
! 1077: int
! 1078: rs_read_levtype(FILE *inf, LEVTYPE *l)
! 1079: {
! 1080: int lt;
! 1081:
! 1082: rs_read_int(inf, <);
! 1083:
! 1084: switch(lt)
! 1085: {
! 1086: case 1: *l = NORMLEV; break;
! 1087: case 2: *l = POSTLEV; break;
! 1088: case 3: *l = MAZELEV; break;
! 1089: case 4: *l = OUTSIDE; break;
! 1090: case 5: *l = STARTLEV; break;
! 1091: default: *l = NORMLEV; break;
! 1092: }
! 1093:
! 1094: return(READSTAT);
! 1095: }
! 1096:
! 1097: int
! 1098: rs_write_stats(FILE *savef, struct stats *s)
! 1099: {
! 1100: if (write_error)
! 1101: return(WRITESTAT);
! 1102:
! 1103: rs_write_marker(savef, RSID_STATS);
! 1104: rs_write_short(savef, s->s_str);
! 1105: rs_write_short(savef, s->s_intel);
! 1106: rs_write_short(savef, s->s_wisdom);
! 1107: rs_write_short(savef, s->s_dext);
! 1108: rs_write_short(savef, s->s_const);
! 1109: rs_write_short(savef, s->s_charisma);
! 1110: rs_write_ulong(savef, s->s_exp);
! 1111: rs_write_int(savef, s->s_lvladj);
! 1112: rs_write_int(savef, s->s_lvl);
! 1113: rs_write_int(savef, s->s_arm);
! 1114: rs_write_int(savef, s->s_hpt);
! 1115: rs_write_int(savef, s->s_pack);
! 1116: rs_write_int(savef, s->s_carry);
! 1117: rs_write(savef, s->s_dmg, sizeof(s->s_dmg));
! 1118:
! 1119: return(WRITESTAT);
! 1120: }
! 1121:
! 1122: int
! 1123: rs_read_stats(FILE *inf, struct stats *s)
! 1124: {
! 1125: if (read_error || format_error)
! 1126: return(READSTAT);
! 1127:
! 1128: rs_read_marker(inf, RSID_STATS);
! 1129: rs_read_short(inf,&s->s_str);
! 1130: rs_read_short(inf,&s->s_intel);
! 1131: rs_read_short(inf,&s->s_wisdom);
! 1132: rs_read_short(inf,&s->s_dext);
! 1133: rs_read_short(inf,&s->s_const);
! 1134: rs_read_short(inf,&s->s_charisma);
! 1135: rs_read_ulong(inf,&s->s_exp);
! 1136: rs_read_int(inf,&s->s_lvladj);
! 1137: rs_read_int(inf,&s->s_lvl);
! 1138: rs_read_int(inf,&s->s_arm);
! 1139: rs_read_int(inf,&s->s_hpt);
! 1140: rs_read_int(inf,&s->s_pack);
! 1141: rs_read_int(inf,&s->s_carry);
! 1142: rs_read(inf,s->s_dmg,sizeof(s->s_dmg));
! 1143:
! 1144: return(READSTAT);
! 1145: }
! 1146:
! 1147: int
! 1148: rs_write_magic_items(FILE *savef, struct magic_item *i, int count)
! 1149: {
! 1150: int n;
! 1151:
! 1152: rs_write_marker(savef, RSID_MAGICITEMS);
! 1153: rs_write_int(savef, count);
! 1154:
! 1155: for(n=0;n<count;n++)
! 1156: {
! 1157: /* rs_write(savef,i[n].mi_name,sizeof(i[n].mi_name)); */
! 1158: rs_write_int(savef,i[n].mi_prob);
! 1159: /* rs_write_int(savef,i[n].mi_worth); */
! 1160: /* rs_write_int(savef,i[n].mi_curse); */
! 1161: /* rs_write_int(savef,i[n].mi_bless); */
! 1162: }
! 1163:
! 1164: return(WRITESTAT);
! 1165: }
! 1166:
! 1167: int
! 1168: rs_read_magic_items(FILE *inf, struct magic_item *mi, int count)
! 1169: {
! 1170: int n;
! 1171: int value;
! 1172:
! 1173: rs_read_marker(inf, RSID_MAGICITEMS);
! 1174:
! 1175: rs_read_int(inf, &value);
! 1176:
! 1177: if (value != count)
! 1178: format_error = 1;
! 1179: else
! 1180: {
! 1181: for(n = 0; n < value; n++)
! 1182: {
! 1183: /* rs_read(inf,mi[n].mi_name,sizeof(mi[n].mi_name)); */
! 1184: rs_read_int(inf,&mi[n].mi_prob);
! 1185: /* rs_read_int(inf,&mi[n].mi_worth); */
! 1186: /* rs_read_int(inf,&mi[n].mi_curse); */
! 1187: /* rs_read_int(inf,&mi[n].mi_bless); */
! 1188: }
! 1189: }
! 1190:
! 1191: return(READSTAT);
! 1192: }
! 1193:
! 1194: int
! 1195: rs_write_scrolls(FILE *savef)
! 1196: {
! 1197: int i;
! 1198:
! 1199: if (write_error)
! 1200: return(WRITESTAT);
! 1201:
! 1202: for(i = 0; i < MAXSCROLLS; i++)
! 1203: {
! 1204: rs_write_string(savef, s_names[i]);
! 1205: rs_write_boolean(savef,s_know[i]);
! 1206: rs_write_string(savef,s_guess[i]);
! 1207: }
! 1208:
! 1209: return(WRITESTAT);
! 1210: }
! 1211:
! 1212: int
! 1213: rs_read_scrolls(FILE *inf)
! 1214: {
! 1215: int i;
! 1216:
! 1217: if (read_error || format_error)
! 1218: return(READSTAT);
! 1219:
! 1220: for(i = 0; i < MAXSCROLLS; i++)
! 1221: {
! 1222: rs_read_new_string(inf,&s_names[i]);
! 1223: rs_read_boolean(inf,&s_know[i]);
! 1224: rs_read_new_string(inf,&s_guess[i]);
! 1225: }
! 1226:
! 1227: return(READSTAT);
! 1228: }
! 1229:
! 1230: int
! 1231: rs_write_potions(FILE *savef)
! 1232: {
! 1233: int i;
! 1234:
! 1235: if (write_error)
! 1236: return(WRITESTAT);
! 1237:
! 1238: for(i = 0; i < MAXPOTIONS; i++)
! 1239: {
! 1240: rs_write_string_index(savef,rainbow,cNCOLORS,p_colors[i]);
! 1241: rs_write_boolean(savef,p_know[i]);
! 1242: rs_write_string(savef,p_guess[i]);
! 1243: }
! 1244:
! 1245: return(WRITESTAT);
! 1246: }
! 1247:
! 1248: int
! 1249: rs_read_potions(FILE *inf)
! 1250: {
! 1251: int i;
! 1252:
! 1253: if (read_error || format_error)
! 1254: return(READSTAT);
! 1255:
! 1256: for(i = 0; i < MAXPOTIONS; i++)
! 1257: {
! 1258: rs_read_string_index(inf,rainbow,cNCOLORS,&p_colors[i]);
! 1259: rs_read_boolean(inf,&p_know[i]);
! 1260: rs_read_new_string(inf,&p_guess[i]);
! 1261: }
! 1262:
! 1263: return(READSTAT);
! 1264: }
! 1265:
! 1266: int
! 1267: rs_write_rings(FILE *savef)
! 1268: {
! 1269: int i;
! 1270:
! 1271: if (write_error)
! 1272: return(WRITESTAT);
! 1273:
! 1274: for(i = 0; i < MAXRINGS; i++)
! 1275: {
! 1276: rs_write_string_index(savef,stones,cNSTONES,r_stones[i]);
! 1277: rs_write_boolean(savef,r_know[i]);
! 1278: rs_write_string(savef,r_guess[i]);
! 1279: }
! 1280:
! 1281: return(WRITESTAT);
! 1282: }
! 1283:
! 1284: int
! 1285: rs_read_rings(FILE *inf)
! 1286: {
! 1287: int i;
! 1288:
! 1289: if (read_error || format_error)
! 1290: return(READSTAT);
! 1291:
! 1292: for(i = 0; i < MAXRINGS; i++)
! 1293: {
! 1294: rs_read_string_index(inf,stones,cNSTONES,&r_stones[i]);
! 1295: rs_read_boolean(inf,&r_know[i]);
! 1296: rs_read_new_string(inf,&r_guess[i]);
! 1297: }
! 1298:
! 1299: return(READSTAT);
! 1300: }
! 1301:
! 1302: int
! 1303: rs_write_misc(FILE *savef)
! 1304: {
! 1305: int i;
! 1306:
! 1307: if (read_error || format_error)
! 1308: return(READSTAT);
! 1309:
! 1310: for(i = 0; i < MAXMM; i++)
! 1311: {
! 1312: rs_write_boolean(savef,m_know[i]);
! 1313: rs_write_string(savef,m_guess[i]);
! 1314: }
! 1315:
! 1316: return(READSTAT);
! 1317: }
! 1318:
! 1319: int
! 1320: rs_read_misc(FILE *inf)
! 1321: {
! 1322: int i;
! 1323:
! 1324: if (write_error)
! 1325: return(WRITESTAT);
! 1326:
! 1327: for(i = 0; i < MAXMM; i++)
! 1328: {
! 1329: rs_read_boolean(inf,&m_know[i]);
! 1330: rs_read_new_string(inf,&m_guess[i]);
! 1331: }
! 1332:
! 1333: return(WRITESTAT);
! 1334: }
! 1335:
! 1336: int
! 1337: rs_write_sticks(FILE *savef)
! 1338: {
! 1339: int i;
! 1340:
! 1341: if (write_error)
! 1342: return(WRITESTAT);
! 1343:
! 1344: rs_write_marker(savef, RSID_STICKS);
! 1345:
! 1346: for (i = 0; i < MAXSTICKS; i++)
! 1347: {
! 1348: if (strcmp(ws_type[i],"staff") == 0)
! 1349: {
! 1350: rs_write_int(savef,0);
! 1351: rs_write_string_index(savef,wood,cNWOOD,ws_made[i]);
! 1352: }
! 1353: else
! 1354: {
! 1355: rs_write_int(savef,1);
! 1356: rs_write_string_index(savef,metal,cNMETAL,ws_made[i]);
! 1357: }
! 1358:
! 1359: rs_write_boolean(savef, ws_know[i]);
! 1360: rs_write_string(savef, ws_guess[i]);
! 1361: }
! 1362:
! 1363: return(WRITESTAT);
! 1364: }
! 1365:
! 1366: int
! 1367: rs_read_sticks(FILE *inf)
! 1368: {
! 1369: int i = 0, j = 0, list = 0;
! 1370:
! 1371: if (read_error || format_error)
! 1372: return(READSTAT);
! 1373:
! 1374: rs_read_marker(inf, RSID_STICKS);
! 1375:
! 1376: for(i = 0; i < MAXSTICKS; i++)
! 1377: {
! 1378: rs_read_int(inf,&list);
! 1379: ws_made[i] = NULL;
! 1380:
! 1381: if (list == 0)
! 1382: {
! 1383: rs_read_string_index(inf,wood,cNWOOD,&ws_made[i]);
! 1384: ws_type[i] = "staff";
! 1385: }
! 1386: else
! 1387: {
! 1388: rs_read_string_index(inf,metal,cNMETAL,&ws_made[i]);
! 1389: ws_type[i] = "wand";
! 1390: }
! 1391: rs_read_boolean(inf, &ws_know[i]);
! 1392: rs_read_new_string(inf, &ws_guess[i]);
! 1393: }
! 1394:
! 1395: return(READSTAT);
! 1396: }
! 1397:
! 1398: /* Assigns a number to an alchemy jug associated with a fuse, so it can be
! 1399: * found and reassociated when restoring.
! 1400: * 1 - 31: slot in pack
! 1401: * 32+ : on floor
! 1402: * Hopefully monsters do not pick them up.
! 1403: */
! 1404: int number_alchemy_jug(struct object *obj) {
! 1405: struct object *tobj = NULL;
! 1406: struct linked_list *item;
! 1407: int i = 1;
! 1408: for (item = pack; item != NULL; item = next(item), i++) {
! 1409: tobj = OBJPTR(item);
! 1410: if (tobj == obj &&
! 1411: tobj->o_type == MM &&
! 1412: tobj->o_which== MM_JUG)
! 1413: break;
! 1414: }
! 1415: if (item == NULL) {
! 1416: for (item = lvl_obj, i = 32; item != NULL; item = next(item), i++) {
! 1417: tobj = OBJPTR(item);
! 1418: if (tobj == obj &&
! 1419: tobj->o_type == MM &&
! 1420: tobj->o_which== MM_JUG)
! 1421: break;
! 1422: }
! 1423: }
! 1424: if (item == NULL)
! 1425: return 0;
! 1426: return i;
! 1427: }
! 1428:
! 1429: /* Takes an alchemy jug number and tracks down the object. */
! 1430: struct object *find_alchemy_jug(int n) {
! 1431: struct object *tobj;
! 1432: struct linked_list *item;
! 1433:
! 1434: if (n <= 0) {
! 1435: return NULL;
! 1436: }
! 1437: else if (n < 32) {
! 1438: item = pack;
! 1439: n -= 1;
! 1440: }
! 1441: else if (n < 1024) {
! 1442: item = lvl_obj;
! 1443: n -= 32;
! 1444: }
! 1445: else {
! 1446: /* This is likely a bug, not 1024 actual items on the floor. */
! 1447: return NULL;
! 1448: }
! 1449: while (item != NULL && n > 0) {
! 1450: item = next(item);
! 1451: n--;
! 1452: }
! 1453: if (item == NULL)
! 1454: return NULL;
! 1455: tobj = OBJPTR(item);
! 1456: if (tobj->o_type != MM || tobj->o_which != MM_JUG)
! 1457: return NULL;
! 1458: return tobj;
! 1459: }
! 1460:
! 1461: int
! 1462: rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
! 1463: {
! 1464: int i = 0;
! 1465: int func = 0;
! 1466:
! 1467: if (write_error)
! 1468: return(WRITESTAT);
! 1469:
! 1470: rs_write_marker(savef, RSID_DAEMONS);
! 1471: rs_write_int(savef, count);
! 1472:
! 1473: for(i = 0; i < count; i++)
! 1474: {
! 1475: if (d_list[i].d_func == rollwand)
! 1476: func = 1;
! 1477: else if (d_list[i].d_func == doctor)
! 1478: func = 2;
! 1479: else if (d_list[i].d_func == stomach)
! 1480: func = 3;
! 1481: else if (d_list[i].d_func == trap_look)
! 1482: func = 4;
! 1483: else if (d_list[i].d_func == eat_gold)
! 1484: func = 5;
! 1485: else if (d_list[i].d_func == ring_search)
! 1486: func = 6;
! 1487: else if (d_list[i].d_func == ring_teleport)
! 1488: func = 7;
! 1489: else if (d_list[i].d_func == fumble)
! 1490: func = 8;
! 1491: else if (d_list[i].d_func == strangle)
! 1492: func = 9;
! 1493: else if (d_list[i].d_func == unconfuse)
! 1494: func = 10;
! 1495: else if (d_list[i].d_func == swander)
! 1496: func = 11;
! 1497: else if (d_list[i].d_func == spell_recovery)
! 1498: func = 12;
! 1499: else if (d_list[i].d_func == chant_recovery)
! 1500: func = 13;
! 1501: else if (d_list[i].d_func == prayer_recovery)
! 1502: func = 14;
! 1503: else if (d_list[i].d_func == cure_disease)
! 1504: func = 15;
! 1505: else if (d_list[i].d_func == unstink)
! 1506: func = 16;
! 1507: else if (d_list[i].d_func == res_strength)
! 1508: func = 17;
! 1509: else if (d_list[i].d_func == undance)
! 1510: func = 18;
! 1511: else if (d_list[i].d_func == suffocate)
! 1512: func = 19;
! 1513: else if (d_list[i].d_func == wghtchk)
! 1514: func = 20;
! 1515: else if (d_list[i].d_func == dust_appear)
! 1516: func = 21;
! 1517: else if (d_list[i].d_func == unchoke)
! 1518: func = 22;
! 1519: else if (d_list[i].d_func == sight)
! 1520: func = 23;
! 1521: else if (d_list[i].d_func == changeclass)
! 1522: func = 24;
! 1523: else if (d_list[i].d_func == cloak_charge)
! 1524: func = 25;
! 1525: else if (d_list[i].d_func == quill_charge)
! 1526: func = 26;
! 1527: else if (d_list[i].d_func == nohaste)
! 1528: func = 27;
! 1529: else if (d_list[i].d_func == noslow)
! 1530: func = 28;
! 1531: else if (d_list[i].d_func == unclrhead)
! 1532: func = 29;
! 1533: else if (d_list[i].d_func == unsee)
! 1534: func = 30;
! 1535: else if (d_list[i].d_func == unphase)
! 1536: func = 31;
! 1537: else if (d_list[i].d_func == land)
! 1538: func = 32;
! 1539: else if (d_list[i].d_func == appear)
! 1540: func = 33;
! 1541: else if (d_list[i].d_func == unskill)
! 1542: func = 34;
! 1543: else if (d_list[i].d_func == nofire)
! 1544: func = 35;
! 1545: else if (d_list[i].d_func == nocold)
! 1546: func = 36;
! 1547: else if (d_list[i].d_func == nobolt)
! 1548: func = 37;
! 1549: else if (d_list[i].d_func == alchemy)
! 1550: func = 38;
! 1551: else if (d_list[i].d_func == NULL)
! 1552: func = 0;
! 1553: else
! 1554: func = -1;
! 1555:
! 1556: rs_write_int(savef, d_list[i].d_type);
! 1557: rs_write_int(savef, func);
! 1558:
! 1559: if (d_list[i].d_func == doctor)
! 1560: rs_write_int(savef, 1);
! 1561: else if (d_list[i].d_func == eat_gold)
! 1562: {
! 1563: int index;
! 1564: index = find_list_ptr(player.t_pack, d_list[i].d_.varg);
! 1565: rs_write_int(savef,index);
! 1566: }
! 1567: else if (d_list[i].d_func == changeclass)
! 1568: {
! 1569: rs_write_int(savef, d_list[i].d_.arg);
! 1570: }
! 1571: else if (d_list[i].d_func == cloak_charge)
! 1572: {
! 1573: int index;
! 1574: index = find_list_ptr(player.t_pack, d_list[i].d_.varg);
! 1575: rs_write_int(savef,index);
! 1576: }
! 1577: else if (d_list[i].d_func == alchemy)
! 1578: {
! 1579: rs_write_int(savef, number_alchemy_jug(d_list[i].d_.varg));
! 1580: }
! 1581: else
! 1582: rs_write_int(savef, d_list[i].d_.arg);
! 1583:
! 1584: rs_write_int(savef, d_list[i].d_time);
! 1585: }
! 1586:
! 1587: return(WRITESTAT);
! 1588: }
! 1589:
! 1590: int
! 1591: rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count)
! 1592: {
! 1593: int i = 0;
! 1594: int func = 0;
! 1595: int value = 0;
! 1596: int dummy = 0;
! 1597:
! 1598: if (read_error || format_error)
! 1599: return(READSTAT);
! 1600:
! 1601: rs_read_marker(inf, RSID_DAEMONS);
! 1602: rs_read_int(inf, &value);
! 1603:
! 1604: if (value > count)
! 1605: format_error = TRUE;
! 1606:
! 1607: for(i=0; i < count; i++)
! 1608: {
! 1609: func = 0;
! 1610: rs_read_int(inf, &d_list[i].d_type);
! 1611: rs_read_int(inf, &func);
! 1612:
! 1613: switch(func)
! 1614: {
! 1615: case 1: d_list[i].d_func = rollwand;
! 1616: break;
! 1617: case 2: d_list[i].d_func = doctor;
! 1618: break;
! 1619: case 3: d_list[i].d_func = stomach;
! 1620: break;
! 1621: case 4: d_list[i].d_func = trap_look;
! 1622: break;
! 1623: case 5: d_list[i].d_func = eat_gold;
! 1624: break;
! 1625: case 6: d_list[i].d_func = ring_search;
! 1626: break;
! 1627: case 7: d_list[i].d_func = ring_teleport;
! 1628: break;
! 1629: case 8: d_list[i].d_func = fumble;
! 1630: break;
! 1631: case 9: d_list[i].d_func = strangle;
! 1632: break;
! 1633: case 10: d_list[i].d_func = unconfuse;
! 1634: break;
! 1635: case 11: d_list[i].d_func = swander;
! 1636: break;
! 1637: case 12: d_list[i].d_func = spell_recovery;
! 1638: break;
! 1639: case 13: d_list[i].d_func = chant_recovery;
! 1640: break;
! 1641: case 14: d_list[i].d_func = prayer_recovery;
! 1642: break;
! 1643: case 15: d_list[i].d_func = cure_disease;
! 1644: break;
! 1645: case 16: d_list[i].d_func = unstink;
! 1646: break;
! 1647: case 17: d_list[i].d_func = res_strength;
! 1648: break;
! 1649: case 18: d_list[i].d_func = undance;
! 1650: break;
! 1651: case 19: d_list[i].d_func = suffocate;
! 1652: break;
! 1653: case 20: d_list[i].d_func = wghtchk;
! 1654: break;
! 1655: case 21: d_list[i].d_func = dust_appear;
! 1656: break;
! 1657: case 22: d_list[i].d_func = unchoke;
! 1658: break;
! 1659: case 23: d_list[i].d_func = sight;
! 1660: break;
! 1661: case 24: d_list[i].d_func = changeclass;
! 1662: break;
! 1663: case 25: d_list[i].d_func = cloak_charge;
! 1664: break;
! 1665: case 26: d_list[i].d_func = quill_charge;
! 1666: break;
! 1667: case 27: d_list[i].d_func = nohaste;
! 1668: break;
! 1669: case 28: d_list[i].d_func = noslow;
! 1670: break;
! 1671: case 29: d_list[i].d_func = unclrhead;
! 1672: break;
! 1673: case 30: d_list[i].d_func = unsee;
! 1674: break;
! 1675: case 31: d_list[i].d_func = unphase;
! 1676: break;
! 1677: case 32: d_list[i].d_func = land;
! 1678: break;
! 1679: case 33: d_list[i].d_func = appear;
! 1680: break;
! 1681: case 34: d_list[i].d_func = unskill;
! 1682: break;
! 1683: case 35: d_list[i].d_func = nofire;
! 1684: break;
! 1685: case 36: d_list[i].d_func = nocold;
! 1686: break;
! 1687: case 37: d_list[i].d_func = nobolt;
! 1688: break;
! 1689: case 38: d_list[i].d_func = alchemy;
! 1690: break;
! 1691: case 0:
! 1692: case -1:
! 1693: default: d_list[i].d_func = NULL;
! 1694: break;
! 1695: }
! 1696:
! 1697: if (d_list[i].d_func == doctor)
! 1698: {
! 1699: rs_read_int(inf, &dummy);
! 1700: d_list[i].d_.varg = &player;
! 1701: }
! 1702: else if (d_list[i].d_func == eat_gold)
! 1703: {
! 1704: rs_read_int(inf, &dummy);
! 1705: d_list[i].d_.varg = get_list_item(player.t_pack, dummy);
! 1706: if (d_list[i].d_.varg == NULL)
! 1707: d_list[i].d_type = 0;
! 1708: }
! 1709: else if (d_list[i].d_func == changeclass)
! 1710: {
! 1711: rs_read_int(inf, &d_list[i].d_.arg);
! 1712: }
! 1713: else if (d_list[i].d_func == cloak_charge)
! 1714: {
! 1715: rs_read_int(inf, &dummy);
! 1716: d_list[i].d_.varg = get_list_item(player.t_pack,dummy);
! 1717:
! 1718: if (d_list[i].d_.varg == NULL)
! 1719: d_list[i].d_type = 0;
! 1720: }
! 1721: else if (d_list[i].d_func == alchemy)
! 1722: {
! 1723: rs_read_int(inf, &dummy);
! 1724: d_list[i].d_.varg = find_alchemy_jug(dummy);
! 1725: if (d_list[i].d_.varg == NULL)
! 1726: d_list[i].d_type = 0;
! 1727: }
! 1728: else
! 1729: rs_read_int(inf, &d_list[i].d_.arg);
! 1730:
! 1731: rs_read_int(inf, &d_list[i].d_time);
! 1732:
! 1733: if (d_list[i].d_func == NULL)
! 1734: {
! 1735: d_list[i].d_time = 0;
! 1736: d_list[i].d_.varg = NULL;
! 1737: d_list[i].d_type = 0;
! 1738: }
! 1739:
! 1740: }
! 1741:
! 1742: return(READSTAT);
! 1743: }
! 1744:
! 1745: int
! 1746: rs_write_room(FILE *savef, struct room *r)
! 1747: {
! 1748: struct linked_list *l;
! 1749: int i;
! 1750:
! 1751: if (write_error)
! 1752: return(WRITESTAT);
! 1753:
! 1754: rs_write_coord(savef, r->r_pos);
! 1755: rs_write_coord(savef, r->r_max);
! 1756: rs_write_long(savef, r->r_flags);
! 1757:
! 1758: l = r->r_fires;
! 1759: i = list_size(l);
! 1760:
! 1761: rs_write_int(savef, i);
! 1762:
! 1763: if (i >0)
! 1764: while (l != NULL)
! 1765: {
! 1766: i = find_list_ptr(mlist, l->l_data);
! 1767: rs_write_int(savef,i);
! 1768: l = l->l_next;
! 1769: }
! 1770:
! 1771: rs_write_coord_list(savef, r->r_exit);
! 1772:
! 1773: return(WRITESTAT);
! 1774: }
! 1775:
! 1776: int
! 1777: rs_read_room(FILE *inf, struct room *r)
! 1778: {
! 1779: int value = 0, n = 0, i = 0, index = 0, id = 0;
! 1780: struct linked_list *fires=NULL, *item = NULL;
! 1781:
! 1782: if (read_error || format_error)
! 1783: return(READSTAT);
! 1784:
! 1785: rs_read_coord(inf,&r->r_pos);
! 1786: rs_read_coord(inf,&r->r_max);
! 1787: rs_read_long(inf,&r->r_flags);
! 1788:
! 1789: rs_read_int(inf, &i);
! 1790: fires = NULL;
! 1791:
! 1792: while (i>0)
! 1793: {
! 1794: rs_read_int(inf,&index);
! 1795:
! 1796: if (index >= 0)
! 1797: {
! 1798: void *data;
! 1799: data = get_list_item(mlist,index);
! 1800: item = creat_item();
! 1801: item->l_data = data;
! 1802: if (fires == NULL)
! 1803: fires = item;
! 1804: else
! 1805: attach(fires,item);
! 1806: }
! 1807: i--;
! 1808: }
! 1809:
! 1810: r->r_fires=fires;
! 1811:
! 1812: rs_read_coord_list(inf, &r->r_exit);
! 1813:
! 1814: return(READSTAT);
! 1815: }
! 1816:
! 1817: int
! 1818: rs_write_rooms(FILE *savef, struct room r[], int count)
! 1819: {
! 1820: int n = 0;
! 1821:
! 1822: if (write_error)
! 1823: return(WRITESTAT);
! 1824:
! 1825: rs_write_int(savef, count);
! 1826:
! 1827: for(n = 0; n < count; n++)
! 1828: rs_write_room(savef, &r[n]);
! 1829:
! 1830: return(WRITESTAT);
! 1831: }
! 1832:
! 1833: int
! 1834: rs_read_rooms(FILE *inf, struct room *r, int count)
! 1835: {
! 1836: int value = 0, n = 0;
! 1837:
! 1838: if (read_error || format_error)
! 1839: return(READSTAT);
! 1840:
! 1841: rs_read_int(inf,&value);
! 1842:
! 1843: if (value > count)
! 1844: format_error = TRUE;
! 1845:
! 1846: for(n = 0; n < value; n++)
! 1847: rs_read_room(inf,&r[n]);
! 1848:
! 1849: return(READSTAT);
! 1850: }
! 1851:
! 1852: int
! 1853: rs_write_room_reference(FILE *savef, struct room *rp)
! 1854: {
! 1855: int i, room = -1;
! 1856:
! 1857: if (write_error)
! 1858: return(WRITESTAT);
! 1859:
! 1860: for (i = 0; i < MAXROOMS; i++)
! 1861: if (&rooms[i] == rp)
! 1862: room = i;
! 1863:
! 1864: rs_write_int(savef, room);
! 1865:
! 1866: return(WRITESTAT);
! 1867: }
! 1868:
! 1869: int
! 1870: rs_read_room_reference(FILE *inf, struct room **rp)
! 1871: {
! 1872: int i;
! 1873:
! 1874: if (read_error || format_error)
! 1875: return(READSTAT);
! 1876:
! 1877: rs_read_int(inf, &i);
! 1878:
! 1879: *rp = &rooms[i];
! 1880:
! 1881: return(READSTAT);
! 1882: }
! 1883:
! 1884: int
! 1885: rs_write_door_reference(FILE *savef, coord *exit)
! 1886: {
! 1887: int i, idx;
! 1888:
! 1889: for (i = 0; i < MAXROOMS; i++)
! 1890: {
! 1891: idx = find_list_ptr(rooms[i].r_exit, exit);
! 1892:
! 1893: if (idx != -1)
! 1894: break;
! 1895: }
! 1896:
! 1897: if (i >= MAXROOMS)
! 1898: {
! 1899: rs_write_int(savef,-1);
! 1900: rs_write_int(savef,-1);
! 1901: if (exit != NULL)
! 1902: abort();
! 1903: }
! 1904: else
! 1905: {
! 1906: rs_write_int(savef,i);
! 1907: rs_write_int(savef,idx);
! 1908: }
! 1909:
! 1910: return(WRITESTAT);
! 1911: }
! 1912:
! 1913: int
! 1914: rs_read_door_reference(FILE *inf, coord **exit)
! 1915: {
! 1916: int i, idx;
! 1917:
! 1918: rs_read_int(inf, &i);
! 1919: rs_read_int(inf, &idx);
! 1920:
! 1921: if ( (i == -1) || (idx == -1) )
! 1922: *exit = NULL;
! 1923: else
! 1924: *exit = get_list_item(rooms[i].r_exit, idx);
! 1925:
! 1926: return(READSTAT);
! 1927: }
! 1928:
! 1929: int
! 1930: rs_write_traps(FILE *savef, struct trap *trap,int count)
! 1931: {
! 1932: int n;
! 1933:
! 1934: rs_write_int(savef, RSID_TRAP);
! 1935: rs_write_int(savef, count);
! 1936:
! 1937: for(n=0; n<count; n++)
! 1938: {
! 1939: rs_write_char(savef, trap[n].tr_type);
! 1940: rs_write_char(savef, trap[n].tr_show);
! 1941: rs_write_coord(savef, trap[n].tr_pos);
! 1942: rs_write_long(savef, trap[n].tr_flags);
! 1943: }
! 1944: return (WRITESTAT);
! 1945: }
! 1946:
! 1947: int
! 1948: rs_read_traps(FILE *inf, struct trap *trap, int count)
! 1949: {
! 1950: int id = 0, value = 0, n = 0;
! 1951:
! 1952: if (rs_read_int(inf,&id) != 0)
! 1953: format_error = TRUE;
! 1954: else if (rs_read_int(inf,&value) != 0)
! 1955: {
! 1956: if (value != count)
! 1957: format_error = TRUE;
! 1958: }
! 1959: else
! 1960: {
! 1961: for(n=0;n<value;n++)
! 1962: {
! 1963: rs_read_char(inf,&trap[n].tr_type);
! 1964: rs_read_char(inf,&trap[n].tr_show);
! 1965: rs_read_coord(inf,&trap[n].tr_pos);
! 1966: rs_read_long(inf,&trap[n].tr_flags);
! 1967: }
! 1968: }
! 1969:
! 1970: return(READSTAT);
! 1971: }
! 1972:
! 1973: int
! 1974: rs_write_monsters(FILE *savef, struct monster *m, int count)
! 1975: {
! 1976: int n;
! 1977:
! 1978: if (write_error)
! 1979: return(WRITESTAT);
! 1980:
! 1981: rs_write_marker(savef, RSID_MONSTERS);
! 1982: rs_write_int(savef, count);
! 1983:
! 1984: for(n=0;n<count;n++)
! 1985: {
! 1986: rs_write_boolean(savef, m[n].m_normal);
! 1987: rs_write_boolean(savef, m[n].m_wander);
! 1988: rs_write_short(savef, m[n].m_numsum);
! 1989: }
! 1990:
! 1991: return(WRITESTAT);
! 1992: }
! 1993:
! 1994: int
! 1995: rs_read_monsters(FILE *inf, struct monster *m, int count)
! 1996: {
! 1997: int value = 0, n = 0;
! 1998:
! 1999: if (read_error || format_error)
! 2000: return(READSTAT);
! 2001:
! 2002: rs_read_marker(inf, RSID_MONSTERS);
! 2003:
! 2004: rs_read_int(inf, &value);
! 2005:
! 2006: if (value != count)
! 2007: format_error = TRUE;
! 2008:
! 2009: for(n = 0; n < count; n++)
! 2010: {
! 2011: rs_read_boolean(inf, &m[n].m_normal);
! 2012: rs_read_boolean(inf, &m[n].m_wander);
! 2013: rs_read_short(inf, &m[n].m_numsum);
! 2014: }
! 2015:
! 2016: return(READSTAT);
! 2017: }
! 2018:
! 2019: int
! 2020: rs_write_object(FILE *savef, struct object *o)
! 2021: {
! 2022: if (write_error)
! 2023: return(WRITESTAT);
! 2024:
! 2025: rs_write_marker(savef, RSID_OBJECT);
! 2026: rs_write_int(savef, o->o_type);
! 2027: rs_write_coord(savef, o->o_pos);
! 2028: rs_write_char(savef, o->o_launch);
! 2029: rs_write(savef, o->o_damage, sizeof(o->o_damage));
! 2030: rs_write(savef, o->o_hurldmg, sizeof(o->o_hurldmg));
! 2031: rs_write_object_list(savef, o->contents);
! 2032: rs_write_int(savef, o->o_count);
! 2033: rs_write_int(savef, o->o_which);
! 2034: rs_write_int(savef, o->o_hplus);
! 2035: rs_write_int(savef, o->o_dplus);
! 2036: rs_write_int(savef, o->o_ac);
! 2037: rs_write_long(savef, o->o_flags);
! 2038: rs_write_int(savef, o->o_group);
! 2039: rs_write_int(savef, o->o_weight);
! 2040: rs_write(savef, o->o_mark, MARKLEN);
! 2041:
! 2042:
! 2043: return(WRITESTAT);
! 2044: }
! 2045:
! 2046: int
! 2047: rs_read_object(FILE *inf, struct object *o)
! 2048: {
! 2049: if (read_error || format_error)
! 2050: return(READSTAT);
! 2051:
! 2052: rs_read_marker(inf, RSID_OBJECT);
! 2053: rs_read_int(inf, &o->o_type);
! 2054: rs_read_coord(inf, &o->o_pos);
! 2055: rs_read_char(inf, &o->o_launch);
! 2056: rs_read(inf, o->o_damage, sizeof(o->o_damage));
! 2057: rs_read(inf, o->o_hurldmg, sizeof(o->o_hurldmg));
! 2058: rs_read_object_list(inf,&o->contents);
! 2059: rs_read_int(inf, &o->o_count);
! 2060: rs_read_int(inf, &o->o_which);
! 2061: rs_read_int(inf, &o->o_hplus);
! 2062: rs_read_int(inf, &o->o_dplus);
! 2063: rs_read_int(inf, &o->o_ac);
! 2064: rs_read_long(inf,&o->o_flags);
! 2065: rs_read_int(inf, &o->o_group);
! 2066: rs_read_int(inf, &o->o_weight);
! 2067: rs_read(inf, o->o_mark, MARKLEN);
! 2068:
! 2069: return(READSTAT);
! 2070: }
! 2071:
! 2072: int
! 2073: rs_write_object_list(FILE *savef, struct linked_list *l)
! 2074: {
! 2075: if (write_error)
! 2076: return(WRITESTAT);
! 2077:
! 2078: rs_write_marker(savef, RSID_OBJECTLIST);
! 2079: rs_write_int(savef, list_size(l));
! 2080:
! 2081: for( ;l != NULL; l = l->l_next)
! 2082: rs_write_object(savef, OBJPTR(l));
! 2083:
! 2084: return(WRITESTAT);
! 2085: }
! 2086:
! 2087: int
! 2088: rs_read_object_list(FILE *inf, struct linked_list **list)
! 2089: {
! 2090: int i, cnt;
! 2091: struct linked_list *l = NULL, *previous = NULL, *head = NULL;
! 2092:
! 2093: if (read_error || format_error)
! 2094: return(READSTAT);
! 2095:
! 2096: rs_read_marker(inf, RSID_OBJECTLIST);
! 2097: rs_read_int(inf, &cnt);
! 2098:
! 2099: for (i = 0; i < cnt; i++)
! 2100: {
! 2101: l = new_item(sizeof(struct object));
! 2102:
! 2103: l->l_prev = previous;
! 2104:
! 2105: if (previous != NULL)
! 2106: previous->l_next = l;
! 2107:
! 2108: rs_read_object(inf,OBJPTR(l));
! 2109:
! 2110: if (previous == NULL)
! 2111: head = l;
! 2112:
! 2113: previous = l;
! 2114: }
! 2115:
! 2116: if (l != NULL)
! 2117: l->l_next = NULL;
! 2118:
! 2119: *list = head;
! 2120:
! 2121: return(READSTAT);
! 2122: }
! 2123:
! 2124: int
! 2125: rs_write_object_reference(FILE *savef, struct linked_list *list, struct object *item)
! 2126: {
! 2127: int i;
! 2128:
! 2129: if (write_error)
! 2130: return(WRITESTAT);
! 2131:
! 2132: i = find_list_ptr(list, item);
! 2133:
! 2134: rs_write_int(savef, i);
! 2135:
! 2136: return(WRITESTAT);
! 2137: }
! 2138:
! 2139: int
! 2140: rs_read_object_reference(FILE *inf, struct linked_list *list, struct object **item)
! 2141: {
! 2142: int i;
! 2143:
! 2144: if (read_error || format_error)
! 2145: return(READSTAT);
! 2146:
! 2147: rs_read_int(inf, &i);
! 2148:
! 2149: *item = get_list_item(list,i);
! 2150:
! 2151: return(READSTAT);
! 2152: }
! 2153:
! 2154: int
! 2155: find_thing_coord(struct linked_list *monlist, coord *c)
! 2156: {
! 2157: struct linked_list *mitem;
! 2158: struct thing *tp;
! 2159: int i = 0;
! 2160:
! 2161: for(mitem = monlist; mitem != NULL; mitem = mitem->l_next)
! 2162: {
! 2163: tp = THINGPTR(mitem);
! 2164:
! 2165: if (c == &tp->t_pos)
! 2166: return(i);
! 2167:
! 2168: i++;
! 2169: }
! 2170:
! 2171: return(-1);
! 2172: }
! 2173:
! 2174: int
! 2175: find_object_coord(struct linked_list *objlist, coord *c)
! 2176: {
! 2177: struct linked_list *oitem;
! 2178: struct object *obj;
! 2179: int i = 0;
! 2180:
! 2181: for(oitem = objlist; oitem != NULL; oitem = oitem->l_next)
! 2182: {
! 2183: obj = OBJPTR(oitem);
! 2184:
! 2185: if (c == &obj->o_pos)
! 2186: return(i);
! 2187:
! 2188: i++;
! 2189: }
! 2190:
! 2191: return(-1);
! 2192: }
! 2193:
! 2194: int
! 2195: rs_write_thing(FILE *savef, struct thing *t)
! 2196: {
! 2197: int i = -1;
! 2198:
! 2199: if (write_error)
! 2200: return(WRITESTAT);
! 2201:
! 2202: rs_write_marker(savef, RSID_THING);
! 2203:
! 2204: if (t == NULL)
! 2205: {
! 2206: rs_write_int(savef, 0);
! 2207: return(WRITESTAT);
! 2208: }
! 2209:
! 2210: rs_write_int(savef, 1);
! 2211: rs_write_boolean(savef,t->t_wasshot);
! 2212: rs_write_char(savef, t->t_type);
! 2213: rs_write_char(savef, t->t_disguise);
! 2214: rs_write_char(savef, t->t_oldch);
! 2215: rs_write_short(savef, t->t_ctype);
! 2216: rs_write_short(savef, t->t_index);
! 2217: rs_write_short(savef, t->t_no_move);
! 2218: rs_write_short(savef, t->t_quiet);
! 2219: rs_write_short(savef, t->t_movement);
! 2220: rs_write_short(savef, t->t_action);
! 2221: rs_write_short(savef, t->t_artifact);
! 2222: rs_write_short(savef, t->t_wand);
! 2223: rs_write_short(savef, t->t_summon);
! 2224: rs_write_short(savef, t->t_cast);
! 2225: rs_write_short(savef, t->t_breathe);
! 2226:
! 2227: rs_write_string(savef,t->t_name);
! 2228: rs_write_door_reference(savef, t->t_doorgoal);
! 2229:
! 2230: if (t->t_dest == &hero)
! 2231: {
! 2232: rs_write_int(savef,0);
! 2233: rs_write_int(savef,1);
! 2234: }
! 2235: else if (t->t_dest != NULL)
! 2236: {
! 2237: i = find_thing_coord(mlist, t->t_dest);
! 2238:
! 2239: if (i >= 0)
! 2240: {
! 2241: rs_write_int(savef,1);
! 2242: rs_write_int(savef,i);
! 2243: }
! 2244: else
! 2245: {
! 2246: i = find_object_coord(lvl_obj, t->t_dest);
! 2247:
! 2248: if (i >= 0)
! 2249: {
! 2250: rs_write_int(savef,2);
! 2251: rs_write_int(savef,i);
! 2252: }
! 2253: else
! 2254: {
! 2255: rs_write_int(savef,0);
! 2256: rs_write_int(savef,1); /* chase the hero anyway */
! 2257: }
! 2258: }
! 2259: }
! 2260: else
! 2261: {
! 2262: rs_write_int(savef,0);
! 2263: rs_write_int(savef,0);
! 2264: }
! 2265:
! 2266: rs_write_coord(savef, t->t_pos);
! 2267: rs_write_coord(savef, t->t_oldpos);
! 2268: rs_write_coord(savef, t->t_newpos);
! 2269: rs_write_ulongs(savef, t->t_flags, 16);
! 2270: rs_write_object_list(savef, t->t_pack);
! 2271: i = -1;
! 2272: if (t->t_using != NULL)
! 2273: i = find_list_ptr(t->t_pack, t->t_using->l_data);
! 2274: rs_write_int(savef, i);
! 2275: rs_write_int(savef, t->t_selection);
! 2276: rs_write_stats(savef, &t->t_stats);
! 2277: rs_write_stats(savef, &t->maxstats);
! 2278:
! 2279: return(WRITESTAT);
! 2280: }
! 2281:
! 2282: int
! 2283: rs_read_thing(FILE *inf, struct thing *t)
! 2284: {
! 2285: int listid = 0, index = -1;
! 2286:
! 2287: if (read_error || format_error)
! 2288: return(READSTAT);
! 2289:
! 2290: rs_read_marker(inf, RSID_THING);
! 2291:
! 2292: rs_read_int(inf, &index);
! 2293:
! 2294: if (index == 0)
! 2295: return(READSTAT);
! 2296:
! 2297: rs_read_boolean(inf, &t->t_wasshot);
! 2298: rs_read_char(inf, &t->t_type);
! 2299: rs_read_char(inf, &t->t_disguise);
! 2300: rs_read_char(inf, &t->t_oldch);
! 2301: rs_read_short(inf, &t->t_ctype);
! 2302: rs_read_short(inf, &t->t_index);
! 2303: rs_read_short(inf, &t->t_no_move);
! 2304: rs_read_short(inf, &t->t_quiet);
! 2305: rs_read_short(inf, &t->t_movement);
! 2306: rs_read_short(inf, &t->t_action);
! 2307: rs_read_short(inf, &t->t_artifact);
! 2308: rs_read_short(inf, &t->t_wand);
! 2309: rs_read_short(inf, &t->t_summon);
! 2310: rs_read_short(inf, &t->t_cast);
! 2311: rs_read_short(inf, &t->t_breathe);
! 2312: rs_read_new_string(inf,&t->t_name);
! 2313: rs_read_door_reference(inf,&t->t_doorgoal);
! 2314:
! 2315: rs_read_int(inf,&listid);
! 2316: rs_read_int(inf,&index);
! 2317: t->t_reserved = -1;
! 2318: if (listid == 0)
! 2319: {
! 2320: if (index == 1)
! 2321: t->t_dest = &hero;
! 2322: else
! 2323: t->t_dest = NULL;
! 2324: }
! 2325: else if (listid == 1)
! 2326: {
! 2327: t->t_dest = NULL;
! 2328: t->t_reserved = index;
! 2329: }
! 2330: else if (listid == 2)
! 2331: {
! 2332: struct object *obj;
! 2333: obj = get_list_item(lvl_obj,index);
! 2334: if (obj != NULL)
! 2335: {
! 2336: t->t_dest = &obj->o_pos;
! 2337: }
! 2338: }
! 2339: else
! 2340: t->t_dest = NULL;
! 2341:
! 2342: rs_read_coord(inf,&t->t_pos);
! 2343: rs_read_coord(inf,&t->t_oldpos);
! 2344: rs_read_coord(inf,&t->t_newpos);
! 2345: rs_read_ulongs(inf,t->t_flags,16);
! 2346: rs_read_object_list(inf,&t->t_pack);
! 2347: rs_read_int(inf,&index);
! 2348: t->t_using = get_list_item(t->t_pack, index);
! 2349: rs_read_int(inf, &t->t_selection);
! 2350: rs_read_stats(inf,&t->t_stats);
! 2351: rs_read_stats(inf,&t->maxstats);
! 2352:
! 2353: return(READSTAT);
! 2354: }
! 2355:
! 2356: void
! 2357: rs_fix_thing(struct thing *t)
! 2358: {
! 2359: struct thing *tp;
! 2360:
! 2361: if (t->t_reserved < 0)
! 2362: return;
! 2363:
! 2364: tp = get_list_item(mlist,t->t_reserved);
! 2365:
! 2366: if (tp != NULL)
! 2367: {
! 2368: t->t_dest = &tp->t_pos;
! 2369: }
! 2370: }
! 2371:
! 2372: int
! 2373: rs_write_thing_list(FILE *savef, struct linked_list *l)
! 2374: {
! 2375: int cnt = 0;
! 2376:
! 2377: if (write_error)
! 2378: return(WRITESTAT);
! 2379:
! 2380: rs_write_marker(savef, RSID_MONSTERLIST);
! 2381:
! 2382: cnt = list_size(l);
! 2383:
! 2384: rs_write_int(savef, cnt);
! 2385:
! 2386: if (cnt < 1)
! 2387: return(WRITESTAT);
! 2388:
! 2389: while (l != NULL) {
! 2390: rs_write_thing(savef, (struct thing *)l->l_data);
! 2391: l = l->l_next;
! 2392: }
! 2393:
! 2394: return(WRITESTAT);
! 2395: }
! 2396:
! 2397: int
! 2398: rs_read_thing_list(FILE *inf, struct linked_list **list)
! 2399: {
! 2400: int i, cnt;
! 2401: struct linked_list *l = NULL, *previous = NULL, *head = NULL;
! 2402:
! 2403: if (read_error || format_error)
! 2404: return(READSTAT);
! 2405:
! 2406: rs_read_marker(inf, RSID_MONSTERLIST);
! 2407:
! 2408: rs_read_int(inf, &cnt);
! 2409:
! 2410: for (i = 0; i < cnt; i++)
! 2411: {
! 2412: l = new_item(sizeof(struct thing));
! 2413:
! 2414: l->l_prev = previous;
! 2415:
! 2416: if (previous != NULL)
! 2417: previous->l_next = l;
! 2418:
! 2419: rs_read_thing(inf,THINGPTR(l));
! 2420:
! 2421: if (previous == NULL)
! 2422: head = l;
! 2423:
! 2424: previous = l;
! 2425: }
! 2426:
! 2427: if (l != NULL)
! 2428: l->l_next = NULL;
! 2429:
! 2430: *list = head;
! 2431:
! 2432: return(READSTAT);
! 2433: }
! 2434:
! 2435: void
! 2436: rs_fix_thing_list(struct linked_list *list)
! 2437: {
! 2438: struct linked_list *item;
! 2439:
! 2440: for(item = list; item != NULL; item = item->l_next)
! 2441: rs_fix_thing(THINGPTR(item));
! 2442: }
! 2443:
! 2444: int
! 2445: rs_write_thing_reference(FILE *savef, struct linked_list *list, struct thing *item)
! 2446: {
! 2447: int i;
! 2448:
! 2449: if (write_error)
! 2450: return(WRITESTAT);
! 2451:
! 2452: if (item == NULL)
! 2453: rs_write_int(savef,-1);
! 2454: else
! 2455: {
! 2456: i = find_list_ptr(list, item);
! 2457:
! 2458: rs_write_int(savef, i);
! 2459: }
! 2460:
! 2461: return(WRITESTAT);
! 2462: }
! 2463:
! 2464: int
! 2465: rs_read_thing_reference(FILE *inf, struct linked_list *list, struct thing **item)
! 2466: {
! 2467: int i;
! 2468:
! 2469: if (read_error || format_error)
! 2470: return(READSTAT);
! 2471:
! 2472: rs_read_int(inf, &i);
! 2473:
! 2474: if (i == -1)
! 2475: *item = NULL;
! 2476: else
! 2477: *item = get_list_item(list,i);
! 2478:
! 2479: return(READSTAT);
! 2480: }
! 2481:
! 2482: int
! 2483: rs_write_thing_references(FILE *savef, struct linked_list *list, struct thing *items[], int count)
! 2484: {
! 2485: int i;
! 2486:
! 2487: if (write_error)
! 2488: return(WRITESTAT);
! 2489:
! 2490: for(i = 0; i < count; i++)
! 2491: rs_write_thing_reference(savef,list,items[i]);
! 2492:
! 2493: return(WRITESTAT);
! 2494: }
! 2495:
! 2496: int
! 2497: rs_read_thing_references(FILE *inf, struct linked_list *list, struct thing *items[], int count)
! 2498: {
! 2499: int i;
! 2500:
! 2501: if (read_error || format_error)
! 2502: return(READSTAT);
! 2503:
! 2504: for(i = 0; i < count; i++)
! 2505: rs_read_thing_reference(inf,list,&items[i]);
! 2506:
! 2507: return(WRITESTAT);
! 2508: }
! 2509:
! 2510: int
! 2511: rs_save_file(FILE *savef)
! 2512: {
! 2513: int i;
! 2514:
! 2515: if (write_error)
! 2516: return(WRITESTAT);
! 2517:
! 2518: rs_write_object_list(savef, lvl_obj);
! 2519: rs_write_thing(savef, &player);
! 2520: rs_write_thing_list(savef, mlist);
! 2521: rs_write_thing_list(savef, tlist);
! 2522: rs_write_thing_list(savef, monst_dead);
! 2523:
! 2524: rs_write_traps(savef, traps, MAXTRAPS);
! 2525: rs_write_rooms(savef, rooms, MAXROOMS);
! 2526: rs_write_room_reference(savef,oldrp);
! 2527:
! 2528: rs_write_object_reference(savef, player.t_pack, cur_armor);
! 2529:
! 2530: for (i = 0; i < NUM_FINGERS; i++)
! 2531: rs_write_object_reference(savef, player.t_pack, cur_ring[i]);
! 2532:
! 2533: for (i = 0; i < NUM_MM; i++)
! 2534: rs_write_object_reference(savef, player.t_pack, cur_misc[i]);
! 2535:
! 2536: rs_write_ints(savef, cur_relic, MAXRELIC);
! 2537:
! 2538: rs_write_object_reference(savef, player.t_pack, cur_weapon);
! 2539:
! 2540: rs_write_int(savef,char_type);
! 2541: rs_write_int(savef,foodlev);
! 2542: rs_write_int(savef,ntraps);
! 2543: rs_write_int(savef,trader);
! 2544: rs_write_int(savef,curprice);
! 2545: rs_write_int(savef,seed);
! 2546: rs_write_int(savef,dnum);
! 2547: rs_write_int(savef,max_level);
! 2548: rs_write_int(savef,cur_max);
! 2549: rs_write_int(savef,mpos);
! 2550: rs_write_int(savef,level);
! 2551: rs_write_int(savef,purse);
! 2552: rs_write_int(savef,inpack);
! 2553: rs_write_int(savef,total);
! 2554: rs_write_int(savef,no_food);
! 2555: rs_write_int(savef,foods_this_level);
! 2556: rs_write_int(savef,count);
! 2557: rs_write_int(savef,food_left);
! 2558: rs_write_int(savef,group);
! 2559: rs_write_int(savef,hungry_state);
! 2560: rs_write_int(savef,infest_dam);
! 2561: rs_write_int(savef,lost_str);
! 2562: rs_write_int(savef,lastscore);
! 2563: rs_write_int(savef,hold_count);
! 2564: rs_write_int(savef,trap_tries);
! 2565: rs_write_int(savef,chant_time);
! 2566: rs_write_int(savef,pray_time);
! 2567: rs_write_int(savef,spell_power);
! 2568: rs_write_int(savef,turns);
! 2569: rs_write_int(savef,quest_item);
! 2570: rs_write_int(savef,cols);
! 2571: rs_write_int(savef,lines);
! 2572: rs_write_char(savef,nfloors);
! 2573: rs_write(savef,curpurch,LINELEN);
! 2574: rs_write_char(savef,PLAYER);
! 2575: rs_write_char(savef,take);
! 2576: rs_write(savef,prbuf,LINELEN*2);
! 2577: rs_write(savef,outbuf,BUFSIZ);
! 2578: rs_write_char(savef,runch);
! 2579: rs_write_scrolls(savef);
! 2580: rs_write_potions(savef);
! 2581: rs_write_rings(savef);
! 2582: rs_write_sticks(savef);
! 2583: rs_write_misc(savef);
! 2584: rs_write(savef,whoami,LINELEN);
! 2585: rs_write(savef,huh,LINELEN);
! 2586: rs_write(savef,file_name,LINELEN);
! 2587: rs_write(savef,score_file,LINELEN);
! 2588: rs_write(savef,home,LINELEN);
! 2589: rs_write_window(savef, cw);
! 2590: rs_write_window(savef, hw);
! 2591: rs_write_window(savef, mw);
! 2592: rs_write_window(savef, msgw);
! 2593: rs_write_window(savef, stdscr);
! 2594: rs_write_boolean(savef, pool_teleport);
! 2595: rs_write_boolean(savef, inwhgt);
! 2596: rs_write_boolean(savef, after);
! 2597: rs_write_boolean(savef, waswizard);
! 2598: rs_write_boolean(savef, playing);
! 2599: rs_write_boolean(savef, running);
! 2600: rs_write_boolean(savef, wizard);
! 2601: rs_write_boolean(savef, notify);
! 2602: rs_write_boolean(savef, fight_flush);
! 2603: rs_write_boolean(savef, terse);
! 2604: rs_write_boolean(savef, auto_pickup);
! 2605: rs_write_boolean(savef, menu_overlay);
! 2606: rs_write_boolean(savef, door_stop);
! 2607: rs_write_boolean(savef, jump);
! 2608: rs_write_boolean(savef, slow_invent);
! 2609: rs_write_boolean(savef, firstmove);
! 2610: rs_write_boolean(savef, askme);
! 2611: rs_write_boolean(savef, in_shell);
! 2612: rs_write_boolean(savef, daytime);
! 2613: rs_write_levtype(savef, levtype);
! 2614: rs_write_magic_items(savef, things, MAXTHINGS);
! 2615: rs_write_magic_items(savef, s_magic, MAXSCROLLS);
! 2616: rs_write_magic_items(savef, p_magic, MAXPOTIONS);
! 2617: rs_write_magic_items(savef, r_magic, MAXRINGS);
! 2618: rs_write_magic_items(savef, ws_magic, MAXSTICKS);
! 2619: rs_write_magic_items(savef, m_magic, MAXMM);
! 2620: rs_write_magic_items(savef, rel_magic, MAXRELIC);
! 2621: rs_write_magic_items(savef, foods, MAXFOODS);
! 2622:
! 2623: rs_write_monsters(savef, monsters, NUMMONST+1);
! 2624:
! 2625: rs_write_daemons(savef, d_list, MAXDAEMONS);
! 2626: rs_write_daemons(savef, f_list, MAXFUSES);
! 2627: rs_write_int(savef, demoncnt);
! 2628: rs_write_int(savef, fusecnt);
! 2629:
! 2630: rs_write_int(savef, between);
! 2631:
! 2632: rs_write_int(savef, chance);
! 2633:
! 2634: return(WRITESTAT);
! 2635: }
! 2636:
! 2637: int
! 2638: rs_restore_file(FILE *inf)
! 2639: {
! 2640: int i;
! 2641:
! 2642: if (read_error || format_error)
! 2643: return(READSTAT);
! 2644:
! 2645: rs_read_object_list(inf, &lvl_obj);
! 2646: rs_read_thing(inf, &player);
! 2647: rs_read_thing_list(inf, &mlist);
! 2648: rs_read_thing_list(inf, &tlist);
! 2649: rs_read_thing_list(inf, &monst_dead);
! 2650:
! 2651: rs_fix_thing(&player);
! 2652: rs_fix_thing_list(mlist);
! 2653: rs_fix_thing_list(tlist);
! 2654: rs_fix_thing_list(monst_dead);
! 2655:
! 2656: rs_read_traps(inf, traps, MAXTRAPS);
! 2657: rs_read_rooms(inf, rooms, MAXROOMS);
! 2658: rs_read_room_reference(inf,&oldrp);
! 2659:
! 2660: rs_read_object_reference(inf, player.t_pack, &cur_armor);
! 2661:
! 2662: for(i = 0; i < NUM_FINGERS; i++)
! 2663: rs_read_object_reference(inf, player.t_pack, &cur_ring[i]);
! 2664:
! 2665: for(i = 0; i < NUM_MM; i++)
! 2666: rs_read_object_reference(inf, player.t_pack, &cur_misc[i]);
! 2667:
! 2668: rs_read_ints(inf, cur_relic, MAXRELIC);
! 2669:
! 2670: rs_read_object_reference(inf, player.t_pack, &cur_weapon);
! 2671:
! 2672: rs_read_int(inf,&char_type);
! 2673: rs_read_int(inf,&foodlev);
! 2674: rs_read_int(inf,&ntraps);
! 2675: rs_read_int(inf,&trader);
! 2676: rs_read_int(inf,&curprice);
! 2677: rs_read_int(inf,&seed);
! 2678: rs_read_int(inf,&dnum);
! 2679: rs_read_int(inf,&max_level);
! 2680: rs_read_int(inf,&cur_max);
! 2681: rs_read_int(inf,&mpos);
! 2682: rs_read_int(inf,&level);
! 2683: rs_read_int(inf,&purse);
! 2684: rs_read_int(inf,&inpack);
! 2685: rs_read_int(inf,&total);
! 2686: rs_read_int(inf,&no_food);
! 2687: rs_read_int(inf,&foods_this_level);
! 2688: rs_read_int(inf,&count);
! 2689: rs_read_int(inf,&food_left);
! 2690: rs_read_int(inf,&group);
! 2691: rs_read_int(inf,&hungry_state);
! 2692: rs_read_int(inf,&infest_dam);
! 2693: rs_read_int(inf,&lost_str);
! 2694: rs_read_int(inf,&lastscore);
! 2695: rs_read_int(inf,&hold_count);
! 2696: rs_read_int(inf,&trap_tries);
! 2697: rs_read_int(inf,&chant_time);
! 2698: rs_read_int(inf,&pray_time);
! 2699: rs_read_int(inf,&spell_power);
! 2700: rs_read_int(inf,&turns);
! 2701: rs_read_int(inf,&quest_item);
! 2702: rs_read_int(inf,&cols);
! 2703: rs_read_int(inf,&lines);
! 2704: rs_read_char(inf,&nfloors);
! 2705: rs_read(inf,curpurch,LINELEN);
! 2706: rs_read_char(inf,&PLAYER);
! 2707: rs_read_char(inf,&take);
! 2708: rs_read(inf,prbuf,LINELEN*2);
! 2709: rs_read(inf,outbuf,BUFSIZ);
! 2710: rs_read_char(inf,&runch);
! 2711: rs_read_scrolls(inf);
! 2712: rs_read_potions(inf);
! 2713: rs_read_rings(inf);
! 2714: rs_read_sticks(inf);
! 2715: rs_read_misc(inf);
! 2716: rs_read(inf,whoami,LINELEN);
! 2717: rs_read(inf,huh,LINELEN);
! 2718: rs_read(inf,file_name,LINELEN);
! 2719: rs_read(inf,score_file,LINELEN);
! 2720: rs_read(inf,home,LINELEN);
! 2721: rs_read_window(inf, cw);
! 2722: rs_read_window(inf, hw);
! 2723: rs_read_window(inf, mw);
! 2724: rs_read_window(inf, msgw);
! 2725: rs_read_window(inf, stdscr);
! 2726: rs_read_boolean(inf, &pool_teleport);
! 2727: rs_read_boolean(inf, &inwhgt);
! 2728: rs_read_boolean(inf, &after);
! 2729: rs_read_boolean(inf, &waswizard);
! 2730: rs_read_boolean(inf, &playing);
! 2731: rs_read_boolean(inf, &running);
! 2732: rs_read_boolean(inf, &wizard);
! 2733: rs_read_boolean(inf, ¬ify);
! 2734: rs_read_boolean(inf, &fight_flush);
! 2735: rs_read_boolean(inf, &terse);
! 2736: rs_read_boolean(inf, &auto_pickup);
! 2737: rs_read_boolean(inf, &menu_overlay);
! 2738: rs_read_boolean(inf, &door_stop);
! 2739: rs_read_boolean(inf, &jump);
! 2740: rs_read_boolean(inf, &slow_invent);
! 2741: rs_read_boolean(inf, &firstmove);
! 2742: rs_read_boolean(inf, &askme);
! 2743: rs_read_boolean(inf, &in_shell);
! 2744: rs_read_boolean(inf, &daytime);
! 2745: rs_read_levtype(inf, &levtype);
! 2746: rs_read_magic_items(inf, things, MAXTHINGS);
! 2747: rs_read_magic_items(inf, s_magic, MAXSCROLLS);
! 2748: rs_read_magic_items(inf, p_magic, MAXPOTIONS);
! 2749: rs_read_magic_items(inf, r_magic, MAXRINGS);
! 2750: rs_read_magic_items(inf, ws_magic, MAXSTICKS);
! 2751: rs_read_magic_items(inf, m_magic, MAXMM);
! 2752: rs_read_magic_items(inf, rel_magic, MAXRELIC);
! 2753: rs_read_magic_items(inf, foods, MAXFOODS);
! 2754: rs_read_monsters(inf, monsters, NUMMONST + 1);
! 2755:
! 2756: rs_read_daemons(inf, d_list, MAXDAEMONS);
! 2757: rs_read_daemons(inf, f_list, MAXFUSES);
! 2758: rs_read_int(inf, &demoncnt);
! 2759: rs_read_int(inf, &fusecnt);
! 2760:
! 2761: rs_read_int(inf, &between);
! 2762:
! 2763: rs_read_int(inf, &chance);
! 2764:
! 2765: return(READSTAT);
! 2766: }
CVSweb