xref: /csrg-svn/games/rogue/object.c (revision 60842)
132689Sbostic /*
2*60842Sbostic  * Copyright (c) 1988, 1993
3*60842Sbostic  *	The Regents of the University of California.  All rights reserved.
436704Sbostic  *
536704Sbostic  * This code is derived from software contributed to Berkeley by
636704Sbostic  * Timothy C. Stoehr.
736704Sbostic  *
842599Sbostic  * %sccs.include.redist.c%
936704Sbostic  */
1036704Sbostic 
1136704Sbostic #ifndef lint
12*60842Sbostic static char sccsid[] = "@(#)object.c	8.1 (Berkeley) 05/31/93";
1336704Sbostic #endif /* not lint */
1436704Sbostic 
1536704Sbostic /*
1632689Sbostic  * object.c
1732689Sbostic  *
1832689Sbostic  * This source herein may be modified and/or distributed by anybody who
1932689Sbostic  * so desires, with the following restrictions:
2032689Sbostic  *    1.)  No portion of this notice shall be removed.
2132689Sbostic  *    2.)  Credit shall not be taken for the creation of this source.
2232689Sbostic  *    3.)  This code is not to be traded, sold, or used for personal
2332689Sbostic  *         gain or profit.
2432689Sbostic  *
2532689Sbostic  */
2632689Sbostic 
2732689Sbostic #include "rogue.h"
2832689Sbostic 
2932689Sbostic object level_objects;
3032689Sbostic unsigned short dungeon[DROWS][DCOLS];
3132689Sbostic short foods = 0;
3232689Sbostic object *free_list = (object *) 0;
3332689Sbostic char *fruit = (char *) 0;
3432689Sbostic 
3532689Sbostic fighter rogue = {
3632689Sbostic 	INIT_AW,	/* armor, weapon */
3732689Sbostic 	INIT_RINGS,	/* rings */
3832689Sbostic 	INIT_HP,	/* Hp current,max */
3932689Sbostic 	INIT_STR,	/* Str current,max */
4032689Sbostic 	INIT_PACK,	/* pack */
4132689Sbostic 	INIT_GOLD,	/* gold */
4232689Sbostic 	INIT_EXP,	/* exp level,points */
4332689Sbostic 	0, 0,		/* row, col */
4432689Sbostic 	INIT_CHAR,	/* char */
4532689Sbostic 	INIT_MOVES	/* moves */
4632689Sbostic };
4732689Sbostic 
4832689Sbostic struct id id_potions[POTIONS] = {
4932689Sbostic {100, "blue \0                           ", "of increase strength ", 0},
5032689Sbostic {250, "red \0                            ", "of restore strength ", 0},
5132689Sbostic {100, "green \0                          ", "of healing ", 0},
5232689Sbostic {200, "grey \0                           ", "of extra healing ", 0},
5332689Sbostic  {10, "brown \0                          ", "of poison ", 0},
5432689Sbostic {300, "clear \0                          ", "of raise level ", 0},
5532689Sbostic  {10, "pink \0                           ", "of blindness ", 0},
5632689Sbostic  {25, "white \0                          ", "of hallucination ", 0},
5732689Sbostic {100, "purple \0                         ", "of detect monster ", 0},
5832689Sbostic {100, "black \0                          ", "of detect things ", 0},
5932689Sbostic  {10, "yellow \0                         ", "of confusion ", 0},
6032689Sbostic  {80, "plaid \0                          ", "of levitation ", 0},
6132689Sbostic {150, "burgundy \0                       ", "of haste self ", 0},
6232689Sbostic {145, "beige \0                          ", "of see invisible ", 0}
6332689Sbostic };
6432689Sbostic 
6532689Sbostic struct id id_scrolls[SCROLS] = {
6632689Sbostic {505, "                                   ", "of protect armor ", 0},
6732689Sbostic {200, "                                   ", "of hold monster ", 0},
6832689Sbostic {235, "                                   ", "of enchant weapon ", 0},
6932689Sbostic {235, "                                   ", "of enchant armor ", 0},
7032689Sbostic {175, "                                   ", "of identify ", 0},
7132689Sbostic {190, "                                   ", "of teleportation ", 0},
7232689Sbostic  {25, "                                   ", "of sleep ", 0},
7332689Sbostic {610, "                                   ", "of scare monster ", 0},
7432689Sbostic {210, "                                   ", "of remove curse ", 0},
7532689Sbostic  {80, "                                   ", "of create monster ",0},
7632689Sbostic  {25, "                                   ", "of aggravate monster ",0},
7732689Sbostic {180, "                                   ", "of magic mapping ", 0},
7832689Sbostic  {90, "                                   ", "of confuse monster ", 0}
7932689Sbostic };
8032689Sbostic 
8132689Sbostic struct id id_weapons[WEAPONS] = {
8232689Sbostic 	{150, "short bow ", "", 0},
8332689Sbostic 	  {8, "darts ", "", 0},
8432689Sbostic 	 {15, "arrows ", "", 0},
8532689Sbostic 	 {27, "daggers ", "", 0},
8632689Sbostic 	 {35, "shurikens ", "", 0},
8732689Sbostic 	{360, "mace ", "", 0},
8832689Sbostic 	{470, "long sword ", "", 0},
8932689Sbostic 	{580, "two-handed sword ", "", 0}
9032689Sbostic };
9132689Sbostic 
9232689Sbostic struct id id_armors[ARMORS] = {
9332689Sbostic 	{300, "leather armor ", "", (UNIDENTIFIED)},
9432689Sbostic 	{300, "ring mail ", "", (UNIDENTIFIED)},
9532689Sbostic 	{400, "scale mail ", "", (UNIDENTIFIED)},
9632689Sbostic 	{500, "chain mail ", "", (UNIDENTIFIED)},
9732689Sbostic 	{600, "banded mail ", "", (UNIDENTIFIED)},
9832689Sbostic 	{600, "splint mail ", "", (UNIDENTIFIED)},
9932689Sbostic 	{700, "plate mail ", "", (UNIDENTIFIED)}
10032689Sbostic };
10132689Sbostic 
10232689Sbostic struct id id_wands[WANDS] = {
10332689Sbostic 	 {25, "                                 ", "of teleport away ",0},
10432689Sbostic 	 {50, "                                 ", "of slow monster ", 0},
10532689Sbostic 	  {8, "                                 ", "of invisibility ",0},
10632689Sbostic 	 {55, "                                 ", "of polymorph ",0},
10732689Sbostic 	  {2, "                                 ", "of haste monster ",0},
10832689Sbostic 	 {20, "                                 ", "of magic missile ",0},
10932689Sbostic 	 {20, "                                 ", "of cancellation ",0},
11032689Sbostic 	  {0, "                                 ", "of do nothing ",0},
11132689Sbostic 	 {35, "                                 ", "of drain life ",0},
11232689Sbostic 	 {20, "                                 ", "of cold ",0},
11332689Sbostic 	 {20, "                                 ", "of fire ",0}
11432689Sbostic };
11532689Sbostic 
11632689Sbostic struct id id_rings[RINGS] = {
11732689Sbostic 	 {250, "                                 ", "of stealth ",0},
11832689Sbostic 	 {100, "                                 ", "of teleportation ", 0},
11932689Sbostic 	 {255, "                                 ", "of regeneration ",0},
12032689Sbostic 	 {295, "                                 ", "of slow digestion ",0},
12132689Sbostic 	 {200, "                                 ", "of add strength ",0},
12232689Sbostic 	 {250, "                                 ", "of sustain strength ",0},
12332689Sbostic 	 {250, "                                 ", "of dexterity ",0},
12432689Sbostic 	  {25, "                                 ", "of adornment ",0},
12532689Sbostic 	 {300, "                                 ", "of see invisible ",0},
12632689Sbostic 	 {290, "                                 ", "of maintain armor ",0},
12732689Sbostic 	 {270, "                                 ", "of searching ",0},
12832689Sbostic };
12932689Sbostic 
13032689Sbostic extern short cur_level, max_level;
13132689Sbostic extern short party_room;
13232689Sbostic extern char *error_file;
13332689Sbostic extern boolean is_wood[];
13432689Sbostic 
put_objects()13532689Sbostic put_objects()
13632689Sbostic {
13732689Sbostic 	short i, n;
13832689Sbostic 	object *obj;
13932689Sbostic 
14032689Sbostic 	if (cur_level < max_level) {
14132689Sbostic 		return;
14232689Sbostic 	}
14332689Sbostic 	n = coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
14432689Sbostic 	while (rand_percent(33)) {
14532689Sbostic 		n++;
14632689Sbostic 	}
14732689Sbostic 	if (party_room != NO_ROOM) {
14832689Sbostic 		make_party();
14932689Sbostic 	}
15032689Sbostic 	for (i = 0; i < n; i++) {
15132689Sbostic 		obj = gr_object();
15232689Sbostic 		rand_place(obj);
15332689Sbostic 	}
15432689Sbostic 	put_gold();
15532689Sbostic }
15632689Sbostic 
put_gold()15732689Sbostic put_gold()
15832689Sbostic {
15932689Sbostic 	short i, j;
16032689Sbostic 	short row,col;
16132689Sbostic 	boolean is_maze, is_room;
16232689Sbostic 
16332689Sbostic 	for (i = 0; i < MAXROOMS; i++) {
16432689Sbostic 		is_maze = (rooms[i].is_room & R_MAZE) ? 1 : 0;
16532689Sbostic 		is_room = (rooms[i].is_room & R_ROOM) ? 1 : 0;
16632689Sbostic 
16732689Sbostic 		if (!(is_room || is_maze)) {
16832689Sbostic 			continue;
16932689Sbostic 		}
17032689Sbostic 		if (is_maze || rand_percent(GOLD_PERCENT)) {
17132689Sbostic 			for (j = 0; j < 50; j++) {
17232689Sbostic 				row = get_rand(rooms[i].top_row+1,
17332689Sbostic 				rooms[i].bottom_row-1);
17432689Sbostic 				col = get_rand(rooms[i].left_col+1,
17532689Sbostic 				rooms[i].right_col-1);
17632689Sbostic 				if ((dungeon[row][col] == FLOOR) ||
17732689Sbostic 					(dungeon[row][col] == TUNNEL)) {
17832689Sbostic 					plant_gold(row, col, is_maze);
17932689Sbostic 					break;
18032689Sbostic 				}
18132689Sbostic 			}
18232689Sbostic 		}
18332689Sbostic 	}
18432689Sbostic }
18532689Sbostic 
plant_gold(row,col,is_maze)18632689Sbostic plant_gold(row, col, is_maze)
18732689Sbostic short row, col;
18832689Sbostic boolean is_maze;
18932689Sbostic {
19032689Sbostic 	object *obj;
19132689Sbostic 
19232689Sbostic 	obj = alloc_object();
19332689Sbostic 	obj->row = row; obj->col = col;
19432689Sbostic 	obj->what_is = GOLD;
19532689Sbostic 	obj->quantity = get_rand((2 * cur_level), (16 * cur_level));
19632689Sbostic 	if (is_maze) {
19732689Sbostic 		obj->quantity += obj->quantity / 2;
19832689Sbostic 	}
19932689Sbostic 	dungeon[row][col] |= OBJECT;
20032689Sbostic 	(void) add_to_pack(obj, &level_objects, 0);
20132689Sbostic }
20232689Sbostic 
place_at(obj,row,col)20332689Sbostic place_at(obj, row, col)
20432689Sbostic object *obj;
20532689Sbostic {
20632689Sbostic 	obj->row = row;
20732689Sbostic 	obj->col = col;
20832689Sbostic 	dungeon[row][col] |= OBJECT;
20932689Sbostic 	(void) add_to_pack(obj, &level_objects, 0);
21032689Sbostic }
21132689Sbostic 
21232689Sbostic object *
object_at(pack,row,col)21332689Sbostic object_at(pack, row, col)
21432689Sbostic register object *pack;
21532689Sbostic short row, col;
21632689Sbostic {
21732689Sbostic 	object *obj = (object *) 0;
21832689Sbostic 
21932689Sbostic 	if (dungeon[row][col] & (MONSTER | OBJECT)) {
22032689Sbostic 		obj = pack->next_object;
22132689Sbostic 
22232689Sbostic 		while (obj && ((obj->row != row) || (obj->col != col))) {
22332689Sbostic 			obj = obj->next_object;
22432689Sbostic 		}
22532689Sbostic 		if (!obj) {
22632689Sbostic 			message("object_at(): inconsistent", 1);
22732689Sbostic 		}
22832689Sbostic 	}
22932689Sbostic 	return(obj);
23032689Sbostic }
23132689Sbostic 
23232689Sbostic object *
get_letter_object(ch)23332689Sbostic get_letter_object(ch)
23432689Sbostic {
23532689Sbostic 	object *obj;
23632689Sbostic 
23732689Sbostic 	obj = rogue.pack.next_object;
23832689Sbostic 
23932689Sbostic 	while (obj && (obj->ichar != ch)) {
24032689Sbostic 		obj = obj->next_object;
24132689Sbostic 	}
24232689Sbostic 	return(obj);
24332689Sbostic }
24432689Sbostic 
free_stuff(objlist)24532689Sbostic free_stuff(objlist)
24632689Sbostic object *objlist;
24732689Sbostic {
24832689Sbostic 	object *obj;
24932689Sbostic 
25032689Sbostic 	while (objlist->next_object) {
25132689Sbostic 		obj = objlist->next_object;
25232689Sbostic 		objlist->next_object =
25332689Sbostic 			objlist->next_object->next_object;
25432689Sbostic 		free_object(obj);
25532689Sbostic 	}
25632689Sbostic }
25732689Sbostic 
25832689Sbostic char *
name_of(obj)25932689Sbostic name_of(obj)
26032689Sbostic object *obj;
26132689Sbostic {
26232689Sbostic 	char *retstring;
26332689Sbostic 
26432689Sbostic 	switch(obj->what_is) {
26532689Sbostic 	case SCROL:
26632689Sbostic 		retstring = obj->quantity > 1 ? "scrolls " : "scroll ";
26732689Sbostic 		break;
26832689Sbostic 	case POTION:
26932689Sbostic 		retstring = obj->quantity > 1 ? "potions " : "potion ";
27032689Sbostic 		break;
27132689Sbostic 	case FOOD:
27232689Sbostic 		if (obj->which_kind == RATION) {
27332689Sbostic 			retstring = "food ";
27432689Sbostic 		} else {
27532689Sbostic 			retstring = fruit;
27632689Sbostic 		}
27732689Sbostic 		break;
27832689Sbostic 	case WAND:
27932689Sbostic 		retstring = is_wood[obj->which_kind] ? "staff " : "wand ";
28032689Sbostic 		break;
28132689Sbostic 	case WEAPON:
28232689Sbostic 		switch(obj->which_kind) {
28332689Sbostic 		case DART:
28432689Sbostic 			retstring=obj->quantity > 1 ? "darts " : "dart ";
28532689Sbostic 			break;
28632689Sbostic 		case ARROW:
28732689Sbostic 			retstring=obj->quantity > 1 ? "arrows " : "arrow ";
28832689Sbostic 			break;
28932689Sbostic 		case DAGGER:
29032689Sbostic 			retstring=obj->quantity > 1 ? "daggers " : "dagger ";
29132689Sbostic 			break;
29232689Sbostic 		case SHURIKEN:
29332689Sbostic 			retstring=obj->quantity > 1?"shurikens ":"shuriken ";
29432689Sbostic 			break;
29532689Sbostic 		default:
29632689Sbostic 			retstring = id_weapons[obj->which_kind].title;
29732689Sbostic 		}
29832689Sbostic 		break;
29932689Sbostic 	case ARMOR:
30032689Sbostic 		retstring = "armor ";
30132689Sbostic 		break;
30232689Sbostic 	case RING:
30332689Sbostic 			retstring = "ring ";
30432689Sbostic 		break;
30532689Sbostic 	case AMULET:
30632689Sbostic 		retstring = "amulet ";
30732689Sbostic 		break;
30832689Sbostic 	default:
30932689Sbostic 		retstring = "unknown ";
31032689Sbostic 		break;
31132689Sbostic 	}
31232689Sbostic 	return(retstring);
31332689Sbostic }
31432689Sbostic 
31532689Sbostic object *
gr_object()31632689Sbostic gr_object()
31732689Sbostic {
31832689Sbostic 	object *obj;
31932689Sbostic 
32032689Sbostic 	obj = alloc_object();
32132689Sbostic 
32232689Sbostic 	if (foods < (cur_level / 3)) {
32332689Sbostic 		obj->what_is = FOOD;
32432689Sbostic 		foods++;
32532689Sbostic 	} else {
32632689Sbostic 		obj->what_is = gr_what_is();
32732689Sbostic 	}
32832689Sbostic 	switch(obj->what_is) {
32932689Sbostic 	case SCROL:
33032689Sbostic 		gr_scroll(obj);
33132689Sbostic 		break;
33232689Sbostic 	case POTION:
33332689Sbostic 		gr_potion(obj);
33432689Sbostic 		break;
33532689Sbostic 	case WEAPON:
33632689Sbostic 		gr_weapon(obj, 1);
33732689Sbostic 		break;
33832689Sbostic 	case ARMOR:
33932689Sbostic 		gr_armor(obj);
34032689Sbostic 		break;
34132689Sbostic 	case WAND:
34232689Sbostic 		gr_wand(obj);
34332689Sbostic 		break;
34432689Sbostic 	case FOOD:
34532689Sbostic 		get_food(obj, 0);
34632689Sbostic 		break;
34732689Sbostic 	case RING:
34832689Sbostic 		gr_ring(obj, 1);
34932689Sbostic 		break;
35032689Sbostic 	}
35132689Sbostic 	return(obj);
35232689Sbostic }
35332689Sbostic 
35432689Sbostic unsigned short
gr_what_is()35532689Sbostic gr_what_is()
35632689Sbostic {
35732689Sbostic 	short percent;
35832689Sbostic 	unsigned short what_is;
35932689Sbostic 
36032689Sbostic 	percent = get_rand(1, 91);
36132689Sbostic 
36232689Sbostic 	if (percent <= 30) {
36332689Sbostic 		what_is = SCROL;
36432689Sbostic 	} else if (percent <= 60) {
36532689Sbostic 		what_is = POTION;
36632689Sbostic 	} else if (percent <= 64) {
36732689Sbostic 		what_is = WAND;
36832689Sbostic 	} else if (percent <= 74) {
36932689Sbostic 		what_is = WEAPON;
37032689Sbostic 	} else if (percent <= 83) {
37132689Sbostic 		what_is = ARMOR;
37232689Sbostic 	} else if (percent <= 88) {
37332689Sbostic 		what_is = FOOD;
37432689Sbostic 	} else {
37532689Sbostic 		what_is = RING;
37632689Sbostic 	}
37732689Sbostic 	return(what_is);
37832689Sbostic }
37932689Sbostic 
gr_scroll(obj)38032689Sbostic gr_scroll(obj)
38132689Sbostic object *obj;
38232689Sbostic {
38332689Sbostic 	short percent;
38432689Sbostic 
38532689Sbostic 	percent = get_rand(0, 91);
38632689Sbostic 
38732689Sbostic 	obj->what_is = SCROL;
38832689Sbostic 
38932689Sbostic 	if (percent <= 5) {
39032689Sbostic 		obj->which_kind = PROTECT_ARMOR;
39132689Sbostic 	} else if (percent <= 10) {
39232689Sbostic 		obj->which_kind = HOLD_MONSTER;
39332689Sbostic 	} else if (percent <= 20) {
39432689Sbostic 		obj->which_kind = CREATE_MONSTER;
39532689Sbostic 	} else if (percent <= 35) {
39632689Sbostic 		obj->which_kind = IDENTIFY;
39732689Sbostic 	} else if (percent <= 43) {
39832689Sbostic 		obj->which_kind = TELEPORT;
39932689Sbostic 	} else if (percent <= 50) {
40032689Sbostic 		obj->which_kind = SLEEP;
40132689Sbostic 	} else if (percent <= 55) {
40232689Sbostic 		obj->which_kind = SCARE_MONSTER;
40332689Sbostic 	} else if (percent <= 64) {
40432689Sbostic 		obj->which_kind = REMOVE_CURSE;
40532689Sbostic 	} else if (percent <= 69) {
40632689Sbostic 		obj->which_kind = ENCH_ARMOR;
40732689Sbostic 	} else if (percent <= 74) {
40832689Sbostic 		obj->which_kind = ENCH_WEAPON;
40932689Sbostic 	} else if (percent <= 80) {
41032689Sbostic 		obj->which_kind = AGGRAVATE_MONSTER;
41132689Sbostic 	} else if (percent <= 86) {
41232689Sbostic 		obj->which_kind = CON_MON;
41332689Sbostic 	} else {
41432689Sbostic 		obj->which_kind = MAGIC_MAPPING;
41532689Sbostic 	}
41632689Sbostic }
41732689Sbostic 
gr_potion(obj)41832689Sbostic gr_potion(obj)
41932689Sbostic object *obj;
42032689Sbostic {
42132689Sbostic 	short percent;
42232689Sbostic 
42332689Sbostic 	percent = get_rand(1, 118);
42432689Sbostic 
42532689Sbostic 	obj->what_is = POTION;
42632689Sbostic 
42732689Sbostic 	if (percent <= 5) {
42832689Sbostic 		obj->which_kind = RAISE_LEVEL;
42932689Sbostic 	} else if (percent <= 15) {
43032689Sbostic 		obj->which_kind = DETECT_OBJECTS;
43132689Sbostic 	} else if (percent <= 25) {
43232689Sbostic 		obj->which_kind = DETECT_MONSTER;
43332689Sbostic 	} else if (percent <= 35) {
43432689Sbostic 		obj->which_kind = INCREASE_STRENGTH;
43532689Sbostic 	} else if (percent <= 45) {
43632689Sbostic 		obj->which_kind = RESTORE_STRENGTH;
43732689Sbostic 	} else if (percent <= 55) {
43832689Sbostic 		obj->which_kind = HEALING;
43932689Sbostic 	} else if (percent <= 65) {
44032689Sbostic 		obj->which_kind = EXTRA_HEALING;
44132689Sbostic 	} else if (percent <= 75) {
44232689Sbostic 		obj->which_kind = BLINDNESS;
44332689Sbostic 	} else if (percent <= 85) {
44432689Sbostic 		obj->which_kind = HALLUCINATION;
44532689Sbostic 	} else if (percent <= 95) {
44632689Sbostic 		obj->which_kind = CONFUSION;
44732689Sbostic 	} else if (percent <= 105) {
44832689Sbostic 		obj->which_kind = POISON;
44932689Sbostic 	} else if (percent <= 110) {
45032689Sbostic 		obj->which_kind = LEVITATION;
45132689Sbostic 	} else if (percent <= 114) {
45232689Sbostic 		obj->which_kind = HASTE_SELF;
45332689Sbostic 	} else {
45432689Sbostic 		obj->which_kind = SEE_INVISIBLE;
45532689Sbostic 	}
45632689Sbostic }
45732689Sbostic 
gr_weapon(obj,assign_wk)45832689Sbostic gr_weapon(obj, assign_wk)
45932689Sbostic object *obj;
46032689Sbostic int assign_wk;
46132689Sbostic {
46232689Sbostic 	short percent;
46332689Sbostic 	short i;
46432689Sbostic 	short blessing, increment;
46532689Sbostic 
46632689Sbostic 	obj->what_is = WEAPON;
46732689Sbostic 	if (assign_wk) {
46832689Sbostic 		obj->which_kind = get_rand(0, (WEAPONS - 1));
46932689Sbostic 	}
47032689Sbostic 	if ((obj->which_kind == ARROW) || (obj->which_kind == DAGGER) ||
47132689Sbostic 		(obj->which_kind == SHURIKEN) | (obj->which_kind == DART)) {
47232689Sbostic 		obj->quantity = get_rand(3, 15);
47332689Sbostic 		obj->quiver = get_rand(0, 126);
47432689Sbostic 	} else {
47532689Sbostic 		obj->quantity = 1;
47632689Sbostic 	}
47732689Sbostic 	obj->hit_enchant = obj->d_enchant = 0;
47832689Sbostic 
47932689Sbostic 	percent = get_rand(1, 96);
48032689Sbostic 	blessing = get_rand(1, 3);
48132689Sbostic 
48232689Sbostic 	if (percent <= 16) {
48332689Sbostic 		increment = 1;
48432689Sbostic 	} else if (percent <= 32) {
48532689Sbostic 		increment = -1;
48632689Sbostic 		obj->is_cursed = 1;
48732689Sbostic 	}
48832689Sbostic 	if (percent <= 32) {
48932689Sbostic 		for (i = 0; i < blessing; i++) {
49032689Sbostic 			if (coin_toss()) {
49132689Sbostic 				obj->hit_enchant += increment;
49232689Sbostic 			} else {
49332689Sbostic 				obj->d_enchant += increment;
49432689Sbostic 			}
49532689Sbostic 		}
49632689Sbostic 	}
49732689Sbostic 	switch(obj->which_kind) {
49832689Sbostic 	case BOW:
49932689Sbostic 	case DART:
50032689Sbostic 		obj->damage = "1d1";
50132689Sbostic 		break;
50232689Sbostic 	case ARROW:
50332689Sbostic 		obj->damage = "1d2";
50432689Sbostic 		break;
50532689Sbostic 	case DAGGER:
50632689Sbostic 		obj->damage = "1d3";
50732689Sbostic 		break;
50832689Sbostic 	case SHURIKEN:
50932689Sbostic 		obj->damage = "1d4";
51032689Sbostic 		break;
51132689Sbostic 	case MACE:
51232689Sbostic 		obj->damage = "2d3";
51332689Sbostic 		break;
51432689Sbostic 	case LONG_SWORD:
51532689Sbostic 		obj->damage = "3d4";
51632689Sbostic 		break;
51732689Sbostic 	case TWO_HANDED_SWORD:
51832689Sbostic 		obj->damage = "4d5";
51932689Sbostic 		break;
52032689Sbostic 	}
52132689Sbostic }
52232689Sbostic 
gr_armor(obj)52332689Sbostic gr_armor(obj)
52432689Sbostic object *obj;
52532689Sbostic {
52632689Sbostic 	short percent;
52732689Sbostic 	short blessing;
52832689Sbostic 
52932689Sbostic 	obj->what_is = ARMOR;
53032689Sbostic 	obj->which_kind = get_rand(0, (ARMORS - 1));
53132689Sbostic 	obj->class = obj->which_kind + 2;
53232689Sbostic 	if ((obj->which_kind == PLATE) || (obj->which_kind == SPLINT)) {
53332689Sbostic 		obj->class--;
53432689Sbostic 	}
53532689Sbostic 	obj->is_protected = 0;
53632689Sbostic 	obj->d_enchant = 0;
53732689Sbostic 
53832689Sbostic 	percent = get_rand(1, 100);
53932689Sbostic 	blessing = get_rand(1, 3);
54032689Sbostic 
54132689Sbostic 	if (percent <= 16) {
54232689Sbostic 		obj->is_cursed = 1;
54332689Sbostic 		obj->d_enchant -= blessing;
54432689Sbostic 	} else if (percent <= 33) {
54532689Sbostic 		obj->d_enchant += blessing;
54632689Sbostic 	}
54732689Sbostic }
54832689Sbostic 
gr_wand(obj)54932689Sbostic gr_wand(obj)
55032689Sbostic object *obj;
55132689Sbostic {
55232689Sbostic 	obj->what_is = WAND;
55332689Sbostic 	obj->which_kind = get_rand(0, (WANDS - 1));
55432689Sbostic 	obj->class = get_rand(3, 7);
55532689Sbostic }
55632689Sbostic 
get_food(obj,force_ration)55732689Sbostic get_food(obj, force_ration)
55832689Sbostic object *obj;
55932689Sbostic boolean force_ration;
56032689Sbostic {
56132689Sbostic 	obj->what_is = FOOD;
56232689Sbostic 
56332689Sbostic 	if (force_ration || rand_percent(80)) {
56432689Sbostic 		obj->which_kind = RATION;
56532689Sbostic 	} else {
56632689Sbostic 		obj->which_kind = FRUIT;
56732689Sbostic 	}
56832689Sbostic }
56932689Sbostic 
put_stairs()57032689Sbostic put_stairs()
57132689Sbostic {
57232689Sbostic 	short row, col;
57332689Sbostic 
57432689Sbostic 	gr_row_col(&row, &col, (FLOOR | TUNNEL));
57532689Sbostic 	dungeon[row][col] |= STAIRS;
57632689Sbostic }
57732689Sbostic 
get_armor_class(obj)57832689Sbostic get_armor_class(obj)
57932689Sbostic object *obj;
58032689Sbostic {
58132689Sbostic 	if (obj) {
58232689Sbostic 		return(obj->class + obj->d_enchant);
58332689Sbostic 	}
58432689Sbostic 	return(0);
58532689Sbostic }
58632689Sbostic 
58732689Sbostic object *
alloc_object()58832689Sbostic alloc_object()
58932689Sbostic {
59032689Sbostic 	object *obj;
59132689Sbostic 
59232689Sbostic 	if (free_list) {
59332689Sbostic 		obj = free_list;
59432689Sbostic 		free_list = free_list->next_object;
59532689Sbostic 	} else if (!(obj = (object *) md_malloc(sizeof(object)))) {
59632689Sbostic 			message("cannot allocate object, saving game", 0);
59732689Sbostic 			save_into_file(error_file);
59832689Sbostic 	}
59932689Sbostic 	obj->quantity = 1;
60032689Sbostic 	obj->ichar = 'L';
60132689Sbostic 	obj->picked_up = obj->is_cursed = 0;
60232689Sbostic 	obj->in_use_flags = NOT_USED;
60332689Sbostic 	obj->identified = UNIDENTIFIED;
60432689Sbostic 	obj->damage = "1d1";
60532689Sbostic 	return(obj);
60632689Sbostic }
60732689Sbostic 
free_object(obj)60832689Sbostic free_object(obj)
60932689Sbostic object *obj;
61032689Sbostic {
61132689Sbostic 	obj->next_object = free_list;
61232689Sbostic 	free_list = obj;
61332689Sbostic }
61432689Sbostic 
make_party()61532689Sbostic make_party()
61632689Sbostic {
61732689Sbostic 	short n;
61832689Sbostic 
61932689Sbostic 	party_room = gr_room();
62032689Sbostic 
62132689Sbostic 	n = rand_percent(99) ? party_objects(party_room) : 11;
62232689Sbostic 	if (rand_percent(99)) {
62332689Sbostic 		party_monsters(party_room, n);
62432689Sbostic 	}
62532689Sbostic }
62632689Sbostic 
show_objects()62732689Sbostic show_objects()
62832689Sbostic {
62932689Sbostic 	object *obj;
63032689Sbostic 	short mc, rc, row, col;
63132689Sbostic 	object *monster;
63232689Sbostic 
63332689Sbostic 	obj = level_objects.next_object;
63432689Sbostic 
63532689Sbostic 	while (obj) {
63632689Sbostic 		row = obj->row;
63732689Sbostic 		col = obj->col;
63832689Sbostic 
63932689Sbostic 		rc = get_mask_char(obj->what_is);
64032689Sbostic 
64132689Sbostic 		if (dungeon[row][col] & MONSTER) {
64232689Sbostic 			if (monster = object_at(&level_monsters, row, col)) {
64332689Sbostic 				monster->trail_char = rc;
64432689Sbostic 			}
64532689Sbostic 		}
64632689Sbostic 		mc = mvinch(row, col);
64732689Sbostic 		if (((mc < 'A') || (mc > 'Z')) &&
64832689Sbostic 			((row != rogue.row) || (col != rogue.col))) {
64932689Sbostic 			mvaddch(row, col, rc);
65032689Sbostic 		}
65132689Sbostic 		obj = obj->next_object;
65232689Sbostic 	}
65332689Sbostic 
65432689Sbostic 	monster = level_monsters.next_object;
65532689Sbostic 
65632689Sbostic 	while (monster) {
65732689Sbostic 		if (monster->m_flags & IMITATES) {
65832689Sbostic 			mvaddch(monster->row, monster->col, (int) monster->disguise);
65932689Sbostic 		}
66032689Sbostic 		monster = monster->next_monster;
66132689Sbostic 	}
66232689Sbostic }
66332689Sbostic 
put_amulet()66432689Sbostic put_amulet()
66532689Sbostic {
66632689Sbostic 	object *obj;
66732689Sbostic 
66832689Sbostic 	obj = alloc_object();
66932689Sbostic 	obj->what_is = AMULET;
67032689Sbostic 	rand_place(obj);
67132689Sbostic }
67232689Sbostic 
rand_place(obj)67332689Sbostic rand_place(obj)
67432689Sbostic object *obj;
67532689Sbostic {
67632689Sbostic 	short row, col;
67732689Sbostic 
67832689Sbostic 	gr_row_col(&row, &col, (FLOOR | TUNNEL));
67932689Sbostic 	place_at(obj, row, col);
68032689Sbostic }
68132689Sbostic 
c_object_for_wizard()68232689Sbostic c_object_for_wizard()
68332689Sbostic {
68432689Sbostic 	short ch, max, wk;
68532689Sbostic 	object *obj;
68632689Sbostic 	char buf[80];
68732689Sbostic 
68832689Sbostic 	if (pack_count((object *) 0) >= MAX_PACK_COUNT) {
68932689Sbostic 		message("pack full", 0);
69032689Sbostic 		return;
69132689Sbostic 	}
69232689Sbostic 	message("type of object?", 0);
69332689Sbostic 
69432689Sbostic 	while (r_index("!?:)]=/,\033", (ch = rgetchar()), 0) == -1) {
69532689Sbostic 		sound_bell();
69632689Sbostic 	}
69732689Sbostic 	check_message();
69832689Sbostic 
69932689Sbostic 	if (ch == '\033') {
70032689Sbostic 		return;
70132689Sbostic 	}
70232689Sbostic 	obj = alloc_object();
70332689Sbostic 
70432689Sbostic 	switch(ch) {
70532689Sbostic 	case '!':
70632689Sbostic 		obj->what_is = POTION;
70732689Sbostic 		max = POTIONS - 1;
70832689Sbostic 		break;
70932689Sbostic 	case '?':
71032689Sbostic 		obj->what_is = SCROL;
71132689Sbostic 		max = SCROLS - 1;
71232689Sbostic 		break;
71332689Sbostic 	case ',':
71432689Sbostic 		obj->what_is = AMULET;
71532689Sbostic 		break;
71632689Sbostic 	case ':':
71732689Sbostic 		get_food(obj, 0);
71832689Sbostic 		break;
71932689Sbostic 	case ')':
72032689Sbostic 		gr_weapon(obj, 0);
72132689Sbostic 		max = WEAPONS - 1;
72232689Sbostic 		break;
72332689Sbostic 	case ']':
72432689Sbostic 		gr_armor(obj);
72532689Sbostic 		max = ARMORS - 1;
72632689Sbostic 		break;
72732689Sbostic 	case '/':
72832689Sbostic 		gr_wand(obj);
72932689Sbostic 		max = WANDS - 1;
73032689Sbostic 		break;
73132689Sbostic 	case '=':
73232689Sbostic 		max = RINGS - 1;
73332689Sbostic 		obj->what_is = RING;
73432689Sbostic 		break;
73532689Sbostic 	}
73632689Sbostic 	if ((ch != ',') && (ch != ':')) {
73732689Sbostic GIL:
73832689Sbostic 		if (get_input_line("which kind?", "", buf, "", 0, 1)) {
73932689Sbostic 			wk = get_number(buf);
74032689Sbostic 			if ((wk >= 0) && (wk <= max)) {
74132689Sbostic 				obj->which_kind = (unsigned short) wk;
74232689Sbostic 				if (obj->what_is == RING) {
74332689Sbostic 					gr_ring(obj, 0);
74432689Sbostic 				}
74532689Sbostic 			} else {
74632689Sbostic 				sound_bell();
74732689Sbostic 				goto GIL;
74832689Sbostic 			}
74932689Sbostic 		} else {
75032689Sbostic 			free_object(obj);
75132689Sbostic 			return;
75232689Sbostic 		}
75332689Sbostic 	}
75432689Sbostic 	get_desc(obj, buf);
75532689Sbostic 	message(buf, 0);
75632689Sbostic 	(void) add_to_pack(obj, &rogue.pack, 1);
75732689Sbostic }
758