rogue

Ken Arnold's Rogue
git clone https://git.woozle.org/neale/rogue.git

Neale Pickett  ·  2011-10-13

rinit.c

  1/*
  2 * global variable initializaton
  3 *
  4 * @(#)rinit.c	4.31 (Berkeley) 02/05/99
  5 */
  6
  7#include <curses.h>
  8#include <ctype.h>
  9#include "netprot.h"
 10
 11/*
 12 * init_player:
 13 *	Roll her up
 14 */
 15void
 16init_player(void)
 17{
 18    THING *obj;
 19
 20    Pstats = Max_stats;
 21    Food_left = HUNGERTIME;
 22    /*
 23     * Give him some food
 24     */
 25    obj = new_item();
 26    obj->o_type = FOOD;
 27    obj->o_count = 1;
 28    add_pack(obj, TRUE);
 29    /*
 30     * And his suit of armor
 31     */
 32    obj = new_item();
 33    obj->o_type = ARMOR;
 34    obj->o_which = RING_MAIL;
 35    obj->o_arm = A_class[RING_MAIL] - 1;
 36    obj->o_flags |= ISKNOW;
 37    obj->o_count = 1;
 38    Cur_armor = obj;
 39    add_pack(obj, TRUE);
 40    /*
 41     * Give him his weaponry.  First a mace.
 42     */
 43    obj = new_item();
 44    init_weapon(obj, MACE);
 45    obj->o_hplus = 1;
 46    obj->o_dplus = 1;
 47    obj->o_flags |= ISKNOW;
 48    add_pack(obj, TRUE);
 49    Cur_weapon = obj;
 50    /*
 51     * Now a +1 bow
 52     */
 53    obj = new_item();
 54    init_weapon(obj, BOW);
 55    obj->o_hplus = 1;
 56    obj->o_flags |= ISKNOW;
 57    add_pack(obj, TRUE);
 58    /*
 59     * Now some arrows
 60     */
 61    obj = new_item();
 62    init_weapon(obj, ARROW);
 63    obj->o_count = rnd(15) + 25;
 64    obj->o_flags |= ISKNOW;
 65    add_pack(obj, TRUE);
 66}
 67
 68/*
 69 * Contains defintions and functions for dealing with things like
 70 * potions and scrolls
 71 */
 72
 73static char *Rainbow[] = {
 74    "amber",
 75    "aquamarine",
 76    "black",
 77    "blue",
 78    "brown",
 79    "clear",
 80    "crimson",
 81    "cyan",
 82    "ecru",
 83    "gold",
 84    "green",
 85    "grey",
 86    "magenta",
 87    "orange",
 88    "pink",
 89    "plaid",
 90    "purple",
 91    "red",
 92    "silver",
 93    "tan",
 94    "tangerine",
 95    "topaz",
 96    "turquoise",
 97    "vermilion",
 98    "violet",
 99    "white",
100    "yellow",
101};
102
103#define NCOLORS (sizeof Rainbow / sizeof (char *))
104
105static char *Sylls[] = {
106    "a", "ab", "ag", "aks", "ala", "an", "app", "arg", "arze", "ash",
107    "bek", "bie", "bit", "bjor", "blu", "bot", "bu", "byt", "comp",
108    "con", "cos", "cre", "dalf", "dan", "den", "do", "e", "eep", "el",
109    "eng", "er", "ere", "erk", "esh", "evs", "fa", "fid", "fri", "fu",
110    "gan", "gar", "glen", "gop", "gre", "ha", "hyd", "i", "ing", "ip",
111    "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech",
112    "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur", "nej",
113    "nelg", "nep", "ner", "nes", "nes", "nih", "nin", "o", "od", "ood",
114    "org", "orn", "ox", "oxy", "pay", "ple", "plu", "po", "pot",
115    "prok", "re", "rea", "rhov", "ri", "ro", "rog", "rok", "rol", "sa",
116    "san", "sat", "sef", "seh", "shu", "ski", "sna", "sne", "snik",
117    "sno", "so", "sol", "sri", "sta", "sun", "ta", "tab", "tem",
118    "ther", "ti", "tox", "trol", "tue", "turs", "u", "ulk", "um", "un",
119    "uni", "ur", "val", "viv", "vly", "vom", "wah", "wed", "werg",
120    "wex", "whon", "wun", "xo", "y", "yot", "yu", "zant", "zeb", "zim",
121    "zok", "zon", "zum",
122};
123
124typedef struct {
125    char	*st_name;
126    int		st_value;
127} STONE;
128
129static STONE Stones[] = {
130    { "agate",		 25},
131    { "alexandrite",	 40},
132    { "amethyst",	 50},
133    { "carnelian",	 40},
134    { "diamond",	300},
135    { "emerald",	300},
136    { "germanium",	225},
137    { "granite",	  5},
138    { "garnet",		 50},
139    { "jade",		150},
140    { "kryptonite",	300},
141    { "lapis lazuli",	 50},
142    { "moonstone",	 50},
143    { "obsidian",	 15},
144    { "onyx",		 60},
145    { "opal",		200},
146    { "pearl",		220},
147    { "peridot",	 63},
148    { "ruby",		350},
149    { "sapphire",	285},
150    { "stibotantalite",	200},
151    { "tiger eye",	 50},
152    { "topaz",		 60},
153    { "turquoise",	 70},
154    { "taaffeite",	300},
155    { "zircon",	 	 80},
156};
157
158#define NSTONES (sizeof Stones / sizeof (STONE))
159
160static char *Wood[] = {
161    "avocado wood",
162    "balsa",
163    "bamboo",
164    "banyan",
165    "birch",
166    "cedar",
167    "cherry",
168    "cinnibar",
169    "cypress",
170    "dogwood",
171    "driftwood",
172    "ebony",
173    "elm",
174    "eucalyptus",
175    "fall",
176    "hemlock",
177    "holly",
178    "ironwood",
179    "kukui wood",
180    "mahogany",
181    "manzanita",
182    "maple",
183    "oaken",
184    "persimmon wood",
185    "pecan",
186    "pine",
187    "poplar",
188    "redwood",
189    "rosewood",
190    "spruce",
191    "teak",
192    "walnut",
193    "zebrawood",
194};
195
196#define NWOOD (sizeof Wood / sizeof (char *))
197
198static char *Metal[] = {
199    "aluminum",
200    "beryllium",
201    "bone",
202    "brass",
203    "bronze",
204    "copper",
205    "electrum",
206    "gold",
207    "iron",
208    "lead",
209    "magnesium",
210    "mercury",
211    "nickel",
212    "pewter",
213    "platinum",
214    "steel",
215    "silver",
216    "silicon",
217    "tin",
218    "titanium",
219    "tungsten",
220    "zinc",
221};
222
223#define NMETAL (sizeof Metal / sizeof (char *))
224
225#define MAX3(a,b,c)	(a > b ? (a > c ? a : c) : (b > c ? b : c))
226
227static bool Used[MAX3(NCOLORS, NSTONES, NWOOD)];
228
229/*
230 * init_colors:
231 *	Initialize the potion color scheme for this time
232 */
233void
234init_colors(void)
235{
236    int i, j;
237
238    for (i = 0; i < NCOLORS; i++)
239	Used[i] = FALSE;
240    for (i = 0; i < MAXPOTIONS; i++)
241    {
242	do
243	    j = rnd(NCOLORS);
244	until (!Used[j]);
245	Used[j] = TRUE;
246	P_colors[i] = Rainbow[j];
247    }
248}
249
250/*
251 * init_names:
252 *	Generate the names of the various scrolls
253 */
254#define MAXNAME	40	/* Max number of characters in a name */
255
256void
257init_names(void)
258{
259    int nsyl;
260    char *cp, *sp;
261    int i, nwords;
262
263    for (i = 0; i < MAXSCROLLS; i++)
264    {
265	cp = Prbuf;
266	nwords = rnd(3) + 2;
267	while (nwords--)
268	{
269	    nsyl = rnd(3) + 1;
270	    while (nsyl--)
271	    {
272		sp = Sylls[rnd((sizeof Sylls) / (sizeof (char *)))];
273		if (&cp[strlen(sp)] > &Prbuf[MAXNAME])
274			break;
275		while (*sp)
276		    *cp++ = *sp++;
277	    }
278	    *cp++ = ' ';
279	}
280	*--cp = '\0';
281	S_names[i] = (char *) malloc((unsigned) strlen(Prbuf)+1);
282	strcpy(S_names[i], Prbuf);
283    }
284}
285
286/*
287 * init_stones:
288 *	Initialize the ring stone setting scheme for this time
289 */
290void
291init_stones(void)
292{
293    int i, j;
294
295    for (i = 0; i < NSTONES; i++)
296	Used[i] = FALSE;
297    for (i = 0; i < MAXRINGS; i++)
298    {
299	do
300	    j = rnd(NSTONES);
301	until (!Used[j]);
302	Used[j] = TRUE;
303	R_stones[i] = Stones[j].st_name;
304	Ring_info[i].oi_worth += Stones[j].st_value;
305    }
306}
307
308/*
309 * init_materials:
310 *	Initialize the construction materials for wands and staffs
311 */
312void
313init_materials(void)
314{
315    int i, j;
316    char *str;
317    static bool metused[NMETAL];
318
319    for (i = 0; i < NWOOD; i++)
320	Used[i] = FALSE;
321    for (i = 0; i < NMETAL; i++)
322	metused[i] = FALSE;
323    for (i = 0; i < MAXSTICKS; i++)
324    {
325	for (;;)
326	    if (rnd(2) == 0)
327	    {
328		j = rnd(NMETAL);
329		if (!metused[j])
330		{
331		    Ws_type[i] = "wand";
332		    str = Metal[j];
333		    metused[j] = TRUE;
334		    break;
335		}
336	    }
337	    else
338	    {
339		j = rnd(NWOOD);
340		if (!Used[j])
341		{
342		    Ws_type[i] = "staff";
343		    str = Wood[j];
344		    Used[j] = TRUE;
345		    break;
346		}
347	    }
348	Ws_made[i] = str;
349    }
350}
351
352#ifdef MASTER
353# define	NT	NUMTHINGS, "things"
354# define	MP	MAXPOTIONS, "potions"
355# define	MS	MAXSCROLLS, "scrolls"
356# define	MR	MAXRINGS, "rings"
357# define	MWS	MAXSTICKS, "sticks"
358# define	MW	MAXWEAPONS, "weapons"
359# define	MA	MAXARMORS, "armor"
360#else
361# define	NT	NUMTHINGS
362# define	MP	MAXPOTIONS
363# define	MS	MAXSCROLLS
364# define	MR	MAXRINGS
365# define	MWS	MAXSTICKS
366# define	MW	MAXWEAPONS
367# define	MA	MAXARMORS
368#endif
369
370/*
371 * sumprobs:
372 *	Sum up the probabilities for items appearing
373 */
374void
375sumprobs(struct obj_info *info, int bound
376#ifdef MASTER
377	, char *name
378#endif
379)
380{
381    struct obj_info *last, *endp, *start;
382
383    start = info;
384    endp = info + bound;
385    while (++info < endp)
386	info->oi_prob += (info - 1)->oi_prob;
387#ifdef MASTER
388    badcheck(name, start, bound);
389#endif
390}
391
392/*
393 * init_probs:
394 *	Initialize the probabilities for the various items
395 */
396void
397init_probs(void)
398{
399    sumprobs(Things, NT);
400    sumprobs(Pot_info, MP);
401    sumprobs(Scr_info, MS);
402    sumprobs(Ring_info, MR);
403    sumprobs(Ws_info, MWS);
404    sumprobs(Weap_info, MW);
405    sumprobs(Arm_info, MA);
406}
407
408#ifdef MASTER
409/*
410 * badcheck:
411 *	Check to see if a series of probabilities sums to 100
412 */
413void
414badcheck(char *name, struct obj_info *info, int bound)
415{
416    struct obj_info *end;
417
418    if (info[bound - 1].oi_prob == 100)
419	return;
420    printf("\nBad percentages for %s (bound = %d):\n", name, bound);
421    for (end = &info[bound]; info < end; info++)
422	printf("%3d%% %s\n", info->oi_prob, info->oi_name);
423    printf("[hit RETURN to continue]");
424    fflush(stdout);
425    while (getchar() != '\n')
426	continue;
427}
428#endif
429
430/*
431 * pick_color:
432 *	If he is halucinating, pick a random color name and return it,
433 *	otherwise return the given color.
434 */
435char *
436pick_color(char *col)
437{
438    return (on(Player, ISHALU) ? Rainbow[rnd(NCOLORS)] : col);
439}