Wikia

Wikihack

Source:Hack 1.0/savelev.h

2,032pages on
this wiki
Talk0

Below is the full text to savelev.h from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/savelev.h#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code.

The Usenet post in which this file was originally distributed is not archived at Google Groups. No copy is known to be publicly available. This file is reconstructed from later versions and may not match the original distribution exactly.

Screenshots and source code from Hack are used under the CWI license.
1.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
2.    
3.    #include "hack.h"
4.    #include <stdio.h>
5.    extern struct monst *restmonchn();
6.    extern struct obj *restobjchn();
7.    extern struct obj *billobjs;
8.    extern char *itoa();
9.    
10.   extern char nul[];
11.   #ifndef NOWORM
12.   #include	"def.wseg.h"
13.   
14.   extern struct wseg *wsegs[32], *wheads[32];
15.   extern long wgrowtime[32];
16.   #endif NOWORM
17.   
18.   savelev(fd){
19.   #ifndef NOWORM
20.   	register struct wseg *wtmp, *wtmp2;
21.   	register int tmp;
22.   #endif NOWORM
23.   
24.   	if(fd < 0)
25.              panic("Save on bad file!");
26.   
27.   	bwrite(fd,(char *) levl,sizeof(levl));
28.   	bwrite(fd,(char *) &moves,sizeof(long));
29.   	bwrite(fd,(char *) &xupstair,sizeof(xupstair));
30.   	bwrite(fd,(char *) &yupstair,sizeof(yupstair));
31.   	bwrite(fd,(char *) &xdnstair,sizeof(xdnstair));
32.   	bwrite(fd,(char *) &ydnstair,sizeof(ydnstair));
33.   	savemonchn(fd, fmon);
34.   	savegenchn(fd, fgold);
35.   	savegenchn(fd, ftrap);
36.   	saveobjchn(fd, fobj);
37.   	saveobjchn(fd, billobjs);
38.   /*	if (!ismklev) */
39.   	   billobjs = 0;
40.   	bwrite(fd,(char *) nul, sizeof(unsigned));
41.   #ifndef QUEST
42.   	bwrite(fd,(char *) rooms,sizeof(rooms));
43.   	bwrite(fd,(char *) doors,sizeof(doors));
44.   	save_engravings(fd);
45.   #endif QUEST
46.   /* 	if (!ismklev) */
47.   	   {
48.   	   fgold = ftrap = 0;
49.   	   fmon = 0;
50.   	   fobj = 0;
51.   	   }
52.   /*--------------------------------------------------------------------*/
53.   #ifndef NOWORM
54.   	bwrite(fd,(char *) wsegs,sizeof(wsegs));
55.   	for(tmp=1; tmp<32; tmp++){
56.   		for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2){
57.   			wtmp2 = wtmp->nseg;
58.   			bwrite(fd,(char *) wtmp,sizeof(struct wseg));
59.   		}
60.   /*		if (!ismklev) */
61.   		   wsegs[tmp] = 0;
62.   	}
63.   	bwrite(fd,(char *) wgrowtime,sizeof(wgrowtime));
64.   #endif NOWORM
65.   /*--------------------------------------------------------------------*/
66.   }
67.   
68.   bwrite(fd,loc,num)
69.   register int fd;
70.   register char *loc;
71.   register unsigned num;
72.   {
73.   /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */
74.   	if(write(fd, loc, (int) num) != num)
75.   		panic("cannot write %d bytes to file #%d",num,fd);
76.   }
77.   
78.   saveobjchn(fd,otmp)
79.   register int fd;
80.   register struct obj *otmp;
81.   {
82.   	register struct obj *otmp2;
83.   	unsigned xl;
84.   	int minusone = -1;
85.   
86.   	while(otmp) {
87.   		otmp2 = otmp->nobj;
88.   		xl = otmp->onamelth;
89.   		bwrite(fd, (char *) &xl, sizeof(int));
90.   		bwrite(fd, (char *) otmp, xl + sizeof(struct obj));
91.   /*		if (!ismklev) */
92.   			free((char *) otmp);
93.   		otmp = otmp2;
94.   	}
95.   	bwrite(fd, (char *) &minusone, sizeof(int));
96.   }
97.   
98.   savemonchn(fd,mtmp)
99.   register int fd;
100.  register struct monst *mtmp;
101.  {
102.  	register struct monst *mtmp2;
103.  	unsigned xl;
104.  	int minusone = -1;
105.  	int monnum;
106.  #ifdef FUNNYRELOC
107.  	struct permonst *monbegin = &mons[0];
108.  
109.  	bwrite(fd, (char *) &monbegin, sizeof(monbegin));
110.  #endif
111.  
112.  	while(mtmp) {
113.  		mtmp2 = mtmp->nmon;
114.  		xl = mtmp->mxlth + mtmp->mnamelth;
115.  		bwrite(fd, (char *) &xl, sizeof(int));
116.  
117.  		/* JAT - just save the offset into the monster table, */
118.  		/* it will be relocated when read in */
119.  		monnum = mtmp->data - &mons[0];
120.  		mtmp->data = (struct permonst *)monnum;
121.  #ifdef DEBUGMON
122.  		myprintf("Wrote monster #%d", monnum);
123.  #endif
124.  		bwrite(fd, (char *) mtmp, xl + sizeof(struct monst));
125.  		if(mtmp->minvent) saveobjchn(fd,mtmp->minvent);
126.  /*		if (!ismklev) */
127.  		   free((char *) mtmp);
128.  		mtmp = mtmp2;
129.  	}
130.  	bwrite(fd, (char *) &minusone, sizeof(int));
131.  }
132.  
133.  savegenchn(fd,gtmp)
134.  register int fd;
135.  register struct gen *gtmp;
136.  {
137.  	register struct gen *gtmp2;
138.  	while(gtmp) {
139.  		gtmp2 = gtmp->ngen;
140.  		bwrite(fd, (char *) gtmp, sizeof(struct gen));
141.  /*		if (!ismklev) */
142.  		   free((char *) gtmp);
143.  		gtmp = gtmp2;
144.  	}
145.  	bwrite(fd, nul, sizeof(struct gen));
146.  }
147.  
148.  

Around Wikia's network

Random Wiki