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