Source:NetHack 1.4f/options.c

From NetHackWiki
(Redirected from NetHack 1.4f/options.c)
Jump to navigation Jump to search

Below is the full text to options.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/options.c#line123]], for example.

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

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)options.c	1.4	87/08/08
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* options.c - version 1.0.3 */
4.    
5.    #include "config.h"
6.    #include "hack.h"
7.    extern char *eos();
8.    #ifdef SORTING
9.    static boolean set_order;
10.   #endif
11.   
12.   initoptions()
13.   {
14.   	register char *opts;
15.   	extern char *getenv();
16.   
17.   	flags.time = flags.nonews = flags.notombstone = flags.end_own =
18.   	flags.standout = flags.nonull = FALSE;
19.   	flags.no_rest_on_space = TRUE;
20.   	flags.invlet_constant = TRUE;
21.   	flags.end_top = 5;
22.   	flags.end_around = 4;
23.   	flags.female = FALSE;			/* players are usually male */
24.   #ifdef SORTING
25.   	flags.sortpack = TRUE;
26.   #endif
27.   #ifdef SAFE_ATTACK
28.   	flags.confirm = TRUE;
29.   #endif
30.   #ifdef DGKMOD
31.   	flags.silent = 	flags.pickup = TRUE;
32.   #endif
33.   #ifdef DGK
34.   	flags.IBMBIOS = flags.DECRainbow = flags.rawio = FALSE;
35.   	read_config_file();
36.   #endif
37.   #ifdef HACKOPTIONS
38.   	if(opts = getenv("HACKOPTIONS"))
39.   		parseoptions(opts,TRUE);
40.   #endif
41.   }
42.   
43.   parseoptions(opts, from_env)
44.   register char *opts;
45.   boolean from_env;
46.   {
47.   	register char *op,*op2;
48.   	unsigned num;
49.   	boolean negated;
50.   
51.   	if(op = index(opts, ',')) {
52.   		*op++ = 0;
53.   		parseoptions(op, from_env);
54.   	}
55.   	if(op = index(opts, ' ')) {
56.   		op2 = op;
57.   		while(*op++)
58.   			if(*op != ' ') *op2++ = *op;
59.   	}
60.   	if(!*opts) return;
61.   	negated = FALSE;
62.   	while((*opts == '!') || !strncmp(opts, "no", 2)) {
63.   		if(*opts == '!') opts++; else opts += 2;
64.   		negated = !negated;
65.   	}
66.   	
67.   #ifndef DGK
68.   	if(!strncmp(opts,"standout",4)) {
69.   		flags.standout = !negated;
70.   		return;
71.   	}
72.   
73.   	if(!strncmp(opts,"null",4)) {
74.   		flags.nonull = negated;
75.   		return;
76.   	}
77.   
78.   	if(!strncmp(opts,"tombstone",4)) {
79.   		flags.notombstone = negated;
80.   		return;
81.   	}
82.   
83.   	if(!strncmp(opts,"news",4)) {
84.   		flags.nonews = negated;
85.   		return;
86.   	}
87.   #endif
88.   
89.   #ifdef SAFE_ATTACK
90.   	if (!strncmp(opts, "conf", 4)) {
91.   		flags.confirm = !negated;
92.   		return;
93.   	}
94.   
95.   #endif
96.   #ifdef DGKMOD
97.   	if (!strncmp(opts, "sile", 4)) {
98.   		flags.silent = !negated;
99.   		return;
100.  	}
101.  
102.  	if (!strncmp(opts, "pick", 4)) {
103.  		flags.pickup = !negated;
104.  		return;
105.  	}
106.  #endif
107.  #ifdef DGK
108.  	if (!strncmp(opts, "IBMB", 4)) {
109.  		flags.IBMBIOS = !negated;
110.  		return;
111.  	}
112.  
113.  	if (!strncmp(opts, "rawi", 4)) {
114.  		if (from_env)
115.  			flags.rawio = !negated;
116.  		else
117.  			pline("'rawio' only settable from %s.", configfile);
118.  		return;
119.  	}
120.  
121.  	if (!strncmp(opts, "DECR", 4)) {
122.  		flags.DECRainbow = !negated;
123.  		return;
124.  	}
125.  #endif
126.  
127.  #ifdef SORTING
128.  	if (!strncmp(opts, "sort", 4)) {
129.  		flags.sortpack = !negated;
130.  		return;
131.  	}
132.  
133.  	/*
134.  	 * the order to list the pack
135.  	 */
136.  	if (!strncmp(opts,"packorder",4)) {
137.  		register char	*sp, *tmp;
138.  		extern char	inv_order[];
139.  		int tmpend;
140.  
141.  		op = index(opts,':');
142.  		if(!op) goto bad;
143.  		op++;			/* skip : */
144.  
145.  		/* Missing characters in new order are filled in at the end 
146.  		 * from inv_order.
147.  		 */
148.  		for (sp = op; *sp; sp++)
149.  			if (!index(inv_order, *sp))
150.  				goto bad;		/* bad char in order */
151.  			else if (index(sp + 1, *sp))
152.  				goto bad;		/* dup char in order */
153.  		tmp = (char *) alloc(strlen(inv_order) + 1);
154.  		(void) strcpy(tmp, op);
155.  		for (sp = inv_order, tmpend = strlen(tmp); *sp; sp++)
156.  			if (!index(tmp, *sp)) {
157.  				tmp[tmpend++] = *sp;
158.  				tmp[tmpend] = 0;
159.  			}
160.  		(void) strcpy(inv_order, tmp);
161.  		free(tmp);
162.  		set_order = TRUE;
163.  		return;
164.  	}
165.  #endif
166.  
167.  	if(!strncmp(opts,"time",4)) {
168.  		flags.time = !negated;
169.  		flags.botl = 1;
170.  		return;
171.  	}
172.  
173.  	if(!strncmp(opts,"restonspace",4)) {
174.  		flags.no_rest_on_space = negated;
175.  		return;
176.  	}
177.  
178.  #ifndef DGK
179.  	if(!strncmp(opts,"fixinv",4)) {
180.  		if(from_env)
181.  			flags.invlet_constant = !negated;
182.  		else
183.  			pline("The fixinvlet option must be in HACKOPTIONS.");
184.  		return;
185.  	}
186.  #endif
187.  
188.  	if(!strncmp(opts,"male",4)) {
189.  #ifdef KAA
190.  		if(!from_env && flags.female != negated)
191.  			pline("That is not anatomically possible.");
192.  		else
193.  #endif
194.  			flags.female = negated;
195.  		return;
196.  	}
197.  	if(!strncmp(opts,"female",6)) {
198.  #ifdef KAA
199.  		if(!from_env && flags.female == negated)
200.  			pline("That is not anatomically possible.");
201.  		else
202.  #endif
203.  			flags.female = !negated;
204.  		return;
205.  	}
206.  
207.  	/* name:string */
208.  	if(!strncmp(opts,"name",4)) {
209.  		extern char plname[PL_NSIZ];
210.  		if(!from_env) {
211.  #ifdef DGK
212.  		  pline("'name' only settable from %s.", configfile);
213.  #else
214.  		  pline("The playername can be set only from HACKOPTIONS.");
215.  #endif
216.  		  return;
217.  		}
218.  		op = index(opts,':');
219.  		if(!op) goto bad;
220.  		nmcpy(plname, op+1, sizeof(plname)-1);
221.  		return;
222.  	}
223.  
224.  #ifdef GRAPHICS
225.  	/* graphics:string */
226.  	if(!strncmp(opts,"graphics",4)) {
227.  		char buf[MAXPCHARS];
228.  		if(!from_env) {
229.  #ifdef DGK
230.  		  pline("'graphics' only settable from %s.", configfile);
231.  #else
232.  		  pline("The graphics string can be set only from HACKOPTIONS.");
233.  #endif
234.  		  return;
235.  		}
236.  		op = index(opts,':');
237.  		if(!op)
238.  		    goto bad;
239.  		else
240.  		    opts++;
241.  /*
242.   * You could have problems here if you configure FOUNTAINS, SPIDERS or NEWCLASS
243.   * in or out and forget to change the tail entries in your graphics string.
244.   */
245.  #define SETPCHAR(f, n)	showsyms.f = (strlen(opts) > n) ? opts[n] : defsyms.f
246.  		SETPCHAR(stone, 0);
247.  		SETPCHAR(vwall, 1);
248.  		SETPCHAR(hwall, 2);
249.  		SETPCHAR(tlcorn, 3);
250.  		SETPCHAR(trcorn, 4);
251.  		SETPCHAR(blcorn, 5);
252.  		SETPCHAR(brcorn, 6);
253.  		SETPCHAR(door, 7);
254.  		SETPCHAR(room, 8);
255.  		SETPCHAR(corr, 9);
256.  		SETPCHAR(upstair, 10);
257.  		SETPCHAR(dnstair, 11);
258.  		SETPCHAR(trap, 12);
259.  #ifdef FOUNTAINS
260.  		SETPCHAR(pool, 13);
261.  		SETPCHAR(fountain, 14);
262.  #endif
263.  #ifdef NEWCLASS
264.  		SETPCHAR(throne, 15);
265.  #endif
266.  #ifdef SPIDERS
267.  		SETPCHAR(web, 16);
268.  #endif
269.  #undef SETPCHAR
270.  		return;
271.  	}
272.  #endif /* GRAPHICS */
273.  
274.  	/* endgame:5t[op] 5a[round] o[wn] */
275.  	if(!strncmp(opts,"endgame",3)) {
276.  		op = index(opts,':');
277.  		if(!op) goto bad;
278.  		op++;
279.  		while(*op) {
280.  			num = 1;
281.  			if(digit(*op)) {
282.  				num = atoi(op);
283.  				while(digit(*op)) op++;
284.  			} else
285.  			if(*op == '!') {
286.  				negated = !negated;
287.  				op++;
288.  			}
289.  			switch(*op) {
290.  			case 't':
291.  				flags.end_top = num;
292.  				break;
293.  			case 'a':
294.  				flags.end_around = num;
295.  				break;
296.  			case 'o':
297.  				flags.end_own = !negated;
298.  				break;
299.  			default:
300.  				goto bad;
301.  			}
302.  			while(letter(*++op)) ;
303.  			if(*op == '/') op++;
304.  		}
305.  		return;
306.  	}
307.  #ifdef	DOGNAME
308.  	if(!strncmp(opts, "dogname", 3)) {
309.  		extern char dogname[];
310.  		op = index(opts, ':');
311.  		if (!op) goto bad;
312.  		nmcpy(dogname, ++op, 62);
313.  		return;
314.  	}
315.  #endif	/* DOGNAME */
316.  bad:
317.  	if(!from_env) {
318.  		if(!strncmp(opts, "help", 4)) {
319.  			pline("%s%s%s",
320.  #ifdef DGK
321.  
322.  "To set options use OPTIONS=<options> in ", configfile,
323.  " or give the command \"O\" followed by the line <options> while playing.  ",
324.  "Here <options> is a list of options separated by commas." );
325.  			pline("%s%s",
326.  "Boolean options are confirm, pickup, rawio, silent, sortpack, time, IBMBIOS,",
327.  " and DECRainbow.  These can be negated by prefixing them with '!' or \"no\"." );
328.  			pline("%s%s%s%s",
329.  "The compound options are name, as in OPTIONS=name:Merlin-W,",
330.  #ifdef	DOGNAME
331.  " dogname, which gives the name of your (first) dog (e.g. dogname:Rover)",
332.  #endif	/* DOGNAME */
333.  #ifdef SORTING
334.  " packorder, which lists the order that items should appear in your pack",
335.  #ifdef SPELLS
336.  " (the default is:  packorder:\")[%?+/=!(*0  ), and endgame." );
337.  #else
338.  " (the default is:  packorder:\")[%?/=!(*0  ), and endgame." );
339.  #endif /* SPELLS /**/
340.  #else
341.  #ifdef GRAPHICS
342.  "engame, and graphics.", "", "");
343.  #else
344.  "and engame.", "", "");
345.  #endif
346.  #endif /* SORTING /**/ 	
347.  			pline("%s%s%s",
348.  "Endgame is followed by a description of which parts of the scorelist ",
349.  "you wish to see.  You might for example say: ",
350.  "\"endgame:own scores/5 top scores/4 around my score\"." );
351.  
352.  #else
353.  
354.  "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
355.  "give the command 'O' followed by the line `<options>' while playing. ",
356.  "Here <options> is a list of <option>s separated by commas." );
357.  			pline("%s%s%s",
358.  "Simple (boolean) options are rest_on_space, news, time, ",
359.  "null, tombstone, (fe)male. ",
360.  "These can be negated by prefixing them with '!' or \"no\"." );
361.  			pline("%s%s%s%s",
362.  "The compound options are name, as in OPTIONS=name:Merlin-W,",
363.  #ifdef	DOGNAME
364.  " dogname, which gives the name of your (first) dog (e.g. dogname:Rover)",
365.  #endif	/* DOGNAME */
366.  #ifdef SORTING
367.  " packorder, which lists the order that items should appear in your pack",
368.  #ifdef SPELLS
369.  " (the default is:  packorder:\")[%?+/=!(*0  ), and endgame." );
370.  #else
371.  " (the default is:  packorder:\")[%?/=!(*0  ), and endgame." );
372.  #endif /* SPELLS /**/
373.  #else
374.  "and engame.", "", "");
375.  #endif /* SORTING /**/ 	
376.  			pline("%s%s%s",
377.  "Endgame is followed by a description of what parts of the scorelist",
378.  "you want to see. You might for example say: ",
379.  "`endgame:own scores/5 top scores/4 around my score'." );
380.  
381.  #endif /* DGK /**/
382.  			return;
383.  		}
384.  		pline("Bad option: %s.", opts);
385.  		pline("Type `o help<cr>' for help.");
386.  		return;
387.  	}
388.  #ifdef DGK
389.  	printf("Bad syntax in OPTIONS in %s.", configfile);
390.  #else
391.  	puts("Bad syntax in HACKOPTIONS.");
392.  	puts("Use for example:");
393.  	puts(
394.  "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
395.  	);
396.  #endif
397.  	getret();
398.  }
399.  
400.  doset()
401.  {
402.  	char buf[BUFSZ];
403.  #ifdef SORTING
404.  	extern char inv_order[];
405.  #endif
406.  
407.  	pline("What options do you want to set? ");
408.  	getlin(buf);
409.  	if(!buf[0] || buf[0] == '\033') {
410.  #ifdef DGK
411.  	    (void) strcpy(buf,"OPTIONS=");
412.  #else
413.  	    (void) strcpy(buf,"HACKOPTIONS=");
414.  	    (void) strcat(buf, flags.female ? "female," : "male,");
415.  	    if(flags.standout) (void) strcat(buf,"standout,");
416.  	    if(flags.nonull) (void) strcat(buf,"nonull,");
417.  	    if(flags.nonews) (void) strcat(buf,"nonews,");
418.  	    if(flags.notombstone) (void) strcat(buf,"notombstone,");
419.  	    if(flags.no_rest_on_space)	(void) strcat(buf,"!rest_on_space,");
420.  #endif
421.  #ifdef SORTING
422.  	    if (flags.sortpack) (void) strcat(buf,"sortpack,");
423.  	    if (set_order){
424.  		(void) strcat(buf, "packorder: ");
425.  		(void) strcat(buf, inv_order);
426.  		(void) strcat(buf, ",");
427.  	    }
428.  #endif
429.  #ifdef SAFE_ATTACK
430.  	    if (flags.confirm) (void) strcat(buf,"confirm,");
431.  #endif
432.  #ifdef DGKMOD
433.  	    if (flags.pickup) (void) strcat(buf,"pickup,");
434.  	    if (flags.silent) (void) strcat(buf,"silent,");
435.  #endif
436.  #ifdef DGK
437.  	    if (flags.rawio) (void) strcat(buf,"rawio,");
438.  	    if (flags.IBMBIOS) (void) strcat(buf,"IBMBIOS,");
439.  	    if (flags.DECRainbow) (void) strcat(buf,"DECRainbow,");
440.  #endif
441.  	    if(flags.time) (void) strcat(buf,"time,");
442.  	    if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
443.  		(void) sprintf(eos(buf), "endgame: %u topscores/%u around me",
444.  			flags.end_top, flags.end_around);
445.  		if(flags.end_own) (void) strcat(buf, "/own scores");
446.  	    } else {
447.  		register char *eop = eos(buf);
448.  		if(*--eop == ',') *eop = 0;
449.  	    }
450.  	    pline(buf);
451.  	} else
452.  	    parseoptions(buf, FALSE);
453.  
454.  	return(0);
455.  }
456.  
457.  #ifdef DGKMOD
458.  dotogglepickup() {
459.  	flags.pickup = !flags.pickup;
460.  	pline("Pickup: %s.", flags.pickup ? "ON" : "OFF");
461.  	return (0);
462.  }
463.  #endif
464.  
465.  nmcpy(dest, source, maxlen)
466.  	char	*dest, *source;
467.  	int	maxlen;
468.  {
469.  	char	*cs, *cd;
470.  	int	count;
471.  
472.  	cd = dest;
473.  	cs = source;
474.  	for(count = 1; count < maxlen; count++) {
475.  		if(*cs == ',') break;
476.  		*cd++ = *cs++;
477.  	}
478.  	*cd = 0;
479.  }