forked from RoguelikeRestorationProject/urogue1.03
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate.c
1531 lines (1227 loc) · 37.2 KB
/
state.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
state.c - Portable Rogue Save State Code
Copyright (C) 1993, 1995 Nicholas J. Kisseberth
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name(s) of the author(s) nor the names of other contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
Notes
Should move all game variables into one place
Should move save/restore code into save.c or some such
*/
#include <assert.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define NCURSES_INTERNALS
#include "rogue.h"
/*
Variables for global game state.
All variables that need to get saved when saving a game
are defined in this file. Long term goal is to move many
of these variables into a "struct level" data type of some
kind... perhaps not, maybe struct game...
Other global variables that don't need to get saved are
kept in main.c.
Other global variables that don't change during the course
of a game are kept in urogue.c, monsdata.c, data.c.
*/
#define _X_ { 0, 0, 0, 0, 0 }
struct delayed_action
d_list[MAXDAEMONS] = /* daemon/fuse list */
{
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
_X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_,
};
#undef _X_
/* object data */
struct trap traps[2 * MAXTRAPS]; /* 2x for special effects */
struct room rooms[MAXROOMS]; /* One for each room -- A level */
struct room *oldrp = NULL; /* Roomin(&player.t_oldpos) */
struct thing player; /* The rogue */
struct linked_list *lvl_obj = NULL; /* Treasure on this level */
struct linked_list *fam_ptr = NULL; /* A ptr to the familiar */
struct linked_list *mlist = NULL; /* Monsters on this level */
struct thing *beast; /* The last beast that attacked */
struct object *cur_armor = NULL; /* what rogue wears */
struct object *cur_weapon = NULL; /* ... and wields */
struct object *cur_ring[10]; /* His rings */
struct linked_list *curr_mons = NULL; /* The mons. currently moving */
struct linked_list *next_mons = NULL; /* The mons. after curr_mons */
/* Misc. game state info */
char dummybuf1[50000];
char dummybuf2[50000];
char msgbuf[10][2*LINELEN]; /* message buffer history */
int msg_index = 0; /* index in msg history buffer for nxt msg */
int foodlev = 1; /* how fast he eats food */
int ntraps = 0; /* Number of traps on this level */
int dnum = 0; /* Dungeon number */
int max_level = 0; /* Deepest player has gone */
int lost_dext = 0; /* amount of lost dexterity */
int no_command = 0;
int level = 0;
int see_dist = 3;
int no_food = 0;
int count = 0;
int food_left = HUNGERTIME;
int group = 1;
int hungry_state = F_OK;
int infest_dam = 0;
int lost_str = 0;
int hold_count = 0;
int trap_tries = 0;
int has_artifact = 0;
int picked_artifact = 0;
int luck = 0;
int resurrect = 0;
int fam_type = 0; /* The type of familiar */
int mons_summoned = 0; /* Number of summoned monsters */
char PLAYER = VPLAYER; /* what the player looks like */
char take = 0; /* Thing the rogue is taking */
char runch = 0; /* Direction player is running */
int char_type = C_NOTSET; /* what type of character is player */
int inv_type = INV_CLEAR; /* Overwrite style of inventory */
int pool_teleport = FALSE; /* just teleported from a pool */
int inwhgt = FALSE; /* true if from wghtchk() */
int after = 0; /* True if we want after daemons */
int waswizard = 0; /* Was a wizard sometime */
int canwizard = 1; /* Will be permitted to do this */
int playing = TRUE;
int running = FALSE;
int fighting = FALSE;
int wizard = FALSE;
int wiz_verbose = TRUE;
int moving = FALSE;
coord delta; /* Change indicated to get_dir() */
LEVTYPE levtype; /* type of level i'm on */
long purse = 0;
unsigned long total = 0;
WINDOW *cw; /* Window that the player sees */
WINDOW *hw; /* Used for the help command */
WINDOW *mw; /* Used to store mosnters */
/* options.o */
/* game options */
int terse = FALSE;
int door_stop = FALSE;
int jump = TRUE;
int doorstop = TRUE;
int firstmove = FALSE;
int askme = TRUE;
int autosave = TRUE;
char whoami[2 * LINELEN]; /* Name of player */
char fruit[2 * LINELEN]; /* Favorite fruit */
char file_name[2 * LINELEN]; /* Save file name */
char score_file[2 * LINELEN]; /* Score file name */
/****************************************************************************/
/* Portable Save State Code */
/* */
/* UltraRogue v1.04 */
/****************************************************************************/
#define URS_STATS 0xABCD0001
#define URS_THING 0xABCD0002
#define URS_OBJECT 0xABCD0003
#define URS_MAGIC 0xABCD0004
#define URS_KNOWS 0xABCD0005
#define URS_GUESSES 0xABCD0006
#define URS_STACKOBJECT 0xABCD0007
#define URS_BAGOBJECT 0xABCD0008
#define URS_MONSTERLIST 0xABCD0009
#define URS_MONSTERSTATS 0xABCD000A
#define URS_MONSTER 0xABCD000B
#define URS_TRAP 0xABCD000C
#define URS_WINDOW 0xABCD000D
#define URS_DAEMONS 0xABCD000E
void
ur_write(FILE *savef, void *ptr, size_t size)
{
if (size == 0)
return;
fwrite(ptr,size,1,savef);
}
void
ur_read(FILE *savef, void *ptr, size_t size)
{
if (size == 0)
return;
fread(ptr,size,1,savef);
}
void
ur_write_int(FILE *savef, int c)
{
ur_write(savef,&c,sizeof(int));
}
int
ur_read_int(FILE *savef)
{
int i;
ur_read(savef, &i, sizeof(int));
return(i);
}
void
ur_write_short(FILE *savef, short c)
{
ur_write(savef,&c,sizeof(short));
}
short
ur_read_short(FILE *savef)
{
short s;
ur_read(savef, &s, sizeof(short));
return(s);
}
void
ur_write_long(FILE *savef, long c)
{
ur_write(savef,&c,sizeof(long));
}
long
ur_read_long(FILE *savef)
{
long l;
ur_read(savef, &l, sizeof(long));
return(l);
}
void
ur_write_ulong(FILE *savef, unsigned long c)
{
ur_write(savef,&c,sizeof(unsigned long));
}
unsigned long
ur_read_ulong(FILE *savef)
{
long l;
ur_read(savef, &l, sizeof(unsigned long));
return(l);
}
void
ur_unread_long(FILE *savef)
{
fseek(savef, -(long)sizeof(long), SEEK_CUR);
}
void
ur_write_char(FILE *savef, char c)
{
ur_write(savef,&c,sizeof(char));
}
char
ur_read_char(FILE *savef)
{
char c;
ur_read(savef, &c, sizeof(char));
return(c);
}
void
ur_write_string(FILE *savef, char *s)
{
size_t len;
len = (s == NULL) ? 0L : strlen(s) + 1 ;
ur_write_long(savef, (long) len);
ur_write(savef,s,len);
}
char *
ur_read_string(FILE *savef)
{
size_t len;
char *buf;
len = ur_read_long(savef);
if (len == 0)
return(NULL);
buf = ur_alloc(len);
if (buf == NULL) /* Should flag a global error condition... */
return(NULL);
ur_read(savef,buf,len);
return(buf);
}
void
ur_write_coord(FILE *savef, coord c)
{
ur_write_int(savef, c.x);
ur_write_int(savef, c.y);
}
coord
ur_read_coord(FILE *savef)
{
coord c;
c.x = ur_read_int(savef);
c.y = ur_read_int(savef);
return(c);
}
void
ur_write_room(FILE *savef, struct room *r)
{
int i;
ur_write_coord(savef, r->r_pos);
ur_write_coord(savef, r->r_max);
for(i=0; i<MAXDOORS; i++)
ur_write_coord(savef, r->r_exit[i]);
ur_write_int(savef, r->r_flags);
ur_write_int(savef, r->r_nexits);
ur_write_short(savef, r->r_fires);
}
struct room *
ur_read_room(FILE *savef)
{
struct room *r;
int i;
r = ur_alloc( sizeof(struct room) );
r->r_pos = ur_read_coord(savef);
r->r_max = ur_read_coord(savef);
for(i=0; i<MAXDOORS; i++)
r->r_exit[i] = ur_read_coord(savef);
r->r_flags = ur_read_int(savef);
r->r_nexits = ur_read_int(savef);
r->r_fires = ur_read_short(savef);
return(r);
}
void
ur_write_object(FILE *savef, struct object *o)
{
int other;
ur_write_long(savef, URS_OBJECT);
ur_write_coord(savef, o->o_pos);
ur_write_string(savef, o->o_text);
ur_write_string(savef, o->o_damage);
ur_write_string(savef, o->o_hurldmg);
ur_write_long(savef, o->o_flags);
ur_write_long(savef, o->ar_flags);
ur_write_char(savef, o->o_type);
ur_write_int(savef, o->o_ident);
ur_write_int(savef, o->o_count);
ur_write_int(savef, o->o_which);
ur_write_int(savef, o->o_hplus);
ur_write_int(savef, o->o_dplus);
ur_write_int(savef, o->o_ac);
ur_write_int(savef, o->o_group);
ur_write_int(savef, o->o_weight);
ur_write_char(savef, o->o_launch);
ur_write(savef, &o->o_mark[0], MARKLEN);
other = 0;
if (o->o_bag)
other = 1;
if (o->next_obj && (o->next_obj->l_prev == NULL) )
other |= 2;
ur_write_int(savef,other);
if (other & 1)
ur_write_bag(savef,o->o_bag);
if (other & 2)
ur_write_object_stack(savef, o->next_obj);
}
struct object *
ur_read_object(FILE *savef)
{
struct object *o;
long id;
int other;
o = ur_alloc(sizeof(struct object));
if (o == NULL)
return(NULL);
memset(o,0,sizeof(struct object));
id = ur_read_long(savef);
assert(id == URS_OBJECT);
o->o_pos = ur_read_coord(savef);
o->o_text = ur_read_string(savef);
o->o_damage = ur_read_string(savef);
o->o_hurldmg = ur_read_string(savef);
o->o_flags = ur_read_long(savef);
o->ar_flags = ur_read_long(savef);
o->o_type = ur_read_char(savef);
o->o_ident = ur_read_int(savef);
o->o_count = ur_read_int(savef);
o->o_which = ur_read_int(savef);
o->o_hplus = ur_read_int(savef);
o->o_dplus = ur_read_int(savef);
o->o_ac = ur_read_int(savef);
o->o_group = ur_read_int(savef);
o->o_weight = ur_read_int(savef);
o->o_launch = ur_read_char(savef);
ur_read(savef, &o->o_mark[0], MARKLEN);
other = ur_read_int(savef);
if (other & 1)
o->o_bag = ur_read_bag(savef);
if (other & 2)
o->next_obj = ur_read_object_stack(savef);
if (o->o_ident > 0)
add_to_ident_list(o);
return(o);
}
int
list_size(struct linked_list *l)
{
int cnt=0;
if (l == NULL)
return(0);
while(l != NULL)
{
cnt++;
l = l->l_next;
}
return(cnt);
}
int
find_thing_index(struct linked_list *l, struct thing *item)
{
int cnt=0;
if (l == NULL)
return(-1);
while(l != NULL)
{
if (item == l->data.th)
return(cnt+1);
cnt++;
l = l->l_next;
}
return(0);
}
int
find_list_index(struct linked_list *l, struct object *item)
{
int cnt=0;
if (l == NULL)
return(-1);
while(l != NULL)
{
if (item == l->data.obj)
return(cnt+1);
cnt++;
l = l->l_next;
}
return(0);
}
struct object *
find_object(struct linked_list *list, int num)
{
int cnt = 0;
struct linked_list *l = list;
if ( (num < 1) || (list == NULL) )
return(NULL);
num--;
for(cnt = 0; cnt < num; cnt++)
{
if ( l == NULL )
return(NULL);
l = l->l_next;
}
return(l->data.obj);
}
struct thing *
find_thing(struct linked_list *list, int num)
{
int cnt = 0;
struct linked_list *l = list;
if ( (num < 1) || (list == NULL) )
return(NULL);
num--;
for(cnt = 0; cnt < num; cnt++)
{
if (l == NULL)
return(NULL);
l = l->l_next;
}
return(l->data.th);
}
void
ur_write_object_stack(FILE *savef, struct linked_list *l)
{
int cnt;
ur_write_long(savef, URS_STACKOBJECT);
ur_write_int(savef, cnt = list_size(l) );
if (cnt == 0)
return;
while(l != NULL)
{
ur_write_object(savef, l->data.obj);
l = l->l_next;
}
}
void
ur_write_bag(FILE *savef, struct linked_list *l)
{
int cnt;
ur_write_long(savef, URS_BAGOBJECT);
ur_write_int(savef, cnt = list_size(l) );
if (cnt == 0)
return;
while(l != NULL)
{
ur_write_object(savef, l->data.obj);
l = l->l_next;
}
}
struct linked_list *
ur_read_object_stack(FILE *savef)
{
long id;
int i,cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL;
id = ur_read_long(savef);
assert(id == URS_STACKOBJECT);
cnt = ur_read_int(savef);
for(i = 0; i < cnt; i++)
{
l = new_list();
l->l_prev = previous;
if (previous != NULL)
previous->l_next = l;
l->data.obj = ur_read_object(savef);
if (previous == NULL)
head = l;
previous = l;
}
if (l != NULL)
l->l_next = NULL;
return(head);
}
struct linked_list *
ur_read_bag(FILE *savef)
{
long id;
int i,cnt;
struct linked_list *l = NULL, *previous = NULL, *head = NULL;
id = ur_read_long(savef);
assert( id == URS_BAGOBJECT );
cnt = ur_read_int(savef);
for(i = 0; i < cnt; i++)
{
l = new_list();
l->l_prev = previous;
if (previous != NULL)
previous->l_next = l;
l->data.obj = ur_read_object(savef);
if (previous == NULL)
head = l;
previous = l;
}
if (l != NULL)
l->l_next = NULL;
return(head);
}
void
ur_fixup_monsters(struct linked_list *l)
{
while(l != NULL)
{
if (l->data.th->chasee_index == -1L)
l->data.th->t_chasee = &player;
else
l->data.th->t_chasee = find_thing(mlist, l->data.th->chasee_index);
l->data.th->t_horde = find_object(lvl_obj, l->data.th->horde_index);
l = l->l_next;
}
}
void
ur_write_monsters(FILE *savef, struct linked_list *l)
{
int cnt;
ur_write_long(savef, URS_MONSTERLIST);
cnt = list_size(l);
ur_write_int(savef, cnt);
if (cnt < 1)
return;
while(l != NULL)
{
ur_write_thing(savef, l->data.th);
l = l->l_next;
}
}
struct linked_list *
ur_read_monsters(FILE *savef)
{
long id;
int i,cnt;
struct linked_list *l=NULL, *previous = NULL, *head = NULL;
id = ur_read_long(savef);
assert(id == URS_MONSTERLIST);
cnt = ur_read_int(savef);
if (cnt == 0)
return(NULL);
for(i = 0; i < cnt; i++)
{
l = new_list();
l->l_prev = previous;
if (previous != NULL)
previous->l_next = l;
l->data.th = ur_read_thing(savef);
if (previous == NULL)
head = l;
previous = l;
}
if (l != NULL)
l->l_next = NULL;
return(head);
}
void
ur_write_monster_stats(FILE *savef, struct mstats *m)
{
ur_write_long(savef, URS_MONSTERSTATS);
ur_write_short(savef, m->s_str);
ur_write_long(savef, m->s_exp);
ur_write_int(savef, m->s_lvl);
ur_write_int(savef, m->s_arm);
ur_write_string(savef, m->s_hpt);
ur_write_string(savef, m->s_dmg);
}
struct mstats *
ur_read_monster_stats(FILE *savef)
{
long id;
struct mstats *m;
id = ur_read_long(savef);
assert(id == URS_MONSTERSTATS);
m = ur_alloc( sizeof(struct mstats) );
m->s_str = ur_read_short(savef);
m->s_exp = ur_read_long(savef);
m->s_lvl = ur_read_int(savef);
m->s_arm = ur_read_int(savef);
m->s_hpt = ur_read_string(savef);
m->s_dmg = ur_read_string(savef);
return(m);
}
void
ur_write_monster(FILE *savef, struct monster *m)
{
int i;
ur_write_long(savef, URS_MONSTER);
ur_write_string(savef, m->m_name);
ur_write_short(savef, m->m_carry);
ur_write_int(savef, m->m_normal);
ur_write_int(savef, m->m_wander);
ur_write_char(savef, m->m_appear);
ur_write_string(savef, m->m_intel);
for(i = 0; i < 10; i++)
ur_write_long(savef, m->m_flags[i]);
ur_write_string(savef, m->m_typesum);
ur_write_short(savef, m->m_numsum);
ur_write_short(savef, m->m_add_exp);
ur_write_monster_stats(savef, &m->m_stats);
}
struct monster *
ur_read_monster(FILE *savef)
{
struct monster *m;
struct mstats *mstats;
m = ur_alloc( sizeof(struct monster) );
m->m_name = ur_read_string(savef);
m->m_carry = ur_read_short(savef);
m->m_normal = ur_read_int(savef);
m->m_wander = ur_read_int(savef);
m->m_appear = ur_read_char(savef);
m->m_intel = ur_read_string(savef);
ur_read(savef, &m->m_flags[0], 10*sizeof(long));
m->m_typesum = ur_read_string(savef);
m->m_numsum = ur_read_short(savef);
m->m_add_exp = ur_read_short(savef);
mstats = ur_read_monster_stats(savef);
m->m_stats = *mstats;
ur_free(mstats);
return(m);
}
void
ur_write_trap(FILE *savef, struct trap *t)
{
ur_write_long(savef, URS_TRAP);
ur_write_coord(savef, t->tr_pos);
ur_write_long(savef, t->tr_flags);
ur_write_char(savef, t->tr_type);
ur_write_char(savef, t->tr_show);
}
struct trap *
ur_read_trap(FILE *savef)
{
struct trap *t;
long id;
id = ur_read_long(savef);
assert(id == URS_TRAP);
t = ur_alloc( sizeof(struct trap));
t->tr_pos = ur_read_coord(savef);
t->tr_flags = ur_read_long(savef);
t->tr_type = ur_read_char(savef);
t->tr_show = ur_read_char(savef);
return(t);
}
void
ur_write_stats(FILE *savef, struct stats *s)
{
ur_write_long(savef, URS_STATS);
ur_write_string(savef, s->s_dmg);
ur_write_long(savef, s->s_exp);
ur_write_int(savef, s->s_hpt);
ur_write_int(savef, s->s_pack);
ur_write_int(savef, s->s_carry);
ur_write_int(savef, s->s_lvl);
ur_write_int(savef, s->s_arm);
ur_write_int(savef, s->s_acmod);
ur_write_int(savef, s->s_power);
ur_write_int(savef, s->s_str);
ur_write_int(savef, s->s_intel);
ur_write_int(savef, s->s_wisdom);
ur_write_int(savef, s->s_dext);
ur_write_int(savef, s->s_const);
ur_write_int(savef, s->s_charisma);
}
struct stats *
ur_read_stats(FILE *savef)
{
struct stats *s;
long id;
id = ur_read_long(savef);
assert(id == URS_STATS);
s = ur_alloc(sizeof(struct stats));
s->s_dmg = ur_read_string(savef);
s->s_exp = ur_read_long(savef);
s->s_hpt = ur_read_int(savef);
s->s_pack = ur_read_int(savef);
s->s_carry = ur_read_int(savef);
s->s_lvl = ur_read_int(savef);
s->s_arm = ur_read_int(savef);
s->s_acmod = ur_read_int(savef);
s->s_power = ur_read_int(savef);
s->s_str = ur_read_int(savef);
s->s_intel = ur_read_int(savef);
s->s_wisdom = ur_read_int(savef);
s->s_dext = ur_read_int(savef);
s->s_const = ur_read_int(savef);
s->s_charisma = ur_read_int(savef);
return(s);
}
void
ur_write_thing(FILE *savef, struct thing *t)
{
int i;
ur_write_long(savef, URS_THING);
ur_write_bag(savef, t->t_pack);
ur_write_stats(savef, &t->t_stats);
ur_write_stats(savef, &t->maxstats);
ur_write_int(savef, t->t_ischasing);
if (t->t_chasee == &player)
ur_write_long(savef, -1L);
else if (t->t_chasee == NULL)
ur_write_long(savef, 0L);
else
{
long m;
m = find_thing_index(mlist, t->t_chasee);
ur_write_long(savef,m);
}
ur_write_long(savef, find_list_index(lvl_obj, t->t_horde));
ur_write_coord(savef, t->t_pos);
ur_write_coord(savef, t->t_oldpos);
ur_write_coord(savef, t->t_nxtpos);
for(i = 0; i < 16; i++)
ur_write_int(savef, t->t_flags[i]);
ur_write_int(savef, t->t_praycnt);
ur_write_int(savef, t->t_turn);
ur_write_int(savef, t->t_wasshot);
ur_write_int(savef, t->t_ctype);
ur_write_int(savef, t->t_index);
ur_write_int(savef, t->t_no_move);
ur_write_int(savef, t->t_rest_hpt);
ur_write_int(savef, t->t_rest_pow);
ur_write_int(savef, t->t_doorgoal);
ur_write_char(savef, t->t_type);
ur_write_char(savef, t->t_disguise);
ur_write_char(savef, t->t_oldch);
}
struct thing *
ur_read_thing(FILE *savef)
{
long id;
int i;
struct thing *t;
struct stats *s;
id = ur_read_long(savef);
assert(id == URS_THING);
t = ur_alloc( sizeof(struct thing) );
t->t_pack = ur_read_bag(savef);
s = ur_read_stats(savef);
t->t_stats = *s;
ur_free(s);
s = ur_read_stats(savef);
t->maxstats = *s;
ur_free(s);
t->t_ischasing = ur_read_int(savef);
t->chasee_index = ur_read_long(savef);
t->horde_index = ur_read_long(savef);
t->t_pos = ur_read_coord(savef);
t->t_oldpos = ur_read_coord(savef);
t->t_nxtpos = ur_read_coord(savef);
for(i = 0; i < 16; i++)
t->t_flags[i] = ur_read_int(savef);
t->t_praycnt = ur_read_int(savef);
t->t_turn = ur_read_int(savef);
t->t_wasshot = ur_read_int(savef);
t->t_ctype = ur_read_int(savef);
t->t_index = ur_read_int(savef);
t->t_no_move = ur_read_int(savef);
t->t_rest_hpt = ur_read_int(savef);
t->t_rest_pow = ur_read_int(savef);