1 /* $Id$ */
2 /* File: cmd6.c */
3 
4 /* Purpose: Object commands */
5 
6 /*
7  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8  *
9  * This software may be copied and distributed for educational, research, and
10  * not for profit purposes provided that this copyright and statement are
11  * included in all such copies.
12  */
13 
14 #define SERVER
15 
16 #include "angband.h"
17 
18 
19 
20 /*
21  * This file includes code for eating food, drinking potions,
22  * reading scrolls, aiming wands, using staffs, zapping rods,
23  * and activating artifacts.
24  *
25  * In all cases, if the player becomes "aware" of the item's use
26  * by testing it, mark it as "aware" and reward some experience
27  * based on the object's level, always rounding up.  If the player
28  * remains "unaware", mark that object "kind" as "tried".
29  *
30  * This code now correctly handles the unstacking of wands, staffs,
31  * and rods.  Note the overly paranoid warning about potential pack
32  * overflow, which allows the player to use and drop a stacked item.
33  *
34  * In all "unstacking" scenarios, the "used" object is "carried" as if
35  * the player had just picked it up.  In particular, this means that if
36  * the use of an item induces pack overflow, that item will be dropped.
37  *
38  * For simplicity, these routines induce a full "pack reorganization"
39  * which not only combines similar items, but also reorganizes various
40  * items to obey the current "sorting" method.  This may require about
41  * 400 item comparisons, but only occasionally.
42  *
43  * There may be a BIG problem with any "effect" that can cause "changes"
44  * to the inventory.  For example, a "scroll of recharging" can cause
45  * a wand/staff to "disappear", moving the inventory up.  Luckily, the
46  * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
47  * But, for example, a "staff of recharging" could cause MAJOR problems.
48  * In such a case, it will be best to either (1) "postpone" the effect
49  * until the end of the function, or (2) "change" the effect, say, into
50  * giving a staff "negative" charges, or "turning a staff into a stick".
51  * It seems as though a "rod of recharging" might in fact cause problems.
52  * The basic problem is that the act of recharging (and destroying) an
53  * item causes the inducer of that action to "move", causing "o_ptr" to
54  * no longer point at the correct item, with horrifying results.
55  *
56  * Note that food/potions/scrolls no longer use bit-flags for effects,
57  * but instead use the "sval" (which is also used to sort the objects).
58  */
59 
60 
61 /* How much drinking water feeds ents */
62 #define WATER_ENT_FOOD 1500
63 
64 
65 /* Quick hack to make use of firestones		- Jir -
66  * This function should be obsoleted when ToME power.c is backported.
67  */
68 /* Basically not cumulative */
do_tank(int Ind,int power)69 static void do_tank(int Ind, int power)
70 {
71 	// player_type *p_ptr = Players[Ind];
72 	int i = randint(9);
73 	switch (i)
74 	{
75 		case 1:
76 			set_adrenaline(Ind, power + randint(power));
77 			break;
78 		case 2:
79 			set_biofeedback(Ind, power + randint(power));
80 			break;
81 		case 3:
82 		case 4:
83 			set_tim_esp(Ind, power + randint(power));
84 			break;
85 		case 5:
86 			set_prob_travel(Ind, power + randint(power));
87 			break;
88 		case 6:
89 			set_fury(Ind, power + randint(power));
90 			break;
91 		case 7:
92 			set_fast(Ind, power + randint(power), 10);
93 			break;
94 		case 8:
95 			set_shero(Ind, power + randint(power));
96 			break;
97 		case 9:
98 			set_oppose_acid(Ind, power + randint(power));
99 			set_oppose_elec(Ind, power + randint(power));
100 			set_oppose_fire(Ind, power + randint(power));
101 			set_oppose_cold(Ind, power + randint(power));
102 			set_oppose_pois(Ind, power + randint(power));
103 			break;
104 	}
105 }
106 
107 
eat_food(int Ind,int sval,object_type * o_ptr,bool * keep)108 bool eat_food(int Ind, int sval, object_type *o_ptr, bool *keep) {
109 	player_type *p_ptr = Players[Ind];
110 	bool ident = FALSE;
111 
112 	/* Analyze the food */
113 	switch (sval) {
114 	case SV_FOOD_POISON:
115 		if (!(p_ptr->resist_pois || p_ptr->oppose_pois)) {
116 			if (set_poisoned(Ind, p_ptr->poisoned + rand_int(10) + 10, Ind))
117 				ident = TRUE;
118 		}
119 		break;
120 
121 	case SV_FOOD_BLINDNESS:
122 		if (!p_ptr->resist_blind) {
123 			if (set_blind(Ind, p_ptr->blind + rand_int(200) + 200))
124 				ident = TRUE;
125 		}
126 		break;
127 
128 	case SV_FOOD_PARANOIA:
129 		if (!p_ptr->resist_fear) {
130 			if (set_afraid(Ind, p_ptr->afraid + rand_int(10) + 10) ||
131 			    set_image(Ind, p_ptr->image + 20))
132 				ident = TRUE;
133 		}
134 		break;
135 
136 	case SV_FOOD_CONFUSION:
137 		if (!p_ptr->resist_conf) {
138 			if (set_confused(Ind, p_ptr->confused + rand_int(10) + 10))
139 				ident = TRUE;
140 		}
141 		break;
142 
143 	case SV_FOOD_HALLUCINATION:
144 		if (!p_ptr->resist_chaos) {
145 			take_sanity_hit(Ind, 2, "drugs");
146 			if (set_image(Ind, p_ptr->image + rand_int(250) + 250))
147 				ident = TRUE;
148 		}
149 		break;
150 
151 	case SV_FOOD_PARALYSIS:
152 		if (!p_ptr->free_act) {
153 			if (set_paralyzed(Ind, p_ptr->paralyzed + rand_int(10) + 10))
154 				ident = TRUE;
155 		}
156 		break;
157 
158 	case SV_FOOD_WEAKNESS:
159 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(6, 6), "poisonous food", 0);
160 		(void)do_dec_stat(Ind, A_STR, STAT_DEC_NORMAL);
161 		ident = TRUE;
162 		break;
163 
164 	case SV_FOOD_SICKNESS:
165 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(6, 6), "poisonous food", 0);
166 		(void)do_dec_stat(Ind, A_CON, STAT_DEC_NORMAL);
167 		ident = TRUE;
168 		break;
169 
170 	case SV_FOOD_STUPIDITY:
171 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(8, 8), "poisonous food", 0);
172 		(void)do_dec_stat(Ind, A_INT, STAT_DEC_NORMAL);
173 		ident = TRUE;
174 		break;
175 
176 	case SV_FOOD_NAIVETY:
177 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(8, 8), "poisonous food", 0);
178 		(void)do_dec_stat(Ind, A_WIS, STAT_DEC_NORMAL);
179 		ident = TRUE;
180 		break;
181 
182 	case SV_FOOD_UNHEALTH:
183 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(10, 10), "poisonous food", 0);
184 		(void)do_dec_stat(Ind, A_CON, STAT_DEC_NORMAL);
185 		ident = TRUE;
186 		break;
187 
188 	case SV_FOOD_DISEASE:
189 		if (!p_ptr->suscep_life) take_hit(Ind, damroll(10, 10), "poisonous food", 0);
190 		(void)do_dec_stat(Ind, A_STR, STAT_DEC_NORMAL);
191 		ident = TRUE;
192 		break;
193 
194 	case SV_FOOD_CURE_POISON:
195 		if (set_poisoned(Ind, 0, 0)) ident = TRUE;
196 		break;
197 
198 	case SV_FOOD_CURE_BLINDNESS:
199 		if (set_blind(Ind, 0)) ident = TRUE;
200 		break;
201 
202 	case SV_FOOD_CURE_PARANOIA:
203 		if (set_afraid(Ind, 0)) ident = TRUE;
204 //				if (set_image(Ind, p_ptr->image / 2)) ident = TRUE;
205 		if (set_image(Ind, 0)) ident = TRUE;
206 		break;
207 
208 	case SV_FOOD_CURE_CONFUSION:
209 		if (set_confused(Ind, 0)) ident = TRUE;
210 		break;
211 
212 	case SV_FOOD_CURE_SERIOUS:
213 		if (set_blind(Ind, 0)) ident = TRUE;
214 		if (set_confused(Ind, 0)) ident = TRUE;
215 		if (set_cut(Ind, (p_ptr->cut / 2) - 50, p_ptr->cut_attacker)) ident = TRUE;
216 //			(void)set_poisoned(Ind, 0, 0);
217 //			(void)set_image(Ind, 0);	// ok?
218 		if (hp_player(Ind, damroll(6, 8))) ident = TRUE;
219 		break;
220 
221 	case SV_FOOD_RESTORE_STR:
222 		if (do_res_stat(Ind, A_STR)) ident = TRUE;
223 		break;
224 
225 	case SV_FOOD_RESTORE_CON:
226 		if (do_res_stat(Ind, A_CON)) ident = TRUE;
227 		break;
228 
229 	case SV_FOOD_RESTORING:
230 		if (do_res_stat(Ind, A_STR)) ident = TRUE;
231 		if (do_res_stat(Ind, A_INT)) ident = TRUE;
232 		if (do_res_stat(Ind, A_WIS)) ident = TRUE;
233 		if (do_res_stat(Ind, A_DEX)) ident = TRUE;
234 		if (do_res_stat(Ind, A_CON)) ident = TRUE;
235 		if (do_res_stat(Ind, A_CHR)) ident = TRUE;
236 		if (restore_level(Ind)) ident = TRUE; /* <- new (for RPG_SERVER) */
237 		break;
238 
239 	case SV_FOOD_FORTUNE_COOKIE:
240 		if (!p_ptr->suscep_life)
241 			msg_print(Ind, "That tastes good.");
242 		if (p_ptr->blind || no_lite(Ind)) {
243 			msg_print(Ind, "You feel some paper in it - what a pity you cannot see!");
244 		} else {
245 			msg_print(Ind, "There is message in the cookie. It says:");
246 			fortune(Ind, FALSE);
247 		}
248 		ident = TRUE;
249 		break;
250 
251 	case SV_FOOD_ATHELAS:
252 		msg_print(Ind, "A fresh, clean essence rises, driving away wounds and poison.");
253 		ident = set_poisoned(Ind, 0, 0) |
254 			set_stun(Ind, 0) |
255 			set_cut(Ind, 0, 0);
256 		if (p_ptr->black_breath) {
257 			msg_print(Ind, "The hold of the Black Breath on you is broken!");
258 			p_ptr->black_breath = FALSE;
259 		}
260 		if (p_ptr->suscep_life) take_hit(Ind, 250, "a sprig of athelas", 0);
261 		ident = TRUE;
262 		break;
263 
264 	case SV_FOOD_RATION:
265 		/* 'Rogue' tribute :) */
266 		if (magik(10)) {
267 			msg_print(Ind, "Yuk, that food tasted awful.");
268 			if (p_ptr->max_lev < 2 &&
269 			    !((p_ptr->mode & MODE_DED_IDDC) && !in_irondeepdive(&p_ptr->wpos)))
270 				gain_exp(Ind, 1);
271 			break;
272 		}
273 		/* Fall through */
274 	case SV_FOOD_BISCUIT:
275 	case SV_FOOD_JERKY:
276 	case SV_FOOD_SLIME_MOLD:
277 		if (!p_ptr->suscep_life || sval == SV_FOOD_SLIME_MOLD)
278 			msg_print(Ind, "That tastes good.");
279 		ident = TRUE;
280 		break;
281 
282 	case SV_FOOD_WAYBREAD:
283 		if (!p_ptr->suscep_life && !p_ptr->suscep_good) {
284 			msg_print(Ind, "That tastes very good.");
285 			(void)set_poisoned(Ind, 0, 0);
286 			(void)set_image(Ind, 0);	// ok?
287 			(void)hp_player(Ind, damroll(5, 8));
288 			set_food(Ind, PY_FOOD_MAX - 1);
289 			ident = TRUE;
290 		} else {
291 			msg_print(Ind, "A surge of cleansing disrupts your body.");
292 			take_hit(Ind, damroll(5, 2), "lembas", 0);
293 		}
294 		break;
295 
296 	case SV_FOOD_PINT_OF_ALE:
297 	case SV_FOOD_PINT_OF_WINE:
298 	    if (!p_ptr->suscep_life) {
299 		if (!o_ptr) {
300 			msg_format(Ind, "\377%c*HIC*", random_colour());
301 			msg_format_near(Ind, "\377%c%s hiccups!", random_colour(), p_ptr->name);
302 
303 			if (magik(TRUE? 60 : 30))
304 				set_confused(Ind, p_ptr->confused + 20 + randint(20));
305 			if (magik(TRUE? 50 : 20))
306 				set_stun(Ind, p_ptr->stun + 10 + randint(10));
307 
308 			if (magik(TRUE? 50 : 10)){
309 				set_image(Ind, p_ptr->image + 10 + randint(10));
310 				take_sanity_hit(Ind, 1, "ale");
311 			}
312 			if (magik(TRUE? 10 : 20))
313 				set_paralyzed(Ind, p_ptr->paralyzed + 10 + randint(10));
314 			if (magik(TRUE? 50 : 10))
315 				set_hero(Ind, 10 + randint(10)); /* removed stacking */
316 			if (magik(TRUE? 20 : 5))
317 				set_shero(Ind, 5 + randint(10)); /* removed stacking */
318 			if (magik(TRUE? 5 : 10))
319 				set_afraid(Ind, p_ptr->afraid + 15 + randint(10));
320 			if (magik(TRUE? 5 : 10))
321 				set_slow(Ind, p_ptr->slow + 10 + randint(10));
322 			else if (magik(TRUE? 20 : 5))
323 				set_fast(Ind, 10 + randint(10), 10); /* removed stacking */
324 			/* Methyl! */
325 			if (magik(TRUE? 0 : 3))
326 				set_blind(Ind, p_ptr->blind + 10 + randint(10));
327 			if (rand_int(100) < p_ptr->food * magik(TRUE? 40 : 60) / PY_FOOD_MAX)
328 			{
329 				msg_print(Ind, "You become nauseous and vomit!");
330 				msg_format_near(Ind, "%s vomits!", p_ptr->name);
331 				/* made salt water less deadly -APD */
332 				(void)set_food(Ind, (p_ptr->food/2));
333 				(void)set_poisoned(Ind, 0, 0);
334 				(void)set_paralyzed(Ind, p_ptr->paralyzed + 4);
335 			}
336 			if (magik(TRUE? 2 : 3))
337 				(void)dec_stat(Ind, A_DEX, 1, STAT_DEC_TEMPORARY);
338 			if (magik(TRUE? 2 : 3))
339 				(void)dec_stat(Ind, A_WIS, 1, STAT_DEC_TEMPORARY);
340 			if (magik(TRUE? 0 : 1))
341 				(void)dec_stat(Ind, A_CON, 1, STAT_DEC_TEMPORARY);
342 			//			(void)dec_stat(Ind, A_STR, 1, STAT_DEC_TEMPORARY);
343 			if (magik(TRUE? 3 : 5))
344 				(void)dec_stat(Ind, A_CHR, 1, STAT_DEC_TEMPORARY);
345 			if (magik(TRUE? 2 : 3))
346 				(void)dec_stat(Ind, A_INT, 1, STAT_DEC_TEMPORARY);
347 		}
348 		/* Let's make this usable... - the_sandman */
349 		else if (o_ptr->name1 == ART_DWARVEN_ALE) {
350 			msg_print(Ind, "\377gYou drank the liquior of the gods");
351 			msg_format_near(Ind, "\377gYou look enviously as %s took a sip of The Ale", p_ptr->name);
352 			switch (randint(10)) {
353 			case 1:
354 			case 2:
355 			case 3:	// 3 in 10 for Hero effect
356 				set_hero(Ind, 20 + randint(10)); break;
357 			case 4:
358 			case 5:
359 			case 6:	// 3 in 10 for Speed
360 				set_fast(Ind, 20 + randint(10), 10); break;
361 			case 7:
362 			case 8:
363 			case 9: // 3 in 10 for Berserk
364 				set_shero(Ind, 20 + randint(10)); break;
365 			case 10:// 1 in 10 for confusion ;)
366 			default:
367 				if (!(p_ptr->resist_conf)) {
368 					set_confused(Ind, randint(10));
369 				} break;
370 			}
371 			p_ptr->food = PY_FOOD_FULL;	// A quaff will bring you to the norm sustenance level!
372 		} else if (magik(o_ptr->name2? 50 : 20)) {
373 			msg_format(Ind, "\377%c*HIC*", random_colour());
374 			msg_format_near(Ind, "\377%c%s hiccups!", random_colour(), p_ptr->name);
375 
376 			if (magik(o_ptr->name2? 60 : 30))
377 				set_confused(Ind, p_ptr->confused + 20 + randint(20));
378 			if (magik(o_ptr->name2? 50 : 20))
379 				set_stun(Ind, p_ptr->stun + 10 + randint(10));
380 
381 			if (magik(o_ptr->name2? 50 : 10)){
382 				set_image(Ind, p_ptr->image + 10 + randint(10));
383 				take_sanity_hit(Ind, 1, "ale");
384 			}
385 			if (magik(o_ptr->name2? 10 : 20))
386 				set_paralyzed(Ind, p_ptr->paralyzed + 10 + randint(10));
387 			if (magik(o_ptr->name2? 50 : 10))
388 				set_hero(Ind, 10 + randint(10)); /* removed stacking */
389 			if (magik(o_ptr->name2? 20 : 5))
390 				set_shero(Ind, 5 + randint(10)); /* removed stacking */
391 			if (magik(o_ptr->name2? 5 : 10))
392 				set_afraid(Ind, p_ptr->afraid + 15 + randint(10));
393 			if (magik(o_ptr->name2? 5 : 10))
394 				set_slow(Ind, p_ptr->slow + 10 + randint(10));
395 			else if (magik(o_ptr->name2? 20 : 5))
396 				set_fast(Ind, 10 + randint(10), 10); /* removed stacking */
397 			/* Methyl! */
398 			if (magik(o_ptr->name2? 0 : 3))
399 				set_blind(Ind, p_ptr->blind + 10 + randint(10));
400 			if (rand_int(100) < p_ptr->food * magik(o_ptr->name2? 40 : 60) / PY_FOOD_MAX)
401 			{
402 				msg_print(Ind, "You become nauseous and vomit!");
403 				msg_format_near(Ind, "%s vomits!", p_ptr->name);
404 				/* made salt water less deadly -APD */
405 				(void)set_food(Ind, (p_ptr->food/2));
406 				(void)set_poisoned(Ind, 0, 0);
407 				(void)set_paralyzed(Ind, p_ptr->paralyzed + 4);
408 			}
409 			if (magik(o_ptr->name2? 2 : 3))
410 				(void)dec_stat(Ind, A_DEX, 1, STAT_DEC_TEMPORARY);
411 			if (magik(o_ptr->name2? 2 : 3))
412 				(void)dec_stat(Ind, A_WIS, 1, STAT_DEC_TEMPORARY);
413 			if (magik(o_ptr->name2? 0 : 1))
414 				(void)dec_stat(Ind, A_CON, 1, STAT_DEC_TEMPORARY);
415 			//			(void)dec_stat(Ind, A_STR, 1, STAT_DEC_TEMPORARY);
416 			if (magik(o_ptr->name2? 3 : 5))
417 				(void)dec_stat(Ind, A_CHR, 1, STAT_DEC_TEMPORARY);
418 			if (magik(o_ptr->name2? 2 : 3))
419 				(void)dec_stat(Ind, A_INT, 1, STAT_DEC_TEMPORARY);
420 		}
421 		else msg_print(Ind, "That tastes good.");
422 	    } else {
423 		msg_print(Ind, "That tastes fair but has no effect.");
424 	    }
425 		if (o_ptr && o_ptr->name1 == ART_DWARVEN_ALE) *keep = TRUE;
426 
427 		ident = TRUE;
428 		break;
429 
430 	case SV_FOOD_UNMAGIC:
431 		ident = unmagic(Ind);
432 		break;
433 	}
434 
435 	return ident;
436 }
437 
438 /*
439  * Eat some food (from the pack or floor)
440  */
do_cmd_eat_food(int Ind,int item)441 void do_cmd_eat_food(int Ind, int item) {
442 	player_type *p_ptr = Players[Ind];
443 
444 	int			ident, lev;
445 
446 	object_type		*o_ptr;
447 	bool keep = FALSE, flipped = FALSE;
448 
449 
450 	/* Restrict choices to food */
451 	item_tester_tval = TV_FOOD;
452 
453 	/* Get the item (in the pack) */
454 	if (item >= 0) o_ptr = &p_ptr->inventory[item];
455 	/* Get the item (on the floor) */
456 	else {
457 		if (-item >= o_max) return; /* item doesn't exist */
458 		o_ptr = &o_list[0 - item];
459 	}
460 
461 	if (check_guard_inscription( o_ptr->note, 'E' )) {
462 		msg_print(Ind, "The item's inscription prevents it.");
463 		return;
464 	}
465 
466 	if (!can_use_verbose(Ind, o_ptr)) return;
467 
468 
469 	if (o_ptr->tval != TV_FOOD && o_ptr->tval != TV_FIRESTONE) {
470 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to eat non-food!");
471 		return;
472 	}
473 
474 	if (p_ptr->prace == RACE_ENT && !p_ptr->body_monster) {
475 		/* Let them drink :) */
476 		if (o_ptr->tval != TV_FOOD ||
477 		    (o_ptr->sval != SV_FOOD_PINT_OF_ALE &&
478 		    o_ptr->sval != SV_FOOD_PINT_OF_WINE)) {
479 			msg_print(Ind, "You cannot eat food.");
480 			return;
481 		}
482 	}
483 
484 	/* Let the player stay afk while eating,
485 	   since we assume he's resting ;) - C. Blue */
486 /*	un_afk_idle(Ind); */
487 
488 	/* Take a turn */
489 	p_ptr->energy -= level_speed(&p_ptr->wpos);
490 
491 #ifdef USE_SOUND_2010
492 	sound(Ind, "eat", NULL, SFX_TYPE_COMMAND, FALSE);
493 #endif
494 
495 	/* Identity not known yet */
496 	ident = FALSE;
497 
498 	/* Object level */
499 	lev = k_info[o_ptr->k_idx].level;
500 
501 	/* (not quite) Normal foods */
502 	if (o_ptr->tval == TV_FOOD)
503 		ident = eat_food(Ind, o_ptr->sval, o_ptr, &keep);
504 	/* Firestones */
505 	else if (o_ptr->tval == TV_FIRESTONE) {
506 		bool dragon = FALSE;
507 		if (p_ptr->body_monster) {
508 			monster_race *r_ptr = &r_info[p_ptr->body_monster];
509 			if (strchr("dD", r_ptr->d_char)) dragon = TRUE;
510 		}
511 		if (p_ptr->prace == RACE_DRACONIAN) {
512 			switch (o_ptr->sval) {
513 			case SV_FIRE_SMALL:
514 				msg_print(Ind, "Grrrmfff ...");
515 				do_tank(Ind, 10);
516 				ident = TRUE;
517 				break;
518 
519 			case SV_FIRESTONE:
520 				msg_print(Ind, "Grrrrmmmmmmfffffff ...");
521 				do_tank(Ind, 25);
522 				do_tank(Ind, 25);	// twice
523 				ident = TRUE;
524 				break;
525 			}
526 		}
527 		else if (!dragon) msg_print(Ind, "Yikes, you cannot eat this, you vomit!");
528 		else {
529 			msg_print(Ind, "That tastes weird..");
530 			switch (o_ptr->sval) {
531 			case SV_FIRE_SMALL:
532 				if (p_ptr->csp < p_ptr->msp) {
533 					p_ptr->csp += 30;
534 					if (p_ptr->csp > p_ptr->msp) p_ptr->csp = p_ptr->msp;
535 					msg_print(Ind, "You feel your head clearing.");
536 					p_ptr->redraw |= (PR_MANA);
537 					p_ptr->window |= (PW_PLAYER);
538 					ident = TRUE;
539 				}
540 				break;
541 
542 			case SV_FIRESTONE:
543 				if (p_ptr->csp < p_ptr->msp) {
544 					p_ptr->csp += 100;
545 					if (p_ptr->csp > p_ptr->msp) p_ptr->csp = p_ptr->msp;
546 					msg_print(Ind, "You feel your head clearing.");
547 					p_ptr->redraw |= (PR_MANA);
548 					p_ptr->window |= (PW_PLAYER);
549 					ident = TRUE;
550 				}
551 				break;
552 			}
553 		}
554 	}
555 
556 
557 	/* Combine / Reorder the pack (later) */
558 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
559 
560 	/* The player is now aware of the object */
561 	if (ident && !object_aware_p(Ind, o_ptr)) {
562 		flipped = object_aware(Ind, o_ptr);
563 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
564 	}
565 
566 	/* We have tried it */
567 	object_tried(Ind, o_ptr, flipped);
568 
569 	/* Window stuff */
570 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
571 
572 
573 	/* Food can feed the player */
574 	if (!p_ptr->suscep_life)
575 		(void)set_food(Ind, p_ptr->food + o_ptr->pval);
576 	else if (p_ptr->prace != RACE_VAMPIRE)
577 		(void)set_food(Ind, p_ptr->food + o_ptr->pval / 3);
578 
579 
580 	/* Hack -- really allow certain foods to be "preserved" */
581 	if (keep) return;
582 
583 
584 	/* Destroy a food in the pack */
585 	if (item >= 0) {
586 		inven_item_increase(Ind, item, -1);
587 		inven_item_describe(Ind, item);
588 		inven_item_optimize(Ind, item);
589 	}
590 	/* Destroy a food on the floor */
591 	else {
592 		floor_item_increase(0 - item, -1);
593 		floor_item_describe(0 - item);
594 		floor_item_optimize(0 - item);
595 	}
596 }
597 
598 
599 
quaff_potion(int Ind,int tval,int sval,int pval)600 bool quaff_potion(int Ind, int tval, int sval, int pval) {
601 	player_type *p_ptr = Players[Ind];
602 	int ident = FALSE;
603 	int i;
604 
605 	bypass_invuln = TRUE;
606 
607 	/* Analyze the potion */
608 	if (tval == TV_POTION) {
609 
610 		switch (sval) {
611 		case SV_POTION_WATER:
612 		case SV_POTION_APPLE_JUICE:
613 		case SV_POTION_SLIME_MOLD:
614 			if (!p_ptr->suscep_life) msg_print(Ind, "You feel less thirsty.");
615 			ident = TRUE;
616 			break;
617 		case SV_POTION_SLOWNESS:
618 			if (set_slow(Ind, p_ptr->slow + randint(25) + 15)) ident = TRUE;
619 			break;
620 		case SV_POTION_SALT_WATER:
621 			if (!p_ptr->suscep_life && p_ptr->prace != RACE_ENT) {
622 				msg_print(Ind, "The salty potion makes you vomit!");
623 				msg_format_near(Ind, "%s vomits!", p_ptr->name);
624 				/* made salt water less deadly -APD */
625 				(void)set_food(Ind, (p_ptr->food / 2) - 400);
626 				(void)set_poisoned(Ind, 0, 0);
627 				(void)set_paralyzed(Ind, p_ptr->paralyzed + 4);
628 			} else {
629 				msg_print(Ind, "That potion tastes awfully salty.");
630 			}
631 			ident = TRUE;
632 			break;
633 		case SV_POTION_POISON:
634 			if (!(p_ptr->resist_pois || p_ptr->oppose_pois)) {
635 				if (set_poisoned(Ind, p_ptr->poisoned + rand_int(15) + 10, 0)) {
636 					ident = TRUE;
637 				}
638 			}
639 			break;
640 		case SV_POTION_BLINDNESS:
641 			if (!p_ptr->resist_blind) {
642 				if (set_blind(Ind, p_ptr->blind + rand_int(100) + 100)) ident = TRUE;
643 			}
644 			break;
645 		case SV_POTION_CONFUSION:
646 			if (!p_ptr->resist_conf) {
647 				if (set_confused(Ind, p_ptr->confused + rand_int(20) + 15)) ident = TRUE;
648 			}
649 			break;
650 #if 0
651 		case SV_POTION_MUTATION:
652 			ident = TRUE;
653 			break;
654 #endif
655 		case SV_POTION_SLEEP:
656 			if (!p_ptr->free_act) {
657 				if (set_paralyzed(Ind, p_ptr->paralyzed + rand_int(4) + 4)) ident = TRUE;
658 			}
659 			break;
660 		case SV_POTION_LOSE_MEMORIES:
661 			if (!p_ptr->hold_life && (p_ptr->exp > 0)) {
662 				if (p_ptr->lev == 99) msg_print(Ind, "You are unaffected!");
663 				else {
664 					msg_print(Ind, "\377GYou feel your memories fade.");
665 					lose_exp(Ind, p_ptr->exp / 4);
666 					ident = TRUE;
667 				}
668 			}
669 			break;
670 		case SV_POTION_RUINATION:
671 			msg_print(Ind, "Your nerves and muscles feel weak and lifeless!");
672 			take_hit(Ind, damroll(10, 10), "a Potion of Ruination", 0);
673 			(void)dec_stat(Ind, A_DEX, 25, STAT_DEC_NORMAL);
674 			(void)dec_stat(Ind, A_WIS, 25, STAT_DEC_NORMAL);
675 			(void)dec_stat(Ind, A_CON, 25, STAT_DEC_NORMAL);
676 			(void)dec_stat(Ind, A_STR, 25, STAT_DEC_NORMAL);
677 			(void)dec_stat(Ind, A_CHR, 25, STAT_DEC_NORMAL);
678 			(void)dec_stat(Ind, A_INT, 25, STAT_DEC_NORMAL);
679 			ident = TRUE;
680 			break;
681 		case SV_POTION_DEC_STR:
682 			if (do_dec_stat(Ind, A_STR, STAT_DEC_NORMAL)) ident = TRUE;
683 			break;
684 		case SV_POTION_DEC_INT:
685 			if (do_dec_stat(Ind, A_INT, STAT_DEC_NORMAL)) ident = TRUE;
686 			break;
687 		case SV_POTION_DEC_WIS:
688 			if (do_dec_stat(Ind, A_WIS, STAT_DEC_NORMAL)) ident = TRUE;
689 			break;
690 		case SV_POTION_DEC_DEX:
691 			if (do_dec_stat(Ind, A_DEX, STAT_DEC_NORMAL)) ident = TRUE;
692 			break;
693 		case SV_POTION_DEC_CON:
694 			if (do_dec_stat(Ind, A_CON, STAT_DEC_NORMAL)) ident = TRUE;
695 			break;
696 		case SV_POTION_DEC_CHR:
697 			if (do_dec_stat(Ind, A_CHR, STAT_DEC_NORMAL)) ident = TRUE;
698 			break;
699 		case SV_POTION_DETONATIONS:
700 #ifdef USE_SOUND_2010
701 			sound(Ind, "detonation", NULL, SFX_TYPE_MISC, TRUE);
702 #endif
703 			msg_print(Ind, "Massive explosions rupture your body!");
704 			msg_format_near(Ind, "%s blows up!", p_ptr->name);
705 			take_hit(Ind, damroll(50, 20), "a Potion of Detonation", 0);
706 			(void)set_stun(Ind, p_ptr->stun + 75);
707 			(void)set_cut(Ind, p_ptr->cut + 5000, Ind);
708 			ident = TRUE;
709 			break;
710 		case SV_POTION_DEATH:
711 			if (!p_ptr->suscep_life) {
712 				msg_print(Ind, "A feeling of Death flows through your body.");
713 				take_hit(Ind, 5000, "a Potion of Death", 0);
714 				ident = TRUE;
715 			} else {
716 				msg_print(Ind, "You burp.");
717 				msg_format_near(Ind, "%s burps.", p_ptr->name);
718 				if (p_ptr->cst < p_ptr->mst && !p_ptr->shadow_running) {
719 					msg_print(Ind, "You feel refreshed.");
720 					p_ptr->cst = p_ptr->mst;
721 					p_ptr->cst_frac = 0;
722 					p_ptr->redraw |= PR_STAMINA;
723 				}
724 			}
725 			break;
726 		case SV_POTION_INFRAVISION:
727 			if (set_tim_infra(Ind, 100 + randint(100))) /* removed stacking */
728 				ident = TRUE;
729 			break;
730 		case SV_POTION_DETECT_INVIS:
731 			if (set_tim_invis(Ind, 12 + randint(12))) /* removed stacking */
732 				ident = TRUE;
733 			break;
734 		case SV_POTION_INVIS:
735 			set_invis(Ind, 15 + randint(10), p_ptr->lev < 30 ? 24 : p_ptr->lev * 4 / 5);
736 			ident = TRUE;
737 		case SV_POTION_SLOW_POISON:
738 #if 0
739 			if (set_poisoned(Ind, p_ptr->poisoned / 2, p_ptr->poisoned_attacker)) ident = TRUE;
740 #else /* back to traditional way */
741 			if (p_ptr->poisoned && !p_ptr->slow_poison) {
742 				p_ptr->slow_poison = 1;
743 				ident = TRUE;
744 			}
745 #endif
746 			break;
747 		case SV_POTION_CURE_POISON:
748 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
749 			break;
750 		case SV_POTION_BOLDNESS:
751 			/* Stay bold for some turns */
752 			if (set_afraid(Ind, 0)) ident = TRUE;
753 			set_res_fear(Ind, 5);
754 			break;
755 		case SV_POTION_SPEED:
756 			if (!p_ptr->fast) {
757 				if (set_fast(Ind, randint(25) + 15, 10)) ident = TRUE;
758 			} else {
759 				/* not removed stacking due to interesting effect */
760 				(void)set_fast(Ind, p_ptr->fast + 5, 10);
761 			}
762 			break;
763 		case SV_POTION_RESIST_HEAT:
764 			if (set_oppose_fire(Ind, randint(10) + 10)) /* removed stacking */
765 				ident = TRUE;
766 			break;
767 		case SV_POTION_RESIST_COLD:
768 			if (set_oppose_cold(Ind, randint(10) + 10)) /* removed stacking */
769 				ident = TRUE;
770 			break;
771 		case SV_POTION_HEROISM:
772 			if (hp_player(Ind, 10)) ident = TRUE;
773 			if (set_afraid(Ind, 0)) ident = TRUE;
774 			if (set_hero(Ind, randint(25) + 25)) ident = TRUE; /* removed stacking */
775 			break;
776 		case SV_POTION_BERSERK_STRENGTH:
777 			if (hp_player(Ind, 30)) ident = TRUE;
778 			if (set_afraid(Ind, 0)) ident = TRUE;
779 			if (set_shero(Ind, randint(25) + 25)) ident = TRUE; /* removed stacking */
780 			break;
781 		case SV_POTION_CURE_LIGHT:
782 			if (hp_player(Ind, damroll(3, 8))) ident = TRUE;
783 			if (set_blind(Ind, 0)) ident = TRUE;
784 			if (set_cut(Ind, p_ptr->cut - 10, p_ptr->cut_attacker)) ident = TRUE;
785 			break;
786 		case SV_POTION_CURE_SERIOUS:
787 			if (hp_player(Ind, damroll(6, 8))) ident = TRUE;
788 			if (set_blind(Ind, 0)) ident = TRUE;
789 			if (set_confused(Ind, 0)) ident = TRUE;
790 			if (set_cut(Ind, (p_ptr->cut / 2) - 50, p_ptr->cut_attacker)) ident = TRUE;
791 			break;
792 		case SV_POTION_CURE_CRITICAL:
793 			if (hp_player(Ind, damroll(14, 8))) ident = TRUE;
794 			if (set_blind(Ind, 0)) ident = TRUE;
795 			if (set_confused(Ind, 0)) ident = TRUE;
796 			//			if (set_poisoned(Ind, 0, 0)) ident = TRUE;	/* use specialized pots */
797 			if (set_stun(Ind, 0)) ident = TRUE;
798 			if (set_cut(Ind, 0, 0)) ident = TRUE;
799 			break;
800 		case SV_POTION_HEALING:
801 			if (hp_player(Ind, 300)) ident = TRUE;
802 			if (set_blind(Ind, 0)) ident = TRUE;
803 			if (set_confused(Ind, 0)) ident = TRUE;
804 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
805 			if (set_stun(Ind, 0)) ident = TRUE;
806 			if (set_cut(Ind, 0, 0)) ident = TRUE;
807 			break;
808 		case SV_POTION_STAR_HEALING:
809 			if (hp_player(Ind, 700)) ident = TRUE;
810 			if (set_blind(Ind, 0)) ident = TRUE;
811 			if (set_confused(Ind, 0)) ident = TRUE;
812 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
813 			if (set_stun(Ind, 0)) ident = TRUE;
814 			if (set_cut(Ind, 0, 0)) ident = TRUE;
815 			break;
816 		case SV_POTION_LIFE:
817 			msg_print(Ind, "\377GYou feel life flow through your body!");
818 			restore_level(Ind);
819 			if (p_ptr->suscep_life) take_hit(Ind, 500, "a Potion of Life", 0);
820 			else hp_player(Ind, 700);
821 			(void)set_poisoned(Ind, 0, 0);
822 			(void)set_blind(Ind, 0);
823 			(void)set_confused(Ind, 0);
824 			(void)set_image(Ind, 0);
825 			(void)set_stun(Ind, 0);
826 			(void)set_cut(Ind, 0, 0);
827 			(void)do_res_stat(Ind, A_STR);
828 			(void)do_res_stat(Ind, A_CON);
829 			(void)do_res_stat(Ind, A_DEX);
830 			(void)do_res_stat(Ind, A_WIS);
831 			(void)do_res_stat(Ind, A_INT);
832 			(void)do_res_stat(Ind, A_CHR);
833 			(void)restore_level(Ind);
834 			if (p_ptr->black_breath) {
835 				p_ptr->black_breath = FALSE;
836 				msg_print(Ind, "The hold of the Black Breath on you is broken!");
837 			}
838 			if (!p_ptr->suscep_life &&
839 			    p_ptr->cst < p_ptr->mst && !p_ptr->shadow_running) {
840 				msg_print(Ind, "You feel refreshed.");
841 				p_ptr->cst = p_ptr->mst;
842 				p_ptr->cst_frac = 0;
843 				p_ptr->redraw |= PR_STAMINA;
844 			}
845 			ident = TRUE;
846 			break;
847 		case SV_POTION_RESTORE_MANA:
848 			if (p_ptr->csp < p_ptr->msp) {
849 				p_ptr->csp += 500;
850 				if (p_ptr->csp > p_ptr->msp) p_ptr->csp = p_ptr->msp;
851 				msg_print(Ind, "You feel your head clearing.");
852 				p_ptr->redraw |= (PR_MANA);
853 				p_ptr->window |= (PW_PLAYER);
854 				ident = TRUE;
855 			}
856 			break;
857 		case SV_POTION_STAR_RESTORE_MANA:
858 			if (p_ptr->csp < p_ptr->msp) {
859 				p_ptr->csp += 1000;
860 				if (p_ptr->csp > p_ptr->msp) p_ptr->csp = p_ptr->msp;
861 				msg_print(Ind, "You feel your head clearing!");
862 				p_ptr->redraw |= (PR_MANA);
863 				p_ptr->window |= (PW_PLAYER);
864 				ident = TRUE;
865 			}
866 			break;
867 		case SV_POTION_RESTORE_EXP:
868 			if (restore_level(Ind)) ident = TRUE;
869 			break;
870 		case SV_POTION_RES_STR:
871 			if (do_res_stat(Ind, A_STR)) ident = TRUE;
872 			break;
873 		case SV_POTION_RES_INT:
874 			if (do_res_stat(Ind, A_INT)) ident = TRUE;
875 			break;
876 		case SV_POTION_RES_WIS:
877 			if (do_res_stat(Ind, A_WIS)) ident = TRUE;
878 			break;
879 		case SV_POTION_RES_DEX:
880 			if (do_res_stat(Ind, A_DEX)) ident = TRUE;
881 			break;
882 		case SV_POTION_RES_CON:
883 			if (do_res_stat(Ind, A_CON)) ident = TRUE;
884 			break;
885 		case SV_POTION_RES_CHR:
886 			if (do_res_stat(Ind, A_CHR)) ident = TRUE;
887 			break;
888 		case SV_POTION_INC_STR:
889 			if (do_inc_stat(Ind, A_STR)) ident = TRUE;
890 			break;
891 		case SV_POTION_INC_INT:
892 			if (do_inc_stat(Ind, A_INT)) ident = TRUE;
893 			break;
894 		case SV_POTION_INC_WIS:
895 			if (do_inc_stat(Ind, A_WIS)) ident = TRUE;
896 			break;
897 		case SV_POTION_INC_DEX:
898 			if (do_inc_stat(Ind, A_DEX)) ident = TRUE;
899 			break;
900 		case SV_POTION_INC_CON:
901 			if (do_inc_stat(Ind, A_CON)) ident = TRUE;
902 			break;
903 		case SV_POTION_INC_CHR:
904 			if (do_inc_stat(Ind, A_CHR)) ident = TRUE;
905 			break;
906 		case SV_POTION_AUGMENTATION:
907 			if (do_inc_stat(Ind, A_STR)) ident = TRUE;
908 			if (do_inc_stat(Ind, A_INT)) ident = TRUE;
909 			if (do_inc_stat(Ind, A_WIS)) ident = TRUE;
910 			if (do_inc_stat(Ind, A_DEX)) ident = TRUE;
911 			if (do_inc_stat(Ind, A_CON)) ident = TRUE;
912 			if (do_inc_stat(Ind, A_CHR)) ident = TRUE;
913 			break;
914 		case SV_POTION_ENLIGHTENMENT:
915 			identify_pack(Ind);
916 			msg_print(Ind, "An image of your surroundings forms in your mind...");
917 			wiz_lite(Ind);
918 			ident = TRUE;
919 			break;
920 		case SV_POTION_STAR_ENLIGHTENMENT:
921 #if 0 /* would need to increase price from 25k back to 80k ;) */
922 			for (i = 0; i < INVEN_TOTAL; i++)
923 				identify_fully_item_quiet(Ind, i);
924 #else
925 			identify_pack(Ind);
926 #endif
927 			msg_print(Ind, "You begin to feel more enlightened...");
928 			msg_print(Ind, NULL);
929 			wiz_lite(Ind);
930 			(void)do_inc_stat(Ind, A_INT);
931 			(void)do_inc_stat(Ind, A_WIS);
932 			(void)detect_treasure(Ind, DEFAULT_RADIUS * 2);
933 			(void)detect_object(Ind, DEFAULT_RADIUS * 2);
934 			(void)detect_sdoor(Ind, DEFAULT_RADIUS * 2);
935 			(void)detect_trap(Ind, DEFAULT_RADIUS * 2);
936 			identify_pack(Ind);
937 			self_knowledge(Ind);
938 			ident = TRUE;
939 			break;
940 		case SV_POTION_SELF_KNOWLEDGE:
941 			msg_print(Ind, "You begin to know yourself a little better...");
942 			msg_print(Ind, NULL);
943 			self_knowledge(Ind);
944 			ident = TRUE;
945 			break;
946 		case SV_POTION_EXPERIENCE:
947 			if (p_ptr->exp < PY_MAX_EXP) {
948 				s32b ee = (p_ptr->exp / 2) + 10;
949 				if (ee > 100000L) ee = 100000L;
950 #ifdef ALT_EXPRATIO
951 				ee = (ee * (s64b)p_ptr->expfact) / 100L; /* give same amount to anyone */
952 #endif
953 				if (!(p_ptr->mode & MODE_PVP)) {
954 					msg_print(Ind, "\377GYou feel more experienced.");
955 					gain_exp(Ind, ee);
956 				}
957 				ident = TRUE;
958 			}
959 			break;
960 			/* additions from PernA */
961 		case SV_POTION_CURING:
962 			if (hp_player(Ind, 50)) ident = TRUE;
963 			if (set_blind(Ind, 0)) ident = TRUE;
964 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
965 			if (set_confused(Ind, 0)) ident = TRUE;
966 			if (set_stun(Ind, 0)) ident = TRUE;
967 			if (set_cut(Ind, 0, 0)) ident = TRUE;
968 			if (set_image(Ind, 0)) ident = TRUE;
969 			if (heal_insanity(Ind, 40)) ident = TRUE;
970 			if (p_ptr->food >= PY_FOOD_MAX)
971 				if (set_food(Ind, PY_FOOD_MAX - 1 - pval)) ident = TRUE;
972 			if (do_res_stat(Ind, A_STR)) ident = TRUE;
973 			if (do_res_stat(Ind, A_CON)) ident = TRUE;
974 			if (do_res_stat(Ind, A_DEX)) ident = TRUE;
975 			if (do_res_stat(Ind, A_WIS)) ident = TRUE;
976 			if (do_res_stat(Ind, A_INT)) ident = TRUE;
977 			if (do_res_stat(Ind, A_CHR)) ident = TRUE;
978 			break;
979 		case SV_POTION_INVULNERABILITY:
980 			ident = set_invuln(Ind, randint(7) + 7); /* removed stacking */
981 			break;
982 		case SV_POTION_RESISTANCE:
983 			ident =
984 				set_oppose_acid(Ind, randint(20) + 20) |
985 				set_oppose_elec(Ind, randint(20) + 20) |
986 				set_oppose_fire(Ind, randint(20) + 20) |
987 				set_oppose_cold(Ind, randint(20) + 20) |
988 				set_oppose_pois(Ind, randint(20) + 20); /* removed stacking */
989 			break;
990 #ifdef EXPAND_TV_POTION
991 		//max sanity of a player can go up to around 900 later!
992 		case SV_POTION_CURE_LIGHT_SANITY:
993 			if (heal_insanity(Ind, damroll(4,8))) ident = TRUE;
994 			(void)set_image(Ind, 0);
995 			break;
996 		case SV_POTION_CURE_SERIOUS_SANITY:
997 //			if (heal_insanity(Ind, damroll(6,13))) ident = TRUE;
998 			if (heal_insanity(Ind, damroll(8,12))) ident = TRUE;
999 			(void)set_image(Ind, 0);
1000 			break;
1001 		case SV_POTION_CURE_CRITICAL_SANITY:
1002 //			if (heal_insanity(Ind, damroll(9,20))) ident = TRUE;
1003 			if (heal_insanity(Ind, damroll(16,18))) ident = TRUE;
1004 			(void)set_image(Ind, 0);
1005 			break;
1006 		case SV_POTION_CURE_SANITY:
1007 //			if (heal_insanity(Ind, damroll(14,32))) ident = TRUE;
1008 			if (heal_insanity(Ind, damroll(32,27))) ident = TRUE;
1009 			(void)set_image(Ind, 0);
1010 			break;
1011 		case SV_POTION_CHAUVE_SOURIS:
1012 //			apply_morph(Ind, 100, "Potion of Chauve-Souris");
1013 			if (!p_ptr->fruit_bat) {
1014 				/* FRUIT BAT!!!!!! */
1015 				if (p_ptr->body_monster) do_mimic_change(Ind, 0, TRUE);
1016 				msg_print(Ind, "You have been turned into a fruit bat!");
1017 				strcpy(p_ptr->died_from,"a Potion of Chauve-Souris");
1018 				strcpy(p_ptr->really_died_from,"a Potion of Chauve-Souris");
1019 				p_ptr->fruit_bat = -1;
1020 				p_ptr->deathblow = 0;
1021 				player_death(Ind);
1022 				ident = TRUE;
1023 			} else if(p_ptr->fruit_bat == 2) {
1024 				msg_print(Ind, "You have been restored!");
1025 				p_ptr->fruit_bat = 0;
1026 				p_ptr->update |= (PU_BONUS | PU_HP);
1027 				ident = TRUE;
1028 			}
1029 			else msg_print(Ind, "You feel certain you are a fruit bat!");
1030 			break;
1031 		case SV_POTION_LEARNING:
1032 			ident = TRUE;
1033 			/* gain skill points */
1034 			i = 1 + rand_int(3);
1035 			p_ptr->skill_points += i;
1036 			p_ptr->update |= PU_SKILL_MOD;
1037 			if (is_older_than(&p_ptr->version, 4, 4, 8, 5, 0, 0)) p_ptr->redraw |= PR_STUDY;
1038 			msg_format(Ind, "You gained %d more skill point%s.", i, (i == 1)?"":"s");
1039 			break;
1040 #endif
1041 		}
1042 	} else { /* POTION2 */
1043 		switch (sval) {
1044 		//max sanity of a player can go up to around 900 later!
1045 		case SV_POTION2_CURE_LIGHT_SANITY:
1046 			if (heal_insanity(Ind, damroll(4,8))) ident = TRUE;
1047 			(void)set_image(Ind, 0);
1048 			break;
1049 		case SV_POTION2_CURE_SERIOUS_SANITY:
1050 //			if (heal_insanity(Ind, damroll(6,13))) ident = TRUE;
1051 			if (heal_insanity(Ind, damroll(8,12))) ident = TRUE;
1052 			(void)set_image(Ind, 0);
1053 			break;
1054 		case SV_POTION2_CURE_CRITICAL_SANITY:
1055 //			if (heal_insanity(Ind, damroll(9,20))) ident = TRUE;
1056 			if (heal_insanity(Ind, damroll(16,18))) ident = TRUE;
1057 			(void)set_image(Ind, 0);
1058 			break;
1059 		case SV_POTION2_CURE_SANITY:
1060 //			if (heal_insanity(Ind, damroll(14,32))) ident = TRUE;
1061 			if (heal_insanity(Ind, damroll(32,27))) ident = TRUE;
1062 			(void)set_image(Ind, 0);
1063 			break;
1064 		case SV_POTION2_CHAUVE_SOURIS:
1065 //			apply_morph(Ind, 100, "Potion of Chauve-Souris");
1066 			if (!p_ptr->fruit_bat) {
1067 				/* FRUIT BAT!!!!!! */
1068 				if (p_ptr->body_monster) do_mimic_change(Ind, 0, TRUE);
1069 				msg_print(Ind, "You have been turned into a fruit bat!");
1070 				strcpy(p_ptr->died_from,"a Potion of Chauve-Souris");
1071 				strcpy(p_ptr->really_died_from,"a Potion of Chauve-Souris");
1072 				p_ptr->fruit_bat = -1;
1073 				p_ptr->deathblow = 0;
1074 				player_death(Ind);
1075 				ident = TRUE;
1076 			} else if(p_ptr->fruit_bat == 2) {
1077 				msg_print(Ind, "You have been restored!");
1078 				p_ptr->fruit_bat = 0;
1079 				p_ptr->update |= (PU_BONUS | PU_HP);
1080 				ident = TRUE;
1081 			}
1082 			else msg_print(Ind, "You feel certain you are a fruit bat!");
1083 
1084 			break;
1085 		case SV_POTION2_LEARNING:
1086 			ident = TRUE;
1087 			/* gain skill points */
1088 			i = 1 + rand_int(3);
1089 			p_ptr->skill_points += i;
1090 			p_ptr->update |= PU_SKILL_MOD;
1091 			if (is_older_than(&p_ptr->version, 4, 4, 8, 5, 0, 0)) p_ptr->redraw |= PR_STUDY;
1092 			msg_format(Ind, "You gained %d more skill point%s.", i, (i == 1)?"":"s");
1093 			break;
1094 		case SV_POTION2_AMBER:
1095 			ident = TRUE;
1096 			msg_print(Ind, "Your muscles bulge, and your skin turns to amber!");
1097 			do_xtra_stats(Ind, 20, 20);
1098 			set_shero(Ind, 20); /* -AC cancelled by blessing below */
1099 			p_ptr->blessed_power = 35;
1100 			set_blessed(Ind, 20);
1101 			break;
1102 		}
1103 	}
1104 
1105 	bypass_invuln = FALSE;
1106 	return (ident);
1107 }
1108 
1109 /*
1110  * Quaff a potion (from the pack or the floor)
1111  */
do_cmd_quaff_potion(int Ind,int item)1112 void do_cmd_quaff_potion(int Ind, int item) {
1113 	player_type *p_ptr = Players[Ind];
1114 	int		ident, lev;
1115 	object_type	*o_ptr;
1116 	bool flipped = FALSE;
1117 
1118 
1119 	/* Restrict choices to potions (apparently meanless) */
1120 	item_tester_tval = TV_POTION;
1121 
1122 	/* Get the item (in the pack) */
1123 	if (item >= 0)
1124 		o_ptr = &p_ptr->inventory[item];
1125 
1126 	/* Get the item (on the floor) */
1127 	else {
1128 		if (-item >= o_max)
1129 			return; /* item doesn't exist */
1130 
1131 		o_ptr = &o_list[0 - item];
1132 	}
1133 
1134 	/* Hack -- allow to quaff ale/wine */
1135 	if (o_ptr->tval == TV_FOOD) {
1136 		do_cmd_eat_food(Ind, item);
1137 		return;
1138 	}
1139 
1140 
1141         if (check_guard_inscription(o_ptr->note, 'q')) {
1142                 msg_print(Ind, "The item's inscription prevents it.");
1143                 return;
1144         };
1145 
1146         if (!can_use_verbose(Ind, o_ptr)) return;
1147 
1148 
1149 	if ((o_ptr->tval != TV_POTION) &&
1150 		(o_ptr->tval != TV_POTION2))
1151 	{
1152 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to quaff non-potion!");
1153 		return;
1154 	}
1155 
1156 	/* S(he) is no longer afk */
1157 	un_afk_idle(Ind);
1158 
1159 	/* Take a turn */
1160 	p_ptr->energy -= level_speed(&p_ptr->wpos);
1161 
1162 	/* Not identified yet */
1163 	ident = FALSE;
1164 
1165 	/* Object level */
1166 	lev = k_info[o_ptr->k_idx].level;
1167 
1168 	process_hooks(HOOK_QUAFF, "d", Ind);
1169 
1170 	ident = quaff_potion(Ind, o_ptr->tval, o_ptr->sval, o_ptr->pval);
1171 
1172 	/* Combine / Reorder the pack (later) */
1173 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1174 
1175 	/* An identification was made */
1176 	if (ident && !object_aware_p(Ind, o_ptr)) {
1177 		flipped = object_aware(Ind, o_ptr);
1178 //		object_known(o_ptr);//only for object1.c artifact potion description... maybe obsolete
1179 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
1180 	}
1181 
1182 	/* The item has been tried */
1183 	object_tried(Ind, o_ptr, flipped);
1184 
1185 	/* Window stuff */
1186 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1187 
1188 
1189 	/* Potions can feed the player */
1190 	if (p_ptr->prace == RACE_VAMPIRE) {
1191 		if (o_ptr->sval == SV_POTION_BLOOD) {
1192 			int feed = o_ptr->pval + p_ptr->food;
1193 			/* never get gorged */
1194 			if (feed >= PY_FOOD_MAX) feed = PY_FOOD_MAX - 1;
1195 			set_food(Ind, feed);
1196 		}
1197 	} else if (p_ptr->prace == RACE_ENT) {
1198 		if (o_ptr->sval == SV_POTION_WATER) (void)set_food(Ind, p_ptr->food + WATER_ENT_FOOD);
1199 		else (void)set_food(Ind, p_ptr->food + (o_ptr->pval * 2));
1200 	} else if (p_ptr->suscep_life) {
1201 		(void)set_food(Ind, p_ptr->food + (o_ptr->pval * 2) / 3);
1202 	} else
1203 		(void)set_food(Ind, p_ptr->food + o_ptr->pval);
1204 
1205 	if (true_artifact_p(o_ptr)) handle_art_d(o_ptr->name1);
1206 	questitem_d(o_ptr, 1);
1207 
1208 	/* Destroy a potion in the pack */
1209 	if (item >= 0) {
1210 		inven_item_increase(Ind, item, -1);
1211 		inven_item_describe(Ind, item);
1212 		inven_item_optimize(Ind, item);
1213 	}
1214 
1215 	/* Destroy a potion on the floor */
1216 	else {
1217 		floor_item_increase(0 - item, -1);
1218 		floor_item_describe(0 - item);
1219 		floor_item_optimize(0 - item);
1220 	}
1221 
1222 #ifdef USE_SOUND_2010
1223 	sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1224 #endif
1225 }
1226 
1227 #ifdef FOUNTAIN_GUARDS
fountain_guard(int Ind,bool blood)1228 static void fountain_guard(int Ind, bool blood) {
1229 	player_type *p_ptr = Players[Ind];
1230 	int ridx = 0;
1231 
1232 	if (!magik(FOUNTAIN_GUARDS)) return;
1233 
1234 	if (blood) {
1235 		if (getlevel(&p_ptr->wpos) >= 60) { switch (randint(3)) { case 1: ridx = 758; break; case 2: ridx = 994; break; case 3: ridx = 812; }
1236 		} else if (getlevel(&p_ptr->wpos) >= 50) { switch (randint(3)) { case 1: ridx = 662; break; case 2: ridx = 569; case 3: ridx = 659; }
1237 		} else { switch (randint(3)) { case 1: ridx = 566; break; break; case 2: ridx = 357; break; case 3: ridx = 568; }
1238 		}
1239 	} else {
1240 		if (getlevel(&p_ptr->wpos) >= 40) { switch (randint(2)) { case 1: ridx = 924; break; case 2: ridx = 893; }
1241 		} else if (getlevel(&p_ptr->wpos) >= 35) { switch (randint(3)) { case 1: ridx = 1038; break; case 2: ridx = 894; break; case 3: ridx = 902; }
1242 		} else if (getlevel(&p_ptr->wpos) >= 30) { switch (randint(2)) { case 1: ridx = 512; break; case 2: ridx = 509; }
1243 		} else if (getlevel(&p_ptr->wpos) >= 25) { ridx = 443;
1244 		} else if (getlevel(&p_ptr->wpos) >= 20) { switch (randint(4)) { case 1: ridx = 919; break; case 2: ridx = 882; break; case 3: ridx = 927; break; case 4: ridx = 1057; }
1245 		} else if (getlevel(&p_ptr->wpos) >= 15) { switch (randint(3)) { case 1: ridx = 303; break; case 2: ridx = 923; break; case 3: ridx = 926; }
1246 		} else if (getlevel(&p_ptr->wpos) >= 10) { ridx = 925;
1247 		} else if (getlevel(&p_ptr->wpos) >= 5) { ridx = 207;
1248 		} else { ridx = 900;
1249 		}
1250 	}
1251 
1252 	if (ridx) {
1253 		s_printf("FOUNTAIN_GUARDS: %d ", ridx);
1254 
1255 		msg_print(Ind, "A monster appears in the fountain!");
1256 		summon_override_checks = SO_GRID_TERRAIN | SO_IDDC | SO_PLAYER_SUMMON;
1257 		if (summon_specific_race(&p_ptr->wpos, p_ptr->py, p_ptr->px, ridx, 0, 1))
1258 			s_printf("ok.\n");
1259 		else s_printf("failed.\n");
1260 		summon_override_checks = SO_NONE;
1261 	}
1262 }
1263 #endif
1264 
1265 /*
1266  * Drink from a fountain
1267  */
do_cmd_drink_fountain(int Ind)1268 void do_cmd_drink_fountain(int Ind) {
1269 	player_type *p_ptr = Players[Ind];
1270 	cave_type **zcave;
1271 	cave_type *c_ptr;
1272 	c_special *cs_ptr;
1273 
1274 	bool ident;
1275 	int tval, sval, pval = 0, k_idx;
1276 
1277 	if (!(zcave = getcave(&p_ptr->wpos))) return;
1278 	c_ptr = &zcave[p_ptr->py][p_ptr->px];
1279 
1280 
1281 	/* HACK (sorta bad): if there's an item on the grid,
1282 	   tell us which it is, instead of trying to drink from
1283 	   a fountain! - C. Blue */
1284 	if (c_ptr->o_idx) {
1285 		whats_under_your_feet(Ind);
1286 		return;
1287 	}
1288 
1289 
1290 	/* decided to allow players in WRAITHFORM to drink ;) */
1291 	if (p_ptr->ghost) {
1292 		msg_print(Ind, "You cannot drink.");
1293 		return;
1294 	}
1295 
1296 	if (c_ptr->feat == FEAT_EMPTY_FOUNTAIN) {
1297 		msg_print(Ind, "The fountain is dried out.");
1298 		return;
1299 	} else if (c_ptr->feat == FEAT_DEEP_WATER ||
1300 	    c_ptr->feat == FEAT_SHAL_WATER) {
1301 #ifdef USE_SOUND_2010
1302 		sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1303 #endif
1304 		/* if it's the sea, it's salt water */
1305 		if (!p_ptr->wpos.wz)
1306 #if 0 /* problem: WILD_COAST is used for both oceans and lakes */
1307 		    switch (wild_info[p_ptr->wpos.wy][p_ptr->wpos.wx].type) {
1308 			case WILD_SHORE1:
1309 			case WILD_SHORE2:
1310 			case WILD_OCEANBED1:
1311 			case WILD_OCEANBED2:
1312 			case WILD_OCEAN:
1313 			case WILD_COAST:
1314 #else /* abuse ambient-sfx logic - it works pretty well ^^ */
1315 			if (p_ptr->sound_ambient == SFX_AMBIENT_SHORE) {
1316 #endif
1317 				if (p_ptr->prace == RACE_ENT) msg_print(Ind, "The water is too salty to feed off.");
1318 				else msg_print(Ind, "The water tastes very salty.");
1319 
1320 				/* Take a turn */
1321 				p_ptr->energy -= level_speed(&p_ptr->wpos);
1322 				return;
1323 		}
1324 		/* lake/river: fresh water */
1325 		if (!p_ptr->suscep_life) msg_print(Ind, "You feel less thirsty.");
1326 		else msg_print(Ind, "You drink some.");
1327 		if (p_ptr->prace == RACE_ENT) (void)set_food(Ind, p_ptr->food + WATER_ENT_FOOD);
1328 
1329 #ifdef FOUNTAIN_GUARDS
1330 		//(unlimited charges!) fountain_guard(Ind, FALSE);
1331 #endif
1332 		/* Take a turn */
1333 		p_ptr->energy -= level_speed(&p_ptr->wpos);
1334 		return;
1335 	} else if (c_ptr->feat == FEAT_FOUNTAIN_BLOOD) {
1336 #ifdef USE_SOUND_2010
1337 		sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1338 #endif
1339 
1340 		if (!(cs_ptr = GetCS(c_ptr, CS_FOUNTAIN))) {
1341 			/* paranoia? */
1342 			return;
1343 		}
1344 
1345 		if (p_ptr->prace == RACE_VAMPIRE) {
1346 			int feed = k_info[lookup_kind(TV_POTION, SV_POTION_BLOOD)].pval + p_ptr->food;
1347 
1348 			switch (rand_int(3)) {
1349 			case 0: msg_print(Ind, "Delicious.");
1350 			case 1: msg_print(Ind, "It's fresh.");
1351 			case 2: msg_print(Ind, "You're less thirsty.");
1352 			}
1353 
1354 			/* never get gorged */
1355 			if (feed >= PY_FOOD_MAX) feed = PY_FOOD_MAX - 1;
1356 			set_food(Ind, feed);
1357 		} else if (p_ptr->suscep_life) {
1358 			msg_print(Ind, "You feel less thirsty.");
1359 			(void)set_food(Ind, p_ptr->food + 100);
1360 		} else {
1361 			switch (rand_int(3)) {
1362 			case 0: msg_print(Ind, "Ew."); break;
1363 			case 1: msg_print(Ind, "Gross."); break;
1364 			case 2: msg_print(Ind, "Nasty."); break;
1365 			}
1366 		}
1367 
1368 #ifdef FOUNTAIN_GUARDS
1369 		fountain_guard(Ind, TRUE);
1370 #endif
1371 
1372 		/* Take a turn */
1373 		p_ptr->energy -= level_speed(&p_ptr->wpos);
1374 
1375 		cs_ptr->sc.fountain.rest--;
1376 		if (cs_ptr->sc.fountain.rest <= 0) {
1377 			cave_set_feat(&p_ptr->wpos, p_ptr->py, p_ptr->px, FEAT_EMPTY_FOUNTAIN);
1378 			cs_erase(c_ptr, cs_ptr);
1379 		}
1380 		return;
1381 	}
1382 
1383 	if (c_ptr->feat != FEAT_FOUNTAIN) {
1384 		msg_print(Ind, "You see no fountain here.");
1385 		return;
1386 	}
1387 
1388 	/* Oops! */
1389 	if (!(cs_ptr = GetCS(c_ptr, CS_FOUNTAIN))) {
1390 #ifdef USE_SOUND_2010
1391 		sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1392 #endif
1393 		if (!p_ptr->suscep_life) msg_print(Ind, "You feel less thirsty.");
1394 		else msg_print(Ind, "You drink some.");
1395 		if (p_ptr->prace == RACE_ENT) (void)set_food(Ind, p_ptr->food + WATER_ENT_FOOD);
1396 
1397 #ifdef FOUNTAIN_GUARDS
1398 		//(unlimited charges!) fountain_guard(Ind, FALSE);
1399 #endif
1400 		/* Take a turn */
1401 		p_ptr->energy -= level_speed(&p_ptr->wpos);
1402 		return;
1403 	}
1404 
1405 	if (cs_ptr->sc.fountain.rest <= 0) {
1406 		msg_print(Ind, "The fountain is dried out.");
1407 		return;
1408 	}
1409 
1410 	if (cs_ptr->sc.fountain.type <= SV_POTION_LAST) {
1411 		tval = TV_POTION;
1412 		sval = cs_ptr->sc.fountain.type;
1413 	} else {
1414 		tval = TV_POTION2;
1415 		sval = cs_ptr->sc.fountain.type - SV_POTION_LAST;
1416 	}
1417 
1418 	k_idx = lookup_kind(tval, sval);
1419 
1420 	/* Doh! */
1421 	if (!k_idx) {
1422 #ifdef USE_SOUND_2010
1423 		sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1424 #endif
1425 		if (!p_ptr->suscep_life) msg_print(Ind, "You feel less thirsty.");
1426 		else msg_print(Ind, "You drink some.");
1427 		if (p_ptr->prace == RACE_ENT) (void)set_food(Ind, p_ptr->food + WATER_ENT_FOOD);
1428 
1429 #ifdef FOUNTAIN_GUARDS
1430 		//(unlimited charges!) fountain_guard(Ind, FALSE);
1431 #endif
1432 		/* Take a turn */
1433 		p_ptr->energy -= level_speed(&p_ptr->wpos);
1434 		return;
1435 	}
1436 
1437 	pval = k_info[k_idx].pval;
1438 
1439 	/* S(he) is no longer afk */
1440 	un_afk_idle(Ind);
1441 #ifdef USE_SOUND_2010
1442 	sound(Ind, "quaff_potion", NULL, SFX_TYPE_COMMAND, FALSE);
1443 #endif
1444 
1445 	s_printf("FOUNTAIN: %s: %s\n", p_ptr->name, k_name + k_info[k_idx].name);
1446 
1447 	/* a little hack: avoid the extra less-thirsty-message for the 3 basic effectless potions.
1448 	   Idea: these potions do not give vampires a 'less thirsty' message, but when a vampire
1449 	   drinks from these fountains, he should still get a "you drink some" confirmation. */
1450 	if (tval == TV_POTION)
1451 		switch (sval) {
1452 		case SV_POTION_WATER:
1453 		case SV_POTION_APPLE_JUICE:
1454 		case SV_POTION_SLIME_MOLD:
1455 			ident = TRUE;
1456 			if (p_ptr->prace != RACE_VAMPIRE) msg_print(Ind, "You feel less thirsty.");
1457 			else msg_print(Ind, "You drink some.");
1458 			break;
1459 		default:
1460 			ident = quaff_potion(Ind, tval, sval, pval);
1461 		}
1462 	else ident = quaff_potion(Ind, tval, sval, pval);
1463 	if (ident) cs_ptr->sc.fountain.known = TRUE;
1464 	else if (p_ptr->prace != RACE_VAMPIRE) msg_print(Ind, "You feel less thirsty.");
1465 	else msg_print(Ind, "You drink some.");
1466 
1467 	if (p_ptr->prace == RACE_VAMPIRE) ;
1468 	else if (p_ptr->prace == RACE_ENT) {
1469 		if (sval == SV_POTION_WATER) (void)set_food(Ind, p_ptr->food + WATER_ENT_FOOD);
1470 		else (void)set_food(Ind, p_ptr->food + pval * 2);
1471 	} else if (p_ptr->suscep_life)
1472 		(void)set_food(Ind, p_ptr->food + (pval * 2) / 3);
1473 	else
1474 		(void)set_food(Ind, p_ptr->food + pval);
1475 
1476 	cs_ptr->sc.fountain.rest--;
1477 	if (cs_ptr->sc.fountain.rest <= 0) {
1478 		cave_set_feat(&p_ptr->wpos, p_ptr->py, p_ptr->px, FEAT_EMPTY_FOUNTAIN);
1479 		cs_erase(c_ptr, cs_ptr);
1480 	}
1481 
1482 #ifdef FOUNTAIN_GUARDS
1483 	fountain_guard(Ind, FALSE);
1484 #endif
1485 
1486 	/* Take a turn */
1487 	p_ptr->energy -= level_speed(&p_ptr->wpos);
1488 }
1489 
1490 
1491 
1492 /*
1493  * Fill an empty bottle
1494  */
1495 /* XXX this can be abusable; disable it in case */
1496 /* TODO: allow to fill on FEAT_DEEP_WATER (potion of water :) */
1497 /* Allow filling bottles with fountain blood? */
1498 #define ALLOW_BLOOD_BOTTLING
1499 void do_cmd_fill_bottle(int Ind) {
1500 	player_type *p_ptr = Players[Ind];
1501 	cave_type **zcave;
1502 	cave_type *c_ptr;
1503 	c_special *cs_ptr;
1504 
1505 	//bool ident;
1506 	int tval, sval, k_idx, item;
1507 
1508 	object_type *q_ptr, forge;
1509 	//cptr q, s;
1510 
1511 
1512 	if (!(zcave = getcave(&p_ptr->wpos))) return;
1513 	c_ptr = &zcave[p_ptr->py][p_ptr->px];
1514 
1515 	if (c_ptr->feat == FEAT_EMPTY_FOUNTAIN) {
1516 		msg_print(Ind, "The fountain is dried out.");
1517 		return;
1518 	}
1519 
1520 #ifndef ALLOW_BLOOD_BOTTLING
1521 	if (c_ptr->feat == FEAT_FOUNTAIN_BLOOD) {
1522 		msg_print(Ind, "Fresh blood perishes too quickly.");
1523 		return;
1524 	}
1525 
1526 	if (c_ptr->feat != FEAT_FOUNTAIN) {
1527 		msg_print(Ind, "You see no fountain here.");
1528 		return;
1529 	}
1530 #else
1531 	if (c_ptr->feat != FEAT_FOUNTAIN && c_ptr->feat != FEAT_FOUNTAIN_BLOOD) {
1532 		msg_print(Ind, "You see no fountain here.");
1533 		return;
1534 	}
1535 #endif
1536 
1537 	/* Oops! */
1538 	if (!(cs_ptr = GetCS(c_ptr, CS_FOUNTAIN))) return;
1539 
1540 	if (cs_ptr->sc.fountain.rest <= 0) {
1541 		msg_print(Ind, "The fountain is dried out.");
1542 		return;
1543 	}
1544 
1545 	if (p_ptr->tim_wraith) { /* not in WRAITHFORM */
1546 		    msg_print(Ind, "The water seems to pass through the bottle!");
1547 		return;
1548 	}
1549 
1550 	if (cs_ptr->sc.fountain.type <= SV_POTION_LAST) {
1551 		tval = TV_POTION;
1552 		sval = cs_ptr->sc.fountain.type;
1553 	} else {
1554 		tval = TV_POTION2;
1555 		sval = cs_ptr->sc.fountain.type - SV_POTION_LAST;
1556 	}
1557 
1558 	k_idx = lookup_kind(tval, sval);
1559 
1560 	/* Doh! */
1561 	if (!k_idx) k_idx = lookup_kind(TV_POTION, SV_POTION_WATER);
1562 
1563 	if (!get_something_tval(Ind, TV_BOTTLE, &item)) {
1564 		msg_print(Ind, "You have no bottles to fill.");
1565 		return;
1566 	}
1567 
1568 	/* Destroy a bottle in the pack */
1569 	if (item >= 0) {
1570 		inven_item_increase(Ind, item, -1);
1571 		inven_item_describe(Ind, item);
1572 		inven_item_optimize(Ind, item);
1573 	}
1574 	/* Destroy a potion on the floor */
1575 	else {
1576 		floor_item_increase(0 - item, -1);
1577 		floor_item_describe(0 - item);
1578 		floor_item_optimize(0 - item);
1579 	}
1580 
1581 	/* Create the potion */
1582 	q_ptr = &forge;
1583 	object_prep(q_ptr, k_idx);
1584 	q_ptr->number = 1;
1585 //	q_ptr->owner = p_ptr->id;
1586 	determine_level_req(getlevel(&p_ptr->wpos), q_ptr);
1587 
1588 //	if (c_ptr->info & CAVE_IDNT)
1589 	if (cs_ptr->sc.fountain.known) {
1590 		object_aware(Ind, q_ptr);
1591 		object_known(q_ptr);
1592 	}
1593 	else if (object_aware_p(Ind, q_ptr)) cs_ptr->sc.fountain.known = TRUE;
1594 #ifdef ALLOW_BLOOD_BOTTLING
1595 	if (q_ptr->sval == SV_POTION_BLOOD) q_ptr->timeout = 1750 + rand_int(501);//goes bad after a while!
1596 #endif
1597 	inven_carry(Ind, q_ptr);
1598 
1599 	cs_ptr->sc.fountain.rest--;
1600 
1601 	if (cs_ptr->sc.fountain.rest <= 0) {
1602 		cave_set_feat(&p_ptr->wpos, p_ptr->py, p_ptr->px, FEAT_EMPTY_FOUNTAIN);
1603 		cs_erase(c_ptr, cs_ptr);
1604 	}
1605 
1606 	/* S(he) is no longer afk */
1607 	un_afk_idle(Ind);
1608 
1609 #ifdef FOUNTAIN_GUARDS
1610 	item = 0;
1611 //	if (k_info[lookup_kind(tval, sval)].cost > 0) {
1612 	if (magik(FOUNTAIN_GUARDS)) {
1613 		if (getlevel(&p_ptr->wpos) >= 40) { switch (randint(2)) { case 1:item = 924;break; case 2:item = 893; }
1614 		} else if (getlevel(&p_ptr->wpos) >= 35) { switch (randint(3)) { case 1:item = 1038;break; case 2:item = 894;break; case 3:item = 902; }
1615 		} else if (getlevel(&p_ptr->wpos) >= 30) { switch (randint(2)) { case 1:item = 512;break; case 2:item = 509; }
1616 		} else if (getlevel(&p_ptr->wpos) >= 25) { item = 443;
1617 		} else if (getlevel(&p_ptr->wpos) >= 20) { switch (randint(4)) {case 1:item = 919;break; case 2:item = 882;break; case 3:item = 927;break; case 4:item = 1057; }
1618 		} else if (getlevel(&p_ptr->wpos) >= 15) { switch (randint(3)) {case 1:item = 303;break; case 2:item = 923;break; case 3:item = 926; }
1619 		} else if (getlevel(&p_ptr->wpos) >= 10) { item = 925;
1620 		} else if (getlevel(&p_ptr->wpos) >= 5) { item = 207;
1621 		} else { item = 900;
1622 		}
1623 		s_printf("FOUNTAIN_GUARDS: %d ", item);
1624 	}
1625 //	}
1626 	if (item) {
1627 		msg_print(Ind, "A monster appears in the fountain!");
1628 		summon_override_checks = SO_GRID_TERRAIN | SO_IDDC | SO_PLAYER_SUMMON;
1629 		if (summon_specific_race(&p_ptr->wpos, p_ptr->py, p_ptr->px, item, 0, 1))
1630 			s_printf("ok.\n");
1631 		else s_printf("failed.\n");
1632 		summon_override_checks = SO_NONE;
1633 	}
1634 #endif
1635 
1636 	/* Take a turn */
1637 	p_ptr->energy -= level_speed(&p_ptr->wpos);
1638 }
1639 
1640 
1641 /*
1642  * Empty a potion in the backpack
1643  */
1644 void do_cmd_empty_potion(int Ind, int slot) {
1645 	player_type *p_ptr = Players[Ind];
1646 
1647 	//bool ident;
1648 	int tval;//, k_idx, item;
1649 
1650 	object_type *o_ptr, *q_ptr, forge;
1651 	//cptr q, s;
1652 
1653 	o_ptr = &p_ptr->inventory[slot];
1654 	if (!o_ptr->k_idx) return;
1655 
1656 	tval = o_ptr->tval;
1657 	if (tval != TV_POTION && tval != TV_POTION2) {
1658 		msg_print(Ind, "\377oThat's not a potion!");
1659 		return;
1660 	}
1661 
1662 	/* Create an empty bottle */
1663 	q_ptr = &forge;
1664 	object_wipe(q_ptr);
1665 	q_ptr->number = 1;
1666 	invcopy(q_ptr, lookup_kind(TV_BOTTLE, SV_EMPTY_BOTTLE));
1667 	q_ptr->level = o_ptr->level;
1668 
1669 	/* Destroy a potion in the pack */
1670 	inven_item_increase(Ind, slot, -1);
1671 	inven_item_describe(Ind, slot);
1672 	inven_item_optimize(Ind, slot);
1673 
1674 	/* let the player carry the bottle */
1675 	inven_carry(Ind, q_ptr);
1676 
1677 	/* S(he) is no longer afk */
1678 	un_afk_idle(Ind);
1679 
1680 	/* Take a turn */
1681 	p_ptr->energy -= level_speed(&p_ptr->wpos);
1682 }
1683 
1684 
1685 /*
1686  * Curse the players armor
1687  */
1688 bool curse_armor(int Ind) {
1689 	player_type *p_ptr = Players[Ind];
1690 	object_type *o_ptr;
1691 	char o_name[ONAME_LEN];
1692 
1693 
1694 	/* Curse the body armor */
1695 	o_ptr = &p_ptr->inventory[INVEN_BODY];
1696 
1697 	/* Nothing to curse */
1698 	if (!o_ptr->k_idx) return (FALSE);
1699 
1700 	/* might mess up quest stuff */
1701 	if (o_ptr->questor ||
1702 	    (o_ptr->tval == TV_SPECIAL && o_ptr->sval == SV_QUEST))
1703 		return FALSE;
1704 
1705 
1706 	/* Describe */
1707 	object_desc(Ind, o_name, o_ptr, FALSE, 3);
1708 
1709 	/* Attempt a saving throw for artifacts */
1710 	if (artifact_p(o_ptr) && (rand_int(100) < 30)) {
1711 		/* Cool */
1712 		msg_format(Ind, "A %s tries to %s, but your %s resists the effects!",
1713 		           "terrible black aura", "surround your armour", o_name);
1714 	}
1715 
1716 	/* not artifact or failed save... */
1717 	else {
1718 		/* Oops */
1719 		msg_format(Ind, "A terrible black aura blasts your %s!", o_name);
1720 
1721 		if (true_artifact_p(o_ptr))
1722 			handle_art_d(o_ptr->name1);
1723 
1724 		/* Blast the armor */
1725 		o_ptr->name1 = 0;
1726 		o_ptr->name2 = EGO_BLASTED;
1727 		o_ptr->name3 = 0;
1728 		o_ptr->to_a = 0 - randint(5) - randint(5);
1729 		o_ptr->to_h = 0;
1730 		o_ptr->to_d = 0;
1731 		o_ptr->ac = 0;
1732 		o_ptr->dd = 0;
1733 		o_ptr->ds = 0;
1734 
1735 		/* Curse it */
1736 		o_ptr->ident |= ID_CURSED;
1737 
1738 		/* Break it */
1739 		o_ptr->ident |= ID_BROKEN;
1740 
1741 		/* Recalculate bonuses */
1742 		p_ptr->update |= (PU_BONUS);
1743 
1744 		/* Recalculate mana */
1745 		p_ptr->update |= (PU_MANA);
1746 
1747 		/* Window stuff */
1748 		p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1749 	}
1750 
1751 	return (TRUE);
1752 }
1753 
1754 
1755 /*
1756  * Curse the players weapon
1757  */
1758 bool curse_weapon(int Ind) {
1759 	player_type *p_ptr  = Players[Ind];
1760 	object_type *o_ptr;
1761 	char o_name[ONAME_LEN];
1762 
1763 	/* Curse the weapon */
1764 	o_ptr = &p_ptr->inventory[INVEN_WIELD];
1765 
1766 	/* Nothing to curse */
1767 	if (!o_ptr->k_idx &&
1768 	    (!p_ptr->inventory[INVEN_ARM].k_idx || p_ptr->inventory[INVEN_ARM].tval == TV_SHIELD)) return (FALSE);
1769 	if (!o_ptr->k_idx) o_ptr = &p_ptr->inventory[INVEN_ARM]; /* dual-wield..*/
1770 
1771 	/* might mess up quest stuff */
1772 	if (o_ptr->questor ||
1773 	    (o_ptr->tval == TV_SPECIAL && o_ptr->sval == SV_QUEST))
1774 		return FALSE;
1775 
1776 
1777 	/* Describe */
1778 	object_desc(Ind, o_name, o_ptr, FALSE, 3);
1779 
1780 	/* Attempt a saving throw */
1781 	if (artifact_p(o_ptr) && (rand_int(100) < 30)) {
1782 		/* Cool */
1783 		msg_format(Ind, "A %s tries to %s, but your %s resists the effects!",
1784 		           "terrible black aura", "surround your weapon", o_name);
1785 	}
1786 
1787 	/* not artifact or failed save... */
1788 	else {
1789 		/* Oops */
1790 		msg_format(Ind, "A terrible black aura blasts your %s!", o_name);
1791 
1792 		if (true_artifact_p(o_ptr))
1793 			handle_art_d(o_ptr->name1);
1794 
1795 		/* Shatter the weapon */
1796 		o_ptr->name1 = 0;
1797 		o_ptr->name2 = EGO_SHATTERED;
1798 		o_ptr->name3 = 0;
1799 		o_ptr->to_h = 0 - randint(5) - randint(5);
1800 		o_ptr->to_d = 0 - randint(5) - randint(5);
1801 		o_ptr->to_a = 0;
1802 		o_ptr->ac = 0;
1803 		o_ptr->dd = 0;
1804 		o_ptr->ds = 0;
1805 
1806 		/* Curse it */
1807 		o_ptr->ident |= ID_CURSED;
1808 
1809 		/* Break it */
1810 		o_ptr->ident |= ID_BROKEN;
1811 
1812 		/* Recalculate bonuses */
1813 		p_ptr->update |= (PU_BONUS);
1814 
1815 		/* Recalculate mana */
1816 		p_ptr->update |= (PU_MANA);
1817 
1818 		/* Window stuff */
1819 		p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1820 	}
1821 
1822 	/* Notice */
1823 	return (TRUE);
1824 }
1825 
1826 
1827 
1828 /*
1829  * Curse the players equipment in general	- Jir -
1830  */
1831 #if 0	// let's use this for Hand-o-Doom :)
1832 bool curse_an_item(int Ind, int slot)
1833 {
1834 	player_type *p_ptr = Players[Ind];
1835 
1836 	object_type *o_ptr;
1837 
1838 	char o_name[ONAME_LEN];
1839 
1840 
1841 	/* Curse the body armor */
1842 	o_ptr = &p_ptr->inventory[slot];
1843 
1844 	/* Nothing to curse */
1845 	if (!o_ptr->k_idx) return (FALSE);
1846 
1847 	/* might mess up quest stuff */
1848 	if (o_ptr->questor ||
1849 	    (o_ptr->tval == TV_SPECIAL && o_ptr->sval == SV_QUEST))
1850 		return FALSE;
1851 
1852 	/* Describe */
1853 	object_desc(Ind, o_name, o_ptr, FALSE, 3);
1854 
1855 	/* Attempt a saving throw for artifacts */
1856 	if (artifact_p(o_ptr) && (rand_int(100) < 50)) {
1857 		/* Cool */
1858 		msg_format(Ind, "A %s tries to %s, but your %s resists the effects!",
1859 		           "terrible black aura", "surround you", o_name);
1860 	}
1861 
1862 	/* not artifact or failed save... */
1863 	else {
1864 		/* Oops */
1865 		msg_format(Ind, "A terrible black aura blasts your %s!", o_name);
1866 
1867 		if (true_artifact_p(o_ptr))
1868 			handle_art_d(o_ptr->name1);
1869 
1870 		/* Blast the armor */
1871 		o_ptr->name1 = 0;
1872 		o_ptr->name2 = EGO_BLASTED;	// ?
1873 		o_ptr->name3 = 0;
1874 		o_ptr->to_a = 0 - randint(5) - randint(5);
1875 		o_ptr->to_h = 0 - randint(5) - randint(5);
1876 		o_ptr->to_d = 0 - randint(5) - randint(5);
1877 		o_ptr->ac = 0;
1878 		o_ptr->dd = 0;
1879 		o_ptr->ds = 0;
1880 
1881 		/* Curse it */
1882 		o_ptr->ident |= ID_CURSED;
1883 
1884 		/* Break it */
1885 		o_ptr->ident |= ID_BROKEN;
1886 
1887 		/* Recalculate bonuses */
1888 		p_ptr->update |= (PU_BONUS);
1889 
1890 		/* Recalculate mana */
1891 		p_ptr->update |= (PU_MANA);
1892 
1893 		/* Window stuff */
1894 		p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1895 	}
1896 
1897 	return (TRUE);
1898 }
1899 #endif	// 0
1900 
1901 /*
1902  * Cancel magic in inventory.		- Jir -
1903  * Crappy, isn't it?  But it can..
1904  *
1905  * 0x01 - Affect the equipments too
1906  * 0x02 - Turn scrolls/potions/wands/rods/staves into 'Nothing' kind
1907  */
1908 bool do_cancellation(int Ind, int flags) {
1909 	player_type *p_ptr = Players[Ind];
1910 	int i;
1911 	bool ident = TRUE;
1912 
1913 	s_printf("CANCELLATION: %s (%d)\n", p_ptr->name, flags);
1914 
1915 	for (i = 0; i < ((flags & 0x01) ? INVEN_TOTAL : INVEN_WIELD); i++) {
1916 		object_type *o_ptr = &p_ptr->inventory[i];
1917 		if (!o_ptr->k_idx) continue;
1918 		if (like_artifact_p(o_ptr)) continue;
1919 		if (o_ptr->tval == TV_KEY) continue;
1920 		if (o_ptr->tval == TV_FOOD) continue;
1921 		if (o_ptr->tval == TV_FLASK) continue;
1922 		if (o_ptr->tval == TV_CHEST) continue;
1923 		if (o_ptr->name2 && o_ptr->name2 != EGO_SHATTERED && o_ptr->name2 != EGO_BLASTED) {
1924 			ident = TRUE;
1925 			o_ptr->name2 = 0;
1926 		}
1927 		if (o_ptr->name2b && o_ptr->name2b != EGO_SHATTERED && o_ptr->name2b != EGO_BLASTED) {
1928 			ident = TRUE;
1929 			o_ptr->name2b = 0;
1930 		}
1931 		if (o_ptr->name3) o_ptr->name3 = 0; //Kurzel - Fix stacking, see object2.c
1932 		if (o_ptr->timeout) {
1933 			ident = TRUE;
1934 			if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_POLYMORPH)
1935 				o_ptr->timeout = 1;
1936 			else
1937 				o_ptr->timeout = 0;
1938 		}
1939 		/* pval for potions is their nourishment value, so exempt them */
1940 		if (o_ptr->tval != TV_POTION && o_ptr->pval > 0) {
1941 			ident = TRUE;
1942 			o_ptr->pval = 0;
1943 		}
1944 		if (o_ptr->bpval) {
1945 			ident = TRUE;
1946 			o_ptr->bpval = 0;
1947 		}
1948 		if (o_ptr->to_h > 0) {
1949 			ident = TRUE;
1950 			o_ptr->to_h = 0;
1951 		}
1952 		if (o_ptr->to_d > 0) {
1953 			ident = TRUE;
1954 			o_ptr->to_d = 0;
1955 		}
1956 		if (o_ptr->to_a > 0) {
1957 			ident = TRUE;
1958 			o_ptr->to_a = 0;
1959 		}
1960 #if 0	// Not so useful anyway
1961 		if (flags & 0x02) {
1962 			switch (o_ptr->tval)
1963 			{
1964 			}
1965 		}
1966 #endif	// 0
1967 	}
1968 
1969 	return (ident);
1970 }
1971 
1972 /*
1973  * Read a scroll (from the pack or floor).
1974  *
1975  * Certain scrolls can be "aborted" without losing the scroll.  These
1976  * include scrolls with no effects but recharge or identify, which are
1977  * cancelled before use.  XXX Reading them still takes a turn, though.
1978  */
1979 
1980  /*
1981 
1982  Added scroll of Life... uses vars x,y
1983 -AD-
1984  */
1985 
1986 /* Pfft, it's silly long */
1987 #define LOTTERY_MAX_PRIZE	7
1988 static void do_lottery(int Ind, object_type *o_ptr)
1989 {
1990 	player_type *p_ptr = Players[Ind];
1991 	int i = k_info[o_ptr->k_idx].cost, j, k = 0, i_drop = i, gold;
1992 
1993 	i -= i * o_ptr->discount / 100;
1994 
1995 	/* 30 * 4^7 = 30 * 16384 =   491,520 */
1996 	/* 30 * 5^7 = 30 * 78125 = 2,343,750 */
1997 	for (j = 0; j < LOTTERY_MAX_PRIZE; j++)
1998 	{
1999 /* was this really intended to be magik() !? - C. Blue -		if (!magik(5)) break; */
2000 		if (rand_int(4)) break;
2001 		if (k) i *= 5;
2002 		k++;
2003 	}
2004 
2005 	if (!j)
2006 	{
2007 		msg_print(Ind, "\377WYou draw a blank :-P");
2008 		s_printf("Lottery results: %s drew a blank.\n", p_ptr->name);
2009 	}
2010 	else
2011 	{
2012 		cptr p = "th";
2013 
2014 		k = LOTTERY_MAX_PRIZE + 1 - k;
2015 
2016 		if ((k % 10) == 1) p = "st";
2017 		else if ((k % 10) == 2) p = "nd";
2018 		else if ((k % 10) == 3) p = "rd";
2019 
2020 		s_printf("Lottery results: %s won the %d%s prize of %d Au.\n", p_ptr->name, k, p, i);
2021 
2022 		if (k < 4) {
2023 			if (k == 1) msg_broadcast_format(0, "\374\377y$$$ \377%c%s seems to hit the big time! \377y$$$", COLOUR_CHAT, p_ptr->name);
2024 			else msg_broadcast_format(0, "\374\377%c%s seems to hit the big time!", COLOUR_CHAT, p_ptr->name);
2025 			set_confused(Ind, p_ptr->confused + rand_int(10) + 10);
2026 			set_image(Ind, p_ptr->image + rand_int(10) + 10);
2027 		}
2028 		msg_format(Ind, "\374\377%cYou won the %d%s prize!", COLOUR_CHAT, k, p);
2029 
2030 		gold = i;
2031 
2032 		/* Invert it again for following calcs (#else branch below) */
2033 		k = LOTTERY_MAX_PRIZE + 1 - k;
2034 		i_drop *= 2;
2035 		for (j = 0; j < k; j++) {
2036 			i_drop *= 3;
2037 		}
2038 
2039 		while (gold > 0)
2040 		{
2041 			object_type forge, *j_ptr = &forge;
2042 			int drop;
2043 
2044 #if 0 /*Too many piles*/
2045 			drop = (i > 1000) ?
2046 			    randint(i / 10 / (LOTTERY_MAX_PRIZE * LOTTERY_MAX_PRIZE
2047 			    + 1 - k * k)) * 10 : i;
2048 #else
2049 			drop = i_drop;
2050 #endif
2051 			if (drop > gold) drop = gold;
2052 
2053 			/* Wipe the object */
2054 			object_wipe(j_ptr);
2055 
2056 			/* Prepare a gold object */
2057 			invcopy(j_ptr, gold_colour(drop, TRUE, FALSE));
2058 
2059 			/* Determine how much the treasure is "worth" */
2060 			//j_ptr->pval = (gold >= 15000) ? 15000 : gold;
2061 			j_ptr->pval = drop;
2062 
2063 			drop_near(j_ptr, 0, &p_ptr->wpos, p_ptr->py, p_ptr->px);
2064 
2065 			gold -= drop;
2066 		}
2067 
2068 		/* Window stuff */
2069 		p_ptr->window |= (PW_PLAYER);
2070 	}
2071 }
2072 
2073 /*
2074  * Too much summon cheeze - check it before letting them summon - evileye
2075  * Let's not summon on worldmap surface at all but only in dungeons/towers,
2076  * since those have level requirements (C. Blue)
2077  *
2078  */
2079 static int check_self_summon(player_type *p_ptr){
2080 	cave_type **zcave, *c_ptr;
2081 	struct dun_level *l_ptr = getfloor(&p_ptr->wpos);
2082 
2083 	if (is_admin(p_ptr)) return(TRUE);
2084 
2085 	if (l_ptr && (l_ptr->flags2 & LF2_NO_SUMMON)) return FALSE;
2086 
2087 	if (((!cfg.surface_summoning) && (p_ptr->wpos.wz == 0))
2088 	    || istownarea(&p_ptr->wpos, MAX_TOWNAREA)) /* poly ring anticheeze (those don't run out in town area) */
2089 		return(FALSE);
2090 
2091 	zcave = getcave(&p_ptr->wpos);
2092 	if (zcave) {
2093 		c_ptr = &zcave[p_ptr->py][p_ptr->px];
2094 
2095 		/* not on wilderness edge */
2096 		if (p_ptr->wpos.wz || in_bounds(p_ptr->py, p_ptr->px)) {
2097 			/* and not sitting on the stairs */
2098 			if(c_ptr->feat != FEAT_LESS && c_ptr->feat != FEAT_MORE &&
2099 			    c_ptr->feat != FEAT_WAY_LESS && c_ptr->feat != FEAT_WAY_MORE &&
2100 			    c_ptr->feat != FEAT_BETWEEN)
2101 				return(TRUE);
2102 		}
2103 	}
2104 
2105 	return(FALSE);
2106 }
2107 
2108 bool read_scroll(int Ind, int tval, int sval, object_type *o_ptr, int item, bool *used_up, bool *keep) {
2109 	player_type *p_ptr = Players[Ind];
2110 	int ident = FALSE;
2111 	int k;
2112 	char	m_name[MNAME_LEN];
2113         monster_type    *m_ptr;
2114         monster_race    *r_ptr;
2115 
2116 	/* Analyze the scroll */
2117 	if (tval == TV_SCROLL) {
2118 		switch (sval) {
2119 			case SV_SCROLL_HOUSE:
2120 			{
2121 				if (!o_ptr) break;
2122 
2123 				/* With my fix, this scroll causes crash when rebooting server.
2124 				 * w/o my fix, this scroll causes crash when finishing house
2125 				 * creation.  Pfft
2126 				 */
2127 				//unsigned char *ins = quark_str(o_ptr->note);
2128 				cptr ins = quark_str(o_ptr->note);
2129 				bool floor = TRUE;
2130 				bool jail = FALSE;
2131 				msg_print(Ind, "This is a house creation scroll.");
2132 				ident = TRUE;
2133 				if(ins){
2134 					while ((*ins != '\0')) {
2135 						if (*ins == '@') {
2136 							ins++;
2137 							if (*ins == 'F') {
2138 								floor = FALSE;
2139 							}
2140 							if (*ins == 'J') {
2141 								jail = TRUE;
2142 							}
2143 						}
2144 						ins++;
2145 					}
2146 				}
2147 				house_creation(Ind, floor, jail);
2148 				ident = TRUE;
2149 				break;
2150 			}
2151 
2152 			case SV_SCROLL_GOLEM:
2153 				if (o_ptr) msg_print(Ind, "This is a golem creation scroll.");
2154 				ident = TRUE;
2155 				golem_creation(Ind, 1);
2156 				break;
2157 
2158 			case SV_SCROLL_BLOOD_BOND:
2159 				if (!o_ptr) break;
2160 
2161 				msg_print(Ind, "This is a blood bond scroll.");
2162 				ident = TRUE;
2163 				if (!(p_ptr->mode & MODE_PVP)) blood_bond(Ind, o_ptr);
2164 				else msg_print(Ind, "True gladiators must fight to the death!");
2165 				break;
2166 
2167 			case SV_SCROLL_ARTIFACT_CREATION:
2168 				if (!o_ptr) break;
2169 
2170 				msg_print(Ind, "This is an artifact creation scroll.");
2171 				ident = TRUE;
2172 				/* check for 'no +LIFE' inscription */
2173 				if (o_ptr->note && check_guard_inscription(o_ptr->note, 'L'))
2174 					(void)create_artifact(Ind, TRUE);
2175 				else
2176 					(void)create_artifact(Ind, FALSE);
2177 				*used_up = FALSE;
2178 				p_ptr->using_up_item = item;
2179 				break;
2180 
2181 			case SV_SCROLL_DARKNESS:
2182 				if (unlite_area(Ind, 10, 3)) ident = TRUE;
2183 				if (!p_ptr->resist_dark)
2184 					(void)set_blind(Ind, p_ptr->blind + 3 + randint(5));
2185 				break;
2186 
2187 			case SV_SCROLL_AGGRAVATE_MONSTER:
2188 #ifdef USE_SOUND_2010
2189 				sound_near(Ind, "shriek", NULL, SFX_TYPE_MON_SPELL);
2190 #endif
2191  				msg_print(Ind, "\377RThere is a high-pitched humming noise.");
2192  				msg_print_near(Ind, "\377RThere is a high-pitched humming noise.");
2193 				aggravate_monsters(Ind, -1);
2194 				ident = TRUE;
2195 				break;
2196 
2197 			case SV_SCROLL_CURSE_ARMOR:
2198 				if (curse_armor(Ind)) ident = TRUE;
2199 				break;
2200 
2201 			case SV_SCROLL_CURSE_WEAPON:
2202 				if (curse_weapon(Ind)) ident = TRUE;
2203 				break;
2204 
2205 			case SV_SCROLL_SUMMON_MONSTER:
2206 				if(!check_self_summon(p_ptr)) break;
2207 				s_printf("SUMMON_MONSTER: %s\n", p_ptr->name);
2208 				summon_override_checks = SO_IDDC | SO_PLAYER_SUMMON;
2209 				for (k = 0; k < randint(3); k++) {
2210 					if (summon_specific(&p_ptr->wpos, p_ptr->py, p_ptr->px, getlevel(&p_ptr->wpos), 0, SUMMON_ALL_U98, 1, 0))
2211 						ident = TRUE;
2212 				}
2213 				summon_override_checks = SO_NONE;
2214 				break;
2215 
2216 			case SV_SCROLL_CONJURE_MONSTER: /* clone to avoid heavy mimic cheeze (and maybe exp cheeze) */
2217 				if (!o_ptr) break;
2218 
2219 				if(!check_self_summon(p_ptr)) break;
2220 				k = get_monster(Ind, o_ptr);
2221 				if(!k) break;
2222 				if (r_info[k].flags1 & RF1_UNIQUE) break;
2223 
2224 				monster_race_desc(Ind, m_name, k, 0x188);
2225 		                msg_format(Ind, "\377oYou conjure %s!", m_name);
2226 				msg_format_near(Ind, "\377o%s conjures %s", p_ptr->name, m_name);
2227 				if (summon_specific_race(&p_ptr->wpos, p_ptr->py, p_ptr->px, k, 100, 1))
2228 					ident = TRUE;
2229 				break;
2230 
2231 			case SV_SCROLL_SLEEPING:
2232 				msg_print(Ind, "A veil of sleep falls down over the wide surroundings..");
2233 			        for (k = m_top - 1; k >= 0; k--) {
2234 			                /* Access the monster */
2235 			                m_ptr = &m_list[m_fast[k]];
2236 					r_ptr = race_inf(m_ptr);
2237 	    			        /* On this level? Test its highest encounter so far */
2238 			                if (inarea(&m_ptr->wpos, &p_ptr->wpos) &&
2239 					    !((r_ptr->flags1 & RF1_UNIQUE) ||
2240 			                    (r_ptr->flags3 & RF3_NO_SLEEP)))
2241 						m_ptr->csleep = 1000;
2242 			        }
2243 				break;
2244 
2245 			/* not adding bounds checking now... because of perma walls
2246 			   hope that I don't need to......
2247 
2248 			   OK, modified so you cant ressurect ghosts in walls......
2249 			   to prevent bad things from happening in town.
2250 			   */
2251 			case SV_SCROLL_LIFE:
2252 				/* only restore life levels if no resurrect */
2253 				if(!do_scroll_life(Ind))
2254 					restore_level(Ind);
2255 				break;
2256 
2257 
2258 			case SV_SCROLL_SUMMON_UNDEAD:
2259 				if(!check_self_summon(p_ptr)) break;
2260 				s_printf("SUMMON_UNDEAD: %s\n", p_ptr->name);
2261 				summon_override_checks = SO_IDDC | SO_PLAYER_SUMMON;
2262 				for (k = 0; k < randint(3); k++) {
2263 					if (summon_specific(&p_ptr->wpos, p_ptr->py, p_ptr->px, getlevel(&p_ptr->wpos), 0, SUMMON_UNDEAD, 1, 0))
2264 						ident = TRUE;
2265 				}
2266 				summon_override_checks = SO_NONE;
2267 				break;
2268 
2269 			case SV_SCROLL_TRAP_CREATION:
2270 				if (trap_creation(Ind, 5, 1)) ident = TRUE;
2271 				break;
2272 
2273 			case SV_SCROLL_PHASE_DOOR:
2274 				teleport_player(Ind, 10, TRUE);
2275 				ident = TRUE;
2276 				break;
2277 
2278 			case SV_SCROLL_TELEPORT:
2279 				teleport_player(Ind, 100, FALSE);
2280 				ident = TRUE;
2281 				break;
2282 
2283 			case SV_SCROLL_TELEPORT_LEVEL:
2284 				teleport_player_level(Ind, FALSE);
2285 				ident = TRUE;
2286 				break;
2287 
2288 			case SV_SCROLL_WORD_OF_RECALL:
2289 				if (!o_ptr) break;
2290 
2291 				set_recall(Ind, rand_int(20) + 15, o_ptr);
2292 				ident = TRUE;
2293 				break;
2294 
2295 			case SV_SCROLL_IDENTIFY:
2296 				if (!o_ptr) break;
2297 
2298 				msg_print(Ind, "This is an identify scroll.");
2299 				ident = TRUE;
2300 				(void)ident_spell(Ind);
2301 				*used_up = FALSE;
2302 				p_ptr->using_up_item = item;
2303 				break;
2304 
2305 			case SV_SCROLL_STAR_IDENTIFY:
2306 				if (!o_ptr) break;
2307 
2308 				msg_print(Ind, "This is an *identify* scroll.");
2309 				ident = TRUE;
2310 				(void)identify_fully(Ind);
2311 				*used_up = FALSE;
2312 				p_ptr->using_up_item = item;
2313 				break;
2314 
2315 			case SV_SCROLL_REMOVE_CURSE:
2316 #ifndef NEW_REMOVE_CURSE
2317 				if (remove_curse(Ind)) {
2318 					msg_print(Ind, "\377GYou feel as if someone is watching over you.");
2319 #else
2320 				if (remove_curse_aux(Ind, 0x0, 0)) {
2321 #endif
2322 					ident = TRUE;
2323 				}
2324 				break;
2325 
2326 			case SV_SCROLL_STAR_REMOVE_CURSE:
2327 #ifndef NEW_REMOVE_CURSE
2328 				if (remove_all_curse(Ind)) {
2329 					msg_print(Ind, "\377GYou feel as if someone is watching over you.");
2330 #else
2331 				if (remove_curse_aux(Ind, 0x1, 0)) {
2332 #endif
2333 					ident = TRUE;
2334 				}
2335 				break;
2336 
2337 			case SV_SCROLL_ENCHANT_ARMOR:
2338 				if (!o_ptr) break;
2339 
2340 				msg_print(Ind, "This is a Scroll of Enchant Armour.");
2341 				ident = TRUE;
2342 				(void)enchant_spell(Ind, 0, 0, 1, o_ptr->discount == 100 ? ENCH_STOLEN : 0);
2343 				*used_up = FALSE;
2344 				p_ptr->using_up_item = item;
2345 				break;
2346 
2347 			case SV_SCROLL_ENCHANT_WEAPON_TO_HIT:
2348 				if (!o_ptr) break;
2349 
2350 				msg_print(Ind, "This is a Scroll of Enchant Weapon To-Hit.");
2351 				(void)enchant_spell(Ind, 1, 0, 0, o_ptr->discount == 100 ? ENCH_STOLEN : 0);
2352 				*used_up = FALSE;
2353 				p_ptr->using_up_item = item;
2354 				ident = TRUE;
2355 				break;
2356 
2357 			case SV_SCROLL_ENCHANT_WEAPON_TO_DAM:
2358 				if (!o_ptr) break;
2359 
2360 				msg_print(Ind, "This is a Scroll of Enchant Weapon To-Dam.");
2361 				(void)enchant_spell(Ind, 0, 1, 0, o_ptr->discount == 100 ? ENCH_STOLEN : 0);
2362 				*used_up = FALSE;
2363 				p_ptr->using_up_item = item;
2364 				ident = TRUE;
2365 				break;
2366 
2367 			case SV_SCROLL_STAR_ENCHANT_ARMOR:
2368 				if (!o_ptr) break;
2369 
2370 				msg_print(Ind, "This is a Scroll of *Enchant Armour*.");
2371 				(void)enchant_spell(Ind, 0, 0, randint(3) + 3, o_ptr->discount == 100 ? ENCH_STOLEN : 0);
2372 				*used_up = FALSE;
2373 				p_ptr->using_up_item = item;
2374 				ident = TRUE;
2375 				break;
2376 
2377 			case SV_SCROLL_STAR_ENCHANT_WEAPON:
2378 				if (!o_ptr) break;
2379 
2380 				msg_print(Ind, "This is a Scroll of *Enchant Weapon*.");
2381 				(void)enchant_spell(Ind, 1 + randint(2), 1 + randint(2), 0, o_ptr->discount == 100 ? ENCH_STOLEN : 0);
2382 				*used_up = FALSE;
2383 				p_ptr->using_up_item = item;
2384 				ident = TRUE;
2385 				break;
2386 
2387 			case SV_SCROLL_RECHARGING:
2388 				if (!o_ptr) break;
2389 
2390 				msg_print(Ind, "This is a Scroll of Recharging.");
2391 				(void)recharge(Ind, 60);
2392 				*used_up = FALSE;
2393 				p_ptr->using_up_item = item;
2394 				ident = TRUE;
2395 				break;
2396 
2397 			case SV_SCROLL_LIGHT:
2398 				if (lite_area(Ind, damroll(2, 8), 2)) ident = TRUE;
2399 				//if (p_ptr->suscep_lite && !p_ptr->resist_lite)
2400 				if (p_ptr->prace == RACE_VAMPIRE && !p_ptr->resist_lite)
2401 					take_hit(Ind, damroll(10, 3), o_ptr ? "a Scroll of Light" : "a flash of light", 0);
2402                         	//if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind)
2403 				if (p_ptr->prace == RACE_VAMPIRE && !p_ptr->resist_lite && !p_ptr->resist_blind)
2404 					(void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
2405 				break;
2406 
2407 			case SV_SCROLL_MAPPING:
2408 				map_area(Ind);
2409 				ident = TRUE;
2410 				break;
2411 
2412 			case SV_SCROLL_DETECT_GOLD:
2413 				if (detect_treasure(Ind, DEFAULT_RADIUS * 2)) ident = TRUE;
2414 				break;
2415 
2416 			case SV_SCROLL_DETECT_ITEM:
2417 				if (detect_object(Ind, DEFAULT_RADIUS * 3)) ident = TRUE;
2418 				break;
2419 
2420 			case SV_SCROLL_DETECT_TRAP:
2421 				if (detect_trap(Ind, DEFAULT_RADIUS)) ident = TRUE;
2422 				break;
2423 
2424 			case SV_SCROLL_DETECT_DOOR:
2425 				if (detect_sdoor(Ind, DEFAULT_RADIUS)) ident = TRUE;
2426 				break;
2427 
2428 			case SV_SCROLL_DETECT_INVIS:
2429 				if (detect_invisible(Ind)) ident = TRUE;
2430 				break;
2431 
2432 			case SV_SCROLL_SATISFY_HUNGER:
2433 				//if (!p_ptr->suscep_life)
2434 				if (p_ptr->prace != RACE_VAMPIRE && p_ptr->prace != RACE_ENT) {
2435 					if (set_food(Ind, PY_FOOD_MAX - 1)) ident = TRUE;
2436 				} else
2437 					if (o_ptr) msg_print(Ind, "The scroll has no effect on you.");
2438 				break;
2439 
2440 			case SV_SCROLL_BLESSING:
2441 				if (p_ptr->suscep_good || p_ptr->suscep_life) {
2442 				//if (p_ptr->prace == RACE_VAMPIRE) {
2443 					take_hit(Ind, damroll(5, 3), o_ptr ? "a Scroll of Blessing" : "a blessing", 0);
2444 				} else if (p_ptr->blessed_power <= 8) {
2445 				        p_ptr->blessed_power = 8;
2446 					if (set_blessed(Ind, randint(12) + 6)) ident = TRUE; /* removed stacking */
2447 				}
2448 				break;
2449 
2450 			case SV_SCROLL_HOLY_CHANT:
2451 				if (p_ptr->suscep_good || p_ptr->suscep_life) {
2452 				//if (p_ptr->prace == RACE_VAMPIRE) {
2453 					take_hit(Ind, damroll(10, 3), o_ptr ? "a Scroll of Holy Chant" : "a chant", 0);
2454 				} else if (p_ptr->blessed_power <= 14) {
2455 					p_ptr->blessed_power = 14;
2456 					if (set_blessed(Ind, randint(24) + 12)) ident = TRUE; /* removed stacking */
2457 				}
2458 				break;
2459 
2460 			case SV_SCROLL_HOLY_PRAYER:
2461 				if (p_ptr->suscep_good || p_ptr->suscep_life) {
2462 				//if (p_ptr->prace == RACE_VAMPIRE) {
2463 					take_hit(Ind, damroll(30, 3), o_ptr ? "a Scroll of Holy Prayer" : "a holy prayer", 0);
2464 				} else if (p_ptr->blessed_power <= 20) {
2465 					p_ptr->blessed_power = 20;
2466 					if (set_blessed(Ind, randint(48) + 24)) ident = TRUE; /* removed stacking */
2467 				}
2468 				break;
2469 
2470 			case SV_SCROLL_MONSTER_CONFUSION:
2471 				if (p_ptr->confusing == 0) {
2472 					msg_print(Ind, "Your hands begin to glow.");
2473 					p_ptr->confusing = TRUE;
2474 					ident = TRUE;
2475 				}
2476 				break;
2477 
2478 			case SV_SCROLL_PROTECTION_FROM_EVIL:
2479 				if (p_ptr->suscep_good || p_ptr->suscep_life) {
2480 				//if (p_ptr->prace == RACE_VAMPIRE) {
2481 					take_hit(Ind, damroll(10, 3), o_ptr ? "a Scroll of Protection from Evil" : "evil-repelling magic", 0);
2482 				} else {
2483 					if (set_protevil(Ind, randint(15) + 30)) ident = TRUE; /* removed stacking */
2484 				}
2485 				break;
2486 
2487 			case SV_SCROLL_RUNE_OF_PROTECTION:
2488 				warding_glyph(Ind);
2489 				ident = TRUE;
2490 				break;
2491 
2492 			case SV_SCROLL_TRAP_DOOR_DESTRUCTION:
2493 				if (destroy_doors_touch(Ind, 1)) ident = TRUE;
2494 				break;
2495 
2496 			case SV_SCROLL_STAR_DESTRUCTION:
2497 				destroy_area(&p_ptr->wpos, p_ptr->py, p_ptr->px, 15, TRUE, FEAT_FLOOR, 120);
2498 				ident = TRUE;
2499 				break;
2500 
2501 			case SV_SCROLL_DISPEL_UNDEAD:
2502 				if (dispel_undead(Ind, 100 + p_ptr->lev * 8)) ident = TRUE;
2503 				//if (p_ptr->suscep_life)
2504 				if (p_ptr->prace == RACE_VAMPIRE)
2505 					take_hit(Ind, damroll(30, 3), o_ptr ? "a Scroll of Dispel Undead" : "undead-dispelling magic", 0);
2506 				break;
2507 
2508 			case SV_SCROLL_GENOCIDE:
2509 				if (o_ptr) msg_print(Ind, "This is a genocide scroll.");
2510 				(void)genocide(Ind);
2511 				ident = TRUE;
2512 				break;
2513 
2514 			case SV_SCROLL_OBLITERATION:
2515 				if (o_ptr) msg_print(Ind, "This is a obliteration scroll.");
2516 				(void)obliteration(Ind);
2517 				ident = TRUE;
2518 				break;
2519 
2520 			case SV_SCROLL_ACQUIREMENT:
2521 			{
2522 				int obj_tmp = object_level;
2523 				if (!o_ptr) break;
2524 
2525 				object_level = getlevel(&p_ptr->wpos);
2526 				if (o_ptr->discount == 100) object_discount = 100; /* stolen? */
2527 			        s_printf("%s: ACQ_SCROLL: by player %s\n", showtime(), p_ptr->name);
2528 				acquirement(&p_ptr->wpos, p_ptr->py, p_ptr->px, 1, TRUE, (p_ptr->wpos.wz != 0), make_resf(p_ptr));
2529 				object_discount = 0;
2530 				object_level = obj_tmp; /*just paranoia, dunno if needed.*/
2531 				ident = TRUE;
2532 				break;
2533 			}
2534 
2535 			case SV_SCROLL_STAR_ACQUIREMENT:
2536 			{
2537 				int obj_tmp = object_level;
2538 				if (!o_ptr) break;
2539 
2540 				object_level = getlevel(&p_ptr->wpos);
2541 				if (o_ptr->discount == 100) object_discount = 100; /* stolen? */
2542 			        s_printf("%s: *ACQ_SCROLL*: by player %s\n", showtime(), p_ptr->name);
2543 				acquirement(&p_ptr->wpos, p_ptr->py, p_ptr->px, randint(2) + 1, TRUE, (p_ptr->wpos.wz != 0), make_resf(p_ptr));
2544 				object_discount = 0;
2545 				object_level = obj_tmp; /*just paranoia, dunno if needed.*/
2546 				ident = TRUE;
2547 				break;
2548 			}
2549 
2550 			/* New Zangband scrolls */
2551 			case SV_SCROLL_FIRE:
2552 				sprintf(p_ptr->attacker, " is enveloped by fire for");
2553 				fire_ball(Ind, GF_FIRE, 0, 200, 4, p_ptr->attacker);
2554 				/* Note: "Double" damage since it is centered on the player ... */
2555 				if (!(p_ptr->oppose_fire || p_ptr->resist_fire || p_ptr->immune_fire))
2556 					//                                take_hit(Ind, 50+randint(50)+(p_ptr->suscep_fire)?20:0, "a Scroll of Fire", 0);
2557 					take_hit(Ind, 100 + randint(100), o_ptr ? "a Scroll of Fire" : "fire", 0);
2558 				ident = TRUE;
2559 				break;
2560 
2561 			case SV_SCROLL_ICE:
2562 				sprintf(p_ptr->attacker, " enveloped by frost for");
2563 				fire_ball(Ind, GF_ICE, 0, 200, 4, p_ptr->attacker);
2564 				if (!(p_ptr->oppose_cold || p_ptr->resist_cold || p_ptr->immune_cold))
2565 					take_hit(Ind, 100 + randint(100), o_ptr ? "a Scroll of Ice" : "ice", 0);
2566 				ident = TRUE;
2567 				break;
2568 
2569 			case SV_SCROLL_CHAOS:
2570 				sprintf(p_ptr->attacker, " is enveloped by raw chaos for");
2571 #if 0 // GF_CHAOS == teleporting/polymorphing stuff around...
2572 				fire_ball(Ind, GF_CHAOS, 0, 500, 4, p_ptr->attacker);
2573 #else
2574 				call_chaos(Ind, 0, 0);
2575 #endif
2576 				if (!p_ptr->resist_chaos)
2577 					take_hit(Ind, 111+randint(111), o_ptr ? "a Scroll of Chaos" : "chaos", 0);
2578 				ident = TRUE;
2579 				break;
2580 
2581 			case SV_SCROLL_RUMOR:
2582 				if (o_ptr) msg_print(Ind, "You read the scroll:");
2583 				fortune(Ind, magik(40) ? TRUE : FALSE);
2584 				ident = TRUE;
2585 				break;
2586 
2587 			case SV_SCROLL_LOTTERY:
2588 				if (!o_ptr) break;
2589 
2590 				do_lottery(Ind, o_ptr);
2591 				ident = TRUE;
2592 				break;
2593 
2594 #if 0	// implement them whenever you feel like :)
2595 			case SV_SCROLL_BACCARAT:
2596 			case SV_SCROLL_BLACK_JACK:
2597 			case SV_SCROLL_ROULETTE:
2598 			case SV_SCROLL_SLOT_MACHINE:
2599 			case SV_SCROLL_BACK_GAMMON:
2600 				break;
2601 #endif	// 0
2602 
2603 			case SV_SCROLL_ID_ALL:
2604 				identify_pack(Ind);
2605 				break;
2606 
2607 			case SV_SCROLL_VERMIN_CONTROL:
2608 				if (do_vermin_control(Ind)) ident = TRUE;
2609 				break;
2610 
2611 			case SV_SCROLL_NOTHING:
2612 				if (o_ptr) msg_print(Ind, "This scroll seems to be blank.");
2613 				ident = TRUE;
2614 				*keep = TRUE;
2615 				break;
2616 
2617 			case SV_SCROLL_CANCELLATION:
2618 				ident = do_cancellation(Ind, 0);
2619 				if (ident) msg_print(Ind, "You feel your backpack less worthy.");
2620 				break;
2621 
2622 			case SV_SCROLL_WILDERNESS_MAP:
2623 			{
2624 #ifndef NEW_WILDERNESS_MAP_SCROLLS
2625 				/* Reveal a random dungeon location (C. Blue): */
2626 				int x, y, d_tries, d_no;
2627 				dungeon_type *d_ptr;
2628 				if (rand_int(100) < 50) {
2629 				    x = 0;
2630 				    /* first dungeon (d_tries = 0) is always 'wildernis'
2631 				    -> ignore it by skipping to d_tries = 1: */
2632 				    for (d_tries = 1; d_tries < MAX_D_IDX; d_tries++) {
2633 					if (d_info[d_tries].name) x++;
2634 				    }
2635 				    d_no = randint(x);
2636 				    y = 0;
2637 				    for (d_tries = 1; d_tries < MAX_D_IDX; d_tries++) {
2638 					if (d_info[d_tries].name) y++;
2639 					if (y == d_no) {
2640 					    d_no = d_tries;
2641 					    d_tries = MAX_D_IDX;
2642 					}
2643 				    }
2644 
2645 				    if (!strcmp(d_info[d_no].name + d_name, "The Shores of Valinor")) break;
2646 
2647 				    d_tries = 0;
2648 				    for (y = 0; y < MAX_WILD_Y; y++)
2649 				    for (x = 0; x < MAX_WILD_X; x++) {
2650 					if (d_tries == 0) {
2651 					    if ((d_ptr = wild_info[y][x].tower)) {
2652 				    		if (d_ptr->type == d_no) {
2653 					    	    d_tries = 1;
2654 						    if (o_ptr) msg_format(Ind, "\377sThe scroll carries an inscription: %s at %d , %d", d_info[d_no].name + d_name, x, y);
2655 						}
2656 				    	    }
2657 					    if ((d_ptr = wild_info[y][x].dungeon)) {
2658 				    		if (d_ptr->type == d_no) {
2659 						    d_tries = 1;
2660 						    if (o_ptr) msg_format(Ind, "\377sThe scroll carries an inscription: %s at %d , %d", d_info[d_no].name + d_name, x, y);
2661 						}
2662 				    	    }
2663 					}
2664 				    }
2665 				}
2666 
2667 				if (p_ptr->wpos.wz) {
2668 					msg_print(Ind, "You have a strange feeling of loss.");
2669 					break;
2670 				}
2671 				ident = reveal_wilderness_around_player(Ind,
2672 						p_ptr->wpos.wy, p_ptr->wpos.wx, 0, 3);
2673 				//if (ident) wild_display_map(Ind);
2674 				if (ident) msg_print(Ind, "You seem to get a feel for the place.");
2675 #else
2676 				/* Reveal a random part of the world map, and give a message if it means we discovered a dungeon - C. Blue */
2677 				int x = rand_int(MAX_WILD_X), y = rand_int(MAX_WILD_Y);
2678 				wilderness_type *wild = &wild_info[y][x];
2679 				dungeon_type *d_ptr;
2680 
2681 				if (p_ptr->wild_map[(x + y * MAX_WILD_X) / 8] &
2682 				    (1 << (x + y * MAX_WILD_X) % 8)) {
2683 					msg_format(Ind, "\377sThis world map piece shows the layout at \377u(%d,%d)\377s which you already know.", x, y);
2684 					break;
2685 				}
2686 
2687 				p_ptr->wild_map[(x + y * MAX_WILD_X) / 8] |= (1 << ((x + y * MAX_WILD_X) % 8));
2688 				msg_format(Ind, "\377sYou learn the world map layout at sector \377u(%d,%d)\377s.", x, y);
2689 
2690 				if ((d_ptr = wild->tower)) {
2691 					msg_print(Ind, "\377sYou learn that there is a tower at that location, called:");
2692 					msg_format(Ind, "\377s  '\377u%s\377s'", get_dun_name(x, y, TRUE, d_ptr, 0, TRUE));
2693 				}
2694 				if ((d_ptr = wild->dungeon)) {
2695 					msg_print(Ind, "\377sYou learn that there is a dungeon at that location, called:");
2696 					msg_format(Ind, "\377s  '\377u%s\377s'", get_dun_name(x, y, FALSE, d_ptr, 0, TRUE));
2697 				}
2698 #endif
2699 				break;
2700 			}
2701 
2702 		}
2703 	} else if (tval == TV_PARCHMENT) {
2704 #if 0
2705 		/* Maps */
2706 		if (sval >= 200) {
2707 			int i, n;
2708 			char buf[80], fil[20];
2709 
2710 			strnfmt(fil, 20, "book-%d.txt",o_ptr->sval);
2711 
2712 			n = atoi(get_line(fil, ANGBAND_DIR_FILE, buf, -1));
2713 
2714 			/* Parse all the fields */
2715 			for (i = 0; i < n; i += 4) {
2716 				/* Grab the fields */
2717 				int x = atoi(get_line(fil, ANGBAND_DIR_FILE, buf, i + 0));
2718 				int y = atoi(get_line(fil, ANGBAND_DIR_FILE, buf, i + 1));
2719 				int w = atoi(get_line(fil, ANGBAND_DIR_FILE, buf, i + 2));
2720 				int h = atoi(get_line(fil, ANGBAND_DIR_FILE, buf, i + 3));
2721 
2722 				reveal_wilderness_around_player(y, x, h, w);
2723 			}
2724 		}
2725 
2726 		/* Normal parchments */
2727 		else
2728 #endif	// 0
2729 		{
2730 			/* Get the filename */
2731 			char    path[MAX_PATH_LENGTH];
2732 			cptr q = format("book-%d.txt", sval);
2733 
2734 			path_build(path, MAX_PATH_LENGTH, ANGBAND_DIR_TEXT, q);
2735 			do_cmd_check_other_prepare(Ind, path, "");
2736 
2737 //			*used_up = FALSE;
2738 			*keep = TRUE;
2739 		}
2740 	}
2741 	return ident;
2742 }
2743 
2744 /*
2745  * NOTE: seemingly, 'used_up' flag is used in a strange way to allow
2746  * item specification.  'keep' flag should be used for non-consuming
2747  * scrolls instead.		- Jir -
2748  */
2749 void do_cmd_read_scroll(int Ind, int item) {
2750 	player_type *p_ptr = Players[Ind];
2751 	//cave_type * c_ptr;
2752 
2753 	int	ident, lev;
2754 	bool	used_up, keep = FALSE, flipped = FALSE;
2755 
2756 	object_type	*o_ptr;
2757 
2758 
2759 	/* Check some conditions */
2760 	if (p_ptr->blind) {
2761 		msg_print(Ind, "You can't see anything.");
2762 		s_printf("%s EFFECT: Blind prevented scroll for %s.\n", showtime(), p_ptr->name);
2763 		return;
2764 	}
2765 	if (p_ptr->confused) {
2766 		msg_print(Ind, "You are too confused!");
2767 		s_printf("%s EFFECT: Confusion prevented scroll for %s.\n", showtime(), p_ptr->name);
2768 		return;
2769 	}
2770 
2771 	/* Restrict choices to scrolls */
2772 	item_tester_tval = TV_SCROLL;
2773 
2774 	/* Get the item (in the pack) */
2775 	if (item >= 0) {
2776 		o_ptr = &p_ptr->inventory[item];
2777 	}
2778 	/* Get the item (on the floor) */
2779 	else {
2780 		if (-item >= o_max)
2781 			return; /* item doesn't exist */
2782 
2783 		o_ptr = &o_list[0 - item];
2784 	}
2785 
2786 	if (no_lite(Ind) && !(p_ptr->ghost && (o_ptr->tval == TV_PARCHMENT) && (o_ptr->sval == SV_PARCHMENT_DEATH)))
2787 	{
2788 		msg_print(Ind, "You have no light to read by.");
2789 		s_printf("%s EFFECT: No-light prevented scroll for %s.\n", showtime(), p_ptr->name);
2790 		return;
2791 	}
2792 
2793 	if( check_guard_inscription( o_ptr->note, 'r' )) {
2794 		msg_print(Ind, "The item's inscription prevents it.");
2795 		s_printf("%s EFFECT: Inscription prevented scroll for %s.\n", showtime(), p_ptr->name);
2796 		return;
2797 	};
2798 
2799 	if (o_ptr->tval != TV_SCROLL && o_ptr->tval != TV_PARCHMENT) {
2800 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to read non-scroll!");
2801 		return;
2802 	}
2803 
2804 	if (!can_use_verbose(Ind, o_ptr)) return;
2805 
2806 #ifdef PLAYER_STORES
2807 	/* Reading a cheque gives the money and costs no time. */
2808 	if (o_ptr->tval == TV_SCROLL && o_ptr->sval == SV_SCROLL_CHEQUE) {
2809 		u32b value = ps_get_cheque_value(o_ptr);
2810 
2811 		/* hack: prevent s32b overflow */
2812 		if (!gain_au(Ind, value, FALSE, FALSE)) return;
2813 
2814 		break_cloaking(Ind, 4);
2815 		break_shadow_running(Ind);
2816 		stop_precision(Ind);
2817 		stop_shooting_till_kill(Ind);
2818 
2819 		msg_format(Ind, "\375\377sYou acquire \377y%d\377s gold pieces.", value);
2820 s_printf("PLAYER_STORE_CASH: %s +%d (%s).\n", p_ptr->name, value, o_ptr->note ? quark_str(o_ptr->note) : "");
2821 
2822 
2823 		p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2824 		p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2825 
2826 		if (item >= 0) { /* Destroy scroll in the pack */
2827 			inven_item_increase(Ind, item, -1);
2828 			inven_item_describe(Ind, item);
2829 			inven_item_optimize(Ind, item);
2830 		} else { /* Destroy scroll on the floor */
2831 			floor_item_increase(0 - item, -1);
2832 			floor_item_describe(0 - item);
2833 			floor_item_optimize(0 - item);
2834 		}
2835 		return;
2836 	}
2837 #endif
2838 
2839 #if 0
2840 	/* unbelievers need some more disadvantage, but this might be too much */
2841 	antichance = p_ptr->antimagic / 4;
2842 	if (antichance > ANTIMAGIC_CAP) antichance = ANTIMAGIC_CAP;/* AM cap */
2843 	/* Got disrupted ? */
2844 	if (magik(antichance)) {
2845 		msg_print(Ind, "Your anti-magic field disrupts the scroll.");
2846 	        return;
2847 	}
2848 #endif
2849 
2850 	/* S(he) is no longer afk */
2851 	un_afk_idle(Ind);
2852 
2853 	/* Take a turn */
2854 	p_ptr->energy -= level_speed(&p_ptr->wpos);
2855 
2856 	/* Not identified yet */
2857 	ident = FALSE;
2858 
2859 	/* Object level */
2860 	lev = k_info[o_ptr->k_idx].level;
2861 
2862 	process_hooks(HOOK_READ, "d", Ind);
2863 
2864 	/* Assume the scroll will get used up */
2865 	used_up = TRUE;
2866 
2867 #ifdef USE_SOUND_2010
2868 	sound(Ind, "read_scroll", NULL, SFX_TYPE_COMMAND, FALSE);
2869 #endif
2870 
2871 	ident = read_scroll(Ind, o_ptr->tval, o_ptr->sval, o_ptr, item, &used_up, &keep);
2872 
2873 	break_cloaking(Ind, 4);
2874 	break_shadow_running(Ind);
2875 	stop_precision(Ind);
2876 	stop_shooting_till_kill(Ind);
2877 
2878 	/* Combine / Reorder the pack (later) */
2879 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2880 
2881 	/* An identification was made */
2882 	if (ident && !object_aware_p(Ind, o_ptr)) {
2883 		flipped = object_aware(Ind, o_ptr);
2884 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2885 	}
2886 
2887 	/* The item was tried */
2888 	object_tried(Ind, o_ptr, flipped);
2889 
2890 	/* Window stuff */
2891 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2892 
2893 
2894 	/* Hack -- really allow certain scrolls to be "preserved" */
2895 	if (keep) return;
2896 
2897 	if (true_artifact_p(o_ptr)) handle_art_d(o_ptr->name1);
2898 	questitem_d(o_ptr, 1);
2899 
2900 	/* Destroy a scroll in the pack */
2901 	if (item >= 0) {
2902 		inven_item_increase(Ind, item, -1);
2903 
2904 		/* Hack -- allow certain scrolls to be "preserved" */
2905 		if (!used_up) return;
2906 
2907 		inven_item_describe(Ind, item);
2908 		inven_item_optimize(Ind, item);
2909 	}
2910 	/* Destroy a scroll on the floor */
2911 	else {
2912 		floor_item_increase(0 - item, -1);
2913 		floor_item_describe(0 - item);
2914 		floor_item_optimize(0 - item);
2915 	}
2916 }
2917 
2918 
2919 
2920 bool use_staff(int Ind, int sval, int rad, bool msg, bool *use_charge) {
2921 	player_type *p_ptr = Players[Ind];
2922 	bool ident = FALSE;
2923 	int k;
2924 
2925 	/* Analyze the staff */
2926 	switch (sval) {
2927 		case SV_STAFF_DARKNESS:
2928 		{
2929 			if (unlite_area(Ind, 10, 3)) ident = TRUE;
2930 			if (!p_ptr->resist_blind && !p_ptr->resist_dark)
2931 			{
2932 				if (set_blind(Ind, p_ptr->blind + 3 + randint(5) - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 3))) ident = TRUE;
2933 			}
2934 			break;
2935 		}
2936 
2937 		case SV_STAFF_SLOWNESS:
2938 		{
2939 			if (set_slow(Ind, p_ptr->slow + randint(30) + 15 - get_skill_scale(p_ptr, SKILL_DEVICE, 15))) ident = TRUE;
2940 			break;
2941 		}
2942 
2943 		case SV_STAFF_HASTE_MONSTERS:
2944 		{
2945 			if (speed_monsters(Ind)) ident = TRUE;
2946 			break;
2947 		}
2948 
2949 		case SV_STAFF_SUMMONING:
2950 		{
2951 			if(!check_self_summon(p_ptr)) break;
2952 			//logfile spam- s_printf("SUMMON_SPECIFIC: %s\n", p_ptr->name);
2953 			summon_override_checks = SO_IDDC | SO_PLAYER_SUMMON;
2954 			for (k = 0; k < randint(4); k++) {
2955 				if (summon_specific(&p_ptr->wpos, p_ptr->py, p_ptr->px, getlevel(&p_ptr->wpos), 0, SUMMON_ALL_U98, 1, 0))
2956 					ident = TRUE;
2957 			}
2958 			summon_override_checks = SO_NONE;
2959 			break;
2960 		}
2961 
2962 		case SV_STAFF_TELEPORTATION:
2963 		{
2964 			if (teleport_player(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 100), FALSE))
2965 				msg_format_near(Ind, msg ? "%s teleports away!" : "%s is teleported away!", p_ptr->name);
2966 			ident = TRUE;
2967 			break;
2968 		}
2969 
2970 		case SV_STAFF_IDENTIFY:
2971 		{
2972 			if (!ident_spell(Ind)) *use_charge = FALSE;
2973 			ident = TRUE;
2974 			break;
2975 		}
2976 
2977 		case SV_STAFF_REMOVE_CURSE:
2978 #ifndef NEW_REMOVE_CURSE
2979 			if (remove_curse(Ind)) {
2980 				if (!p_ptr->blind) {
2981 					if (msg) msg_print(Ind, "The staff glows blue for a moment...");
2982 					msg_print(Ind, "There is a blue glow for a moment...");
2983 				}
2984 #else
2985 			if (remove_curse_aux(Ind, 0x0, 0)) {
2986 #endif
2987 				ident = TRUE;
2988 			}
2989 			break;
2990 
2991 		case SV_STAFF_STARLITE:
2992 		{
2993 			if (!p_ptr->blind)
2994 			{
2995 				if (msg) msg_print(Ind, "The end of the staff glows brightly...");
2996 				else msg_print(Ind, "A bright light appear...");
2997 			}
2998 			for (k = 0; k < 8; k++) lite_line(Ind, ddd[k], damroll(9, 8) + get_skill_scale(p_ptr, SKILL_DEVICE, 100));
2999 			if (p_ptr->suscep_lite) take_hit(Ind, damroll((p_ptr->resist_lite ? 10: 30), 3), msg ? "a staff of starlight" : "starlight", 0);
3000                     	if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind) (void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
3001 			ident = TRUE;
3002 			break;
3003 		}
3004 
3005 		case SV_STAFF_LITE:
3006 		{
3007 			if (msg) msg_format_near(Ind, "%s calls light.", p_ptr->name);
3008 			else msg_format_near(Ind, "A light appears.", p_ptr->name);
3009 			if (lite_area(Ind, damroll(2 + get_skill_scale(p_ptr, SKILL_DEVICE, 10), 8), 2)) ident = TRUE;
3010 			if (p_ptr->suscep_lite && !p_ptr->resist_lite) take_hit(Ind, damroll(20, 3), msg ? "a staff of Light" : "light", 0);
3011                     	if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind) (void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
3012 			break;
3013 		}
3014 
3015 		case SV_STAFF_MAPPING:
3016 		{
3017 			map_area(Ind);
3018 			ident = TRUE;
3019 			break;
3020 		}
3021 
3022 		case SV_STAFF_DETECT_GOLD:
3023 		{
3024 			if (detect_treasure(Ind, rad * 2)) ident = TRUE;
3025 			break;
3026 		}
3027 
3028 		case SV_STAFF_DETECT_ITEM:
3029 		{
3030 			if (detect_object(Ind, rad * 3)) ident = TRUE;
3031 			break;
3032 		}
3033 
3034 		case SV_STAFF_DETECT_TRAP:
3035 		{
3036 			if (detect_trap(Ind, rad)) ident = TRUE;
3037 			break;
3038 		}
3039 
3040 		case SV_STAFF_DETECT_DOOR:
3041 		{
3042 			if (detect_sdoor(Ind, rad)) ident = TRUE;
3043 			break;
3044 		}
3045 
3046 		case SV_STAFF_DETECT_INVIS:
3047 		{
3048 			if (detect_invisible(Ind)) ident = TRUE;
3049 			break;
3050 		}
3051 
3052 		case SV_STAFF_DETECT_EVIL:
3053 		{
3054 			if (detect_evil(Ind)) ident = TRUE;
3055 			break;
3056 		}
3057 
3058 		case SV_STAFF_CURE_SERIOUS:
3059 		{
3060 //			if (hp_player(Ind, randint(8 + get_skill_scale(p_ptr, SKILL_DEVICE, 10)))) ident = TRUE;
3061 			/* Turned it into 'Cure Serious Wounds' - C. Blue */
3062 			if (set_blind(Ind, 0)) ident = TRUE;
3063 			if (set_confused(Ind, 0)) ident = TRUE;
3064 			if (set_cut(Ind, (p_ptr->cut / 2) - 50, p_ptr->cut_attacker)) ident = TRUE;
3065 			if (hp_player(Ind, damroll(6 + get_skill_scale(p_ptr, SKILL_DEVICE, 9), 8))) ident = TRUE;
3066 			break;
3067 		}
3068 
3069 		case SV_STAFF_CURING:
3070 		{
3071 			if (set_image(Ind, 0)) ident = TRUE;
3072 			if (set_blind(Ind, 0)) ident = TRUE;
3073 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
3074 			if (set_confused(Ind, 0)) ident = TRUE;
3075 			if (set_stun(Ind, 0)) ident = TRUE;
3076 			if (set_cut(Ind, 0, 0)) ident = TRUE;
3077 			if (p_ptr->food >= PY_FOOD_MAX)
3078 			if (set_food(Ind, PY_FOOD_MAX - 1)) ident = TRUE;
3079 			break;
3080 		}
3081 
3082 		case SV_STAFF_HEALING:
3083 		{
3084 			if (hp_player(Ind, 250 + get_skill_scale(p_ptr, SKILL_DEVICE, 150))) ident = TRUE;
3085 			if (set_stun(Ind, 0)) ident = TRUE;
3086 			if (set_cut(Ind, 0, 0)) ident = TRUE;
3087 			break;
3088 		}
3089 
3090 		case SV_STAFF_THE_MAGI:
3091 		{
3092 			if (do_res_stat(Ind, A_INT)) ident = TRUE;
3093 			if (p_ptr->csp < p_ptr->msp)
3094 			{
3095 				p_ptr->csp += 500;
3096 				if (p_ptr->csp > p_ptr->msp) p_ptr->csp = p_ptr->msp;
3097 				p_ptr->csp_frac = 0;
3098 				ident = TRUE;
3099 				msg_print(Ind, "You feel your head clearing.");
3100 				p_ptr->redraw |= (PR_MANA);
3101 				p_ptr->window |= (PW_PLAYER);
3102 			}
3103 			break;
3104 		}
3105 
3106 		case SV_STAFF_SLEEP_MONSTERS:
3107 		{
3108 			if (sleep_monsters(Ind, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3109 			break;
3110 		}
3111 
3112 		case SV_STAFF_SLOW_MONSTERS:
3113 		{
3114 			if (slow_monsters(Ind, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3115 			break;
3116 		}
3117 
3118 		case SV_STAFF_SPEED:
3119 		{
3120 			if (set_fast(Ind, randint(30) + 15 + get_skill_scale(p_ptr, SKILL_DEVICE, 10), 10)) ident = TRUE; /* removed stacking */
3121 			break;
3122 		}
3123 
3124 		case SV_STAFF_PROBING:
3125 		{
3126 			probing(Ind);
3127 			ident = TRUE;
3128 			break;
3129 		}
3130 
3131 		case SV_STAFF_DISPEL_EVIL:
3132 		{
3133 			if (dispel_evil(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 300) + p_ptr->lev * 2)) ident = TRUE;
3134 			if (p_ptr->suscep_good) {
3135 				take_hit(Ind, damroll(30, 3), msg ? "a staff of dispel evil" : "evil-dispelling magic", 0);
3136 				ident = TRUE;
3137 			}
3138 			break;
3139 		}
3140 
3141 		case SV_STAFF_POWER:
3142 		{
3143 			if (dispel_monsters(Ind, 200 + get_skill_scale(p_ptr, SKILL_DEVICE, 300))) ident = TRUE;
3144 			break;
3145 		}
3146 
3147 		case SV_STAFF_HOLINESS:
3148 		{
3149 			if (dispel_evil(Ind, 200 + get_skill_scale(p_ptr, SKILL_DEVICE, 300))) ident = TRUE;
3150 			if (p_ptr->suscep_good || p_ptr->suscep_life) {
3151 				take_hit(Ind, damroll(50, 3), msg ? "a staff of holiness" : "holy aura", 0);
3152 				ident = TRUE;
3153 			} else {
3154 				k = get_skill_scale(p_ptr, SKILL_DEVICE, 25);
3155 				if (set_protevil(Ind, randint(15) + 30 + k)) ident = TRUE; /* removed stacking */
3156 				if (set_poisoned(Ind, 0, 0)) ident = TRUE;
3157 				if (set_afraid(Ind, 0)) ident = TRUE;
3158 				if (hp_player(Ind, 50)) ident = TRUE;
3159 				if (set_stun(Ind, 0)) ident = TRUE;
3160 				if (set_cut(Ind, 0, 0)) ident = TRUE;
3161 			}
3162 			break;
3163 		}
3164 
3165 		case SV_STAFF_GENOCIDE:
3166 		{
3167 			(void)genocide(Ind);
3168 			ident = TRUE;
3169 			break;
3170 		}
3171 
3172 		case SV_STAFF_EARTHQUAKES:
3173 		{
3174 			if (msg) msg_format_near(Ind, "%s causes the ground to shake!", p_ptr->name);
3175 			else msg_print_near(Ind, "The ground starts to shake!");
3176 			earthquake(&p_ptr->wpos, p_ptr->py, p_ptr->px, 10);
3177 			ident = TRUE;
3178 			break;
3179 		}
3180 
3181 		case SV_STAFF_DESTRUCTION:
3182 		{
3183 			if (msg) msg_format_near(Ind, "%s unleashes great power!", p_ptr->name);
3184 			else msg_print_near(Ind, "Great power is unleashed!");
3185 			destroy_area(&p_ptr->wpos, p_ptr->py, p_ptr->px, 15, TRUE, FEAT_FLOOR, 120);
3186 			ident = TRUE;
3187 			break;
3188 		}
3189 
3190 		case SV_STAFF_STAR_IDENTIFY:
3191 		{
3192 			if (!identify_fully(Ind)) *use_charge = FALSE;
3193 			ident = TRUE;
3194 			break;
3195 		}
3196 	}
3197 
3198 	return ident;
3199 }
3200 
3201 /*
3202  * Use a staff.			-RAK-
3203  *
3204  * One charge of one staff disappears.
3205  *
3206  * Hack -- staffs of identify can be "cancelled".
3207  */
3208 void do_cmd_use_staff(int Ind, int item)
3209 {
3210 	player_type *p_ptr = Players[Ind];
3211 	int lev, ident, rad = DEFAULT_RADIUS_DEV(p_ptr);
3212 	object_type *o_ptr;
3213 
3214 	/* Hack -- let staffs of identify get aborted */
3215 	bool use_charge = TRUE, flipped = FALSE;
3216 
3217 	/* Break goi/manashield */
3218 #if 0
3219 	if (p_ptr->invuln)
3220 		set_invuln(Ind, 0);
3221 	if (p_ptr->tim_manashield)
3222 		set_tim_manashield(Ind, 0);
3223 	if (p_ptr->tim_wraith)
3224 		set_tim_wraith(Ind, 0);
3225 #endif	// 0
3226 
3227 
3228 #if 1
3229 	if (p_ptr->anti_magic) {
3230 		msg_format(Ind, "\377%cYour anti-magic shell disrupts your attempt.", COLOUR_AM_OWN);
3231 		return;
3232 	}
3233 #endif
3234 	if (get_skill(p_ptr, SKILL_ANTIMAGIC)) {
3235 		msg_format(Ind, "\377%cYou don't believe in magic.", COLOUR_AM_OWN);
3236 		return;
3237 	}
3238         if (magik((p_ptr->antimagic * 8) / 5)) {
3239                 msg_format(Ind, "\377%cYour anti-magic field disrupts your attempt.", COLOUR_AM_OWN);
3240                 return;
3241         }
3242 
3243 	/* Restrict choices to wands */
3244 	item_tester_tval = TV_STAFF;
3245 
3246 	/* Get the item (in the pack) */
3247 	if (item >= 0) o_ptr = &p_ptr->inventory[item];
3248 	/* Get the item (on the floor) */
3249 	else {
3250 		if (-item >= o_max)
3251 			return; /* item doesn't exist */
3252 
3253 		o_ptr = &o_list[0 - item];
3254 	}
3255 
3256 	if( check_guard_inscription( o_ptr->note, 'u' )) {
3257                 msg_print(Ind, "The item's inscription prevents it.");
3258                 return;
3259         };
3260 
3261 	if (o_ptr->tval != TV_STAFF) {
3262 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to use non-staff!");
3263 		return;
3264 	}
3265 
3266         if (!can_use_verbose(Ind, o_ptr)) return;
3267 
3268 	/* Mega-Hack -- refuse to use a pile from the ground */
3269 	if ((item < 0) && (o_ptr->number > 1)) {
3270 		msg_print(Ind, "You must first pick up the staffs.");
3271 		return;
3272 	}
3273 
3274 	/* Verify potential overflow */
3275 	/*if ((inven_cnt >= INVEN_PACK) &&
3276 	    (o_ptr->number > 1))
3277 	{*/
3278 		/* Verify with the player */
3279 		/*if (other_query_flag &&
3280 		    !get_check("Your pack might overflow.  Continue? ")) return;
3281 	}*/
3282 
3283 	/* S(he) is no longer afk */
3284 	un_afk_idle(Ind);
3285 
3286 	/* Take a turn */
3287 	p_ptr->energy -= level_speed(&p_ptr->wpos);
3288 
3289 	/* Not identified yet */
3290 	ident = FALSE;
3291 
3292 	if (!activate_magic_device(Ind, o_ptr)) {
3293 		msg_format(Ind, "\377%cYou failed to use the staff properly." , COLOUR_MD_FAIL);
3294 		return;
3295 	}
3296 
3297 	/* Notice empty staffs */
3298 	if (o_ptr->pval <= 0) {
3299 		msg_print(Ind, "The staff has no charges left.");
3300 		o_ptr->ident |= ID_EMPTY;
3301 
3302 		/* Redraw */
3303 		o_ptr->changed = !o_ptr->changed;
3304 		p_ptr->window |= (PW_INVEN);
3305 
3306 		return;
3307 	}
3308 
3309 	ident = use_staff(Ind, o_ptr->sval, rad, TRUE, &use_charge);
3310 
3311 	/* Combine / Reorder the pack (later) */
3312 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3313 
3314 	/* Extract the item level */
3315 	lev = k_info[o_ptr->k_idx].level;
3316 
3317 	/* An identification was made */
3318 	if (ident && !object_aware_p(Ind, o_ptr)) {
3319 		flipped = object_aware(Ind, o_ptr);
3320 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3321 	}
3322 
3323 	/* Tried the item */
3324 	object_tried(Ind, o_ptr, flipped);
3325 
3326 	/* Window stuff */
3327 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3328 
3329 	break_cloaking(Ind, 4);
3330 	break_shadow_running(Ind);
3331 	stop_precision(Ind);
3332 	stop_shooting_till_kill(Ind);
3333 
3334 	/* Hack -- some uses are "free" */
3335 	if (!use_charge) return;
3336 
3337 
3338 	/* Use a single charge */
3339 	o_ptr->pval--;
3340 
3341 	/* XXX Hack -- unstack if necessary */
3342 	if ((item >= 0) && (o_ptr->number > 1))
3343 	{
3344 		/* Make a fake item */
3345 		object_type tmp_obj;
3346 		tmp_obj = *o_ptr;
3347 		tmp_obj.number = 1;
3348 
3349 		/* Restore the charges */
3350 		o_ptr->pval++;
3351 
3352 		/* Unstack the used item */
3353 		o_ptr->number--;
3354 		p_ptr->total_weight -= tmp_obj.weight;
3355 		item = inven_carry(Ind, &tmp_obj);
3356 
3357 		/* Message */
3358 		msg_print(Ind, "You unstack your staff.");
3359 	}
3360 
3361 	/* Describe charges in the pack */
3362 	if (item >= 0)
3363 	{
3364 		inven_item_charges(Ind, item);
3365 	}
3366 
3367 	/* Describe charges on the floor */
3368 	else
3369 	{
3370 		floor_item_charges(0 - item);
3371 	}
3372 }
3373 
3374 
3375 /*
3376  * Aim a wand (from the pack or floor).
3377  *
3378  * Use a single charge from a single item.
3379  * Handle "unstacking" in a logical manner.
3380  *
3381  * For simplicity, you cannot use a stack of items from the
3382  * ground.  This would require too much nasty code.
3383  *
3384  * There are no wands which can "destroy" themselves, in the inventory
3385  * or on the ground, so we can ignore this possibility.  Note that this
3386  * required giving "wand of wonder" the ability to ignore destruction
3387  * by electric balls.
3388  *
3389  * All wands can be "cancelled" at the "Direction?" prompt for free.
3390  *
3391  * Note that the basic "bolt" wands do slightly less damage than the
3392  * basic "bolt" rods, but the basic "ball" wands do the same damage
3393  * as the basic "ball" rods.
3394  */
3395 void do_cmd_aim_wand(int Ind, int item, int dir)
3396 {
3397 	player_type *p_ptr = Players[Ind];
3398 	int lev, ident, sval;
3399 	object_type *o_ptr;
3400 	bool flipped = FALSE;
3401 
3402 	/* Break goi/manashield */
3403 #if 0
3404 	if (p_ptr->invuln) set_invuln(Ind, 0);
3405 	if (p_ptr->tim_manashield) set_tim_manashield(Ind, 0);
3406 	if (p_ptr->tim_wraith) set_tim_wraith(Ind, 0);
3407 #endif	// 0
3408 
3409 #if 1	// anti_magic is not antimagic :)
3410 	if (p_ptr->anti_magic) {
3411 		msg_format(Ind, "\377%cYour anti-magic shell disrupts your attempt.", COLOUR_AM_OWN);
3412 		return;
3413 	}
3414 #endif	// 0
3415 	if (get_skill(p_ptr, SKILL_ANTIMAGIC)) {
3416 		msg_format(Ind, "\377%cYou don't believe in magic.", COLOUR_AM_OWN);
3417 		return;
3418 	}
3419         if (magik((p_ptr->antimagic * 8) / 5)) {
3420                 msg_format(Ind, "\377%cYour anti-magic field disrupts your attempt.", COLOUR_AM_OWN);
3421                 return;
3422         }
3423 
3424 	/* Restrict choices to wands */
3425 	item_tester_tval = TV_WAND;
3426 
3427 	/* Get the item (in the pack) */
3428 	if (item >= 0) o_ptr = &p_ptr->inventory[item];
3429 	/* Get the item (on the floor) */
3430 	else {
3431 		if (-item >= o_max) return; /* item doesn't exist */
3432 		o_ptr = &o_list[0 - item];
3433 	}
3434 	if( check_guard_inscription( o_ptr->note, 'a' )) {
3435                 msg_print(Ind, "The item's inscription prevents it.");
3436                 return;
3437         };
3438 
3439 	if (o_ptr->tval != TV_WAND) {
3440 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to use non-wand!");
3441 		return;
3442 	}
3443 
3444         if (!can_use_verbose(Ind, o_ptr)) return;
3445 
3446 	/* Mega-Hack -- refuse to aim a pile from the ground */
3447 	if ((item < 0) && (o_ptr->number > 1)) {
3448 		msg_print(Ind, "You must first pick up the wands.");
3449 		return;
3450 	}
3451 
3452 	/* Hack -- verify potential overflow */
3453 	/*if ((inven_cnt >= INVEN_PACK) &&
3454 	    (o_ptr->number > 1))
3455 	{*/
3456 		/* Verify with the player */
3457 	/*	if (other_query_flag &&
3458 		    !get_check("Your pack might overflow.  Continue? ")) return;
3459 	}*/
3460 
3461 
3462 	/* New '+' feat in 4.4.6.2 */
3463 	if (dir == 11) {
3464 		get_aim_dir(Ind);
3465 		p_ptr->current_wand = item;
3466 		return;
3467 	}
3468 
3469 
3470 	/* S(he) is no longer afk */
3471 	un_afk_idle(Ind);
3472 
3473 	/* Take a turn */
3474 	p_ptr->energy -= level_speed(&p_ptr->wpos);
3475 
3476 	/* Not identified yet */
3477 	ident = FALSE;
3478 
3479 	if (!activate_magic_device(Ind, o_ptr)) {
3480 		msg_format(Ind, "\377%cYou failed to use the wand properly." , COLOUR_MD_FAIL);
3481 		return;
3482 	}
3483 
3484 	/* The wand is already empty! */
3485 	if (o_ptr->pval <= 0) {
3486 		msg_print(Ind, "The wand has no charges left.");
3487 		o_ptr->ident |= ID_EMPTY;
3488 
3489 		/* Redraw */
3490 		o_ptr->changed = !o_ptr->changed;
3491 		p_ptr->window |= (PW_INVEN);
3492 
3493 		return;
3494 	}
3495 
3496 
3497 
3498 	/* XXX Hack -- Extract the "sval" effect */
3499 	sval = o_ptr->sval;
3500 
3501 	/* XXX Hack -- Wand of wonder can do anything before it */
3502 	if (sval == SV_WAND_WONDER) {
3503 		sval = rand_int(SV_WAND_WONDER);
3504 		/* limit wand of wonder damage in Highlander Tournament */
3505 		if (!p_ptr->wpos.wx && !p_ptr->wpos.wy && !p_ptr->wpos.wz && sector00separation) {
3506 			/* no high wand effects for cheap mass zapping in PvP */
3507 			sval = rand_int(SV_WAND_WONDER - 8 - 2);
3508 			if (sval >= SV_WAND_DRAIN_LIFE) sval += 2;
3509 		}
3510 	}
3511 
3512 	/* Analyze the wand */
3513 	switch (sval % 1000)
3514 	{
3515 		case SV_WAND_HEAL_MONSTER:
3516 		{
3517 			if (heal_monster(Ind, dir)) ident = TRUE;
3518 			break;
3519 		}
3520 
3521 		case SV_WAND_HASTE_MONSTER:
3522 		{
3523 			if (speed_monster(Ind, dir)) ident = TRUE;
3524 			break;
3525 		}
3526 
3527 		case SV_WAND_CLONE_MONSTER:
3528 		{
3529 			if (clone_monster(Ind, dir)) ident = TRUE;
3530 			break;
3531 		}
3532 
3533 		case SV_WAND_TELEPORT_AWAY:
3534 		{
3535 			if (teleport_monster(Ind, dir)) ident = TRUE;
3536 			break;
3537 		}
3538 
3539 		case SV_WAND_DISARMING:
3540 		{
3541 			if (disarm_trap(Ind, dir)) ident = TRUE;
3542 			break;
3543 		}
3544 
3545 		case SV_WAND_TRAP_DOOR_DEST:
3546 		{
3547 			if (destroy_door(Ind, dir)) ident = TRUE;
3548 			break;
3549 		}
3550 
3551 		case SV_WAND_STONE_TO_MUD:
3552 		{
3553 			if (wall_to_mud(Ind, dir)) ident = TRUE;
3554 			break;
3555 		}
3556 
3557 		case SV_WAND_LITE:
3558 		{
3559 			msg_print(Ind, "A line of blue shimmering light appears.");
3560 			lite_line(Ind, dir, damroll(6, 8) + get_skill_scale(p_ptr, SKILL_DEVICE, 50));
3561 			ident = TRUE;
3562 			break;
3563 		}
3564 
3565 		case SV_WAND_SLEEP_MONSTER:
3566 		{
3567 			if (sleep_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3568 			break;
3569 		}
3570 
3571 		case SV_WAND_SLOW_MONSTER:
3572 		{
3573 			if (slow_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3574 			break;
3575 		}
3576 
3577 		case SV_WAND_CONFUSE_MONSTER:
3578 		{
3579 			if (confuse_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3580 			break;
3581 		}
3582 
3583 		case SV_WAND_FEAR_MONSTER:
3584 		{
3585 			if (fear_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3586 			break;
3587 		}
3588 
3589 		case SV_WAND_DRAIN_LIFE:
3590 		{
3591 			if (drain_life(Ind, dir, 10 + get_skill_scale(p_ptr, SKILL_DEVICE, 10))) {
3592 				ident = TRUE;
3593 				hp_player(Ind, p_ptr->ret_dam / 4);
3594 				p_ptr->ret_dam = 0;
3595 			}
3596 			break;
3597 		}
3598 
3599 		case SV_WAND_POLYMORPH:
3600 		{
3601 			if (poly_monster(Ind, dir)) ident = TRUE;
3602 			break;
3603 		}
3604 
3605 		case SV_WAND_STINKING_CLOUD:
3606 		{
3607 			msg_format_near(Ind, "%s fires a stinking cloud.", p_ptr->name);
3608 			sprintf(p_ptr->attacker, " fires a stinking cloud for");
3609 //			fire_ball(Ind, GF_POIS, dir, 12 + get_skill_scale(p_ptr, SKILL_DEVICE, 50), 2, p_ptr->attacker);
3610 			fire_cloud(Ind, GF_POIS, dir, 4 + get_skill_scale(p_ptr, SKILL_DEVICE, 17), 2, 4, 9, p_ptr->attacker);
3611 			ident = TRUE;
3612 			break;
3613 		}
3614 
3615 		case SV_WAND_MAGIC_MISSILE:
3616 		{
3617 			msg_format_near(Ind, "%s fires a magic missile.", p_ptr->name);
3618 			sprintf(p_ptr->attacker, " fires a magic missile for");
3619 			fire_bolt_or_beam(Ind, 20, GF_MISSILE, dir, damroll(2 + get_skill_scale(p_ptr, SKILL_DEVICE, 10), 6), p_ptr->attacker);
3620 			ident = TRUE;
3621 			break;
3622 		}
3623 
3624 		case SV_WAND_ACID_BOLT:
3625 		{
3626 			msg_format_near(Ind, "%s fires an acid bolt.", p_ptr->name);
3627 			sprintf(p_ptr->attacker, " fires an acid bolt for");
3628 			fire_bolt_or_beam(Ind, 20, GF_ACID, dir, damroll(5 + get_skill_scale(p_ptr, SKILL_DEVICE, 13), 8), p_ptr->attacker);
3629 			ident = TRUE;
3630 			break;
3631 		}
3632 
3633 		case SV_WAND_ELEC_BOLT:
3634 		{
3635 			msg_format_near(Ind, "%s fires a lightning bolt.", p_ptr->name);
3636 			sprintf(p_ptr->attacker, " fires a lightning bolt for");
3637 			fire_bolt_or_beam(Ind, 20, GF_ELEC, dir, damroll(5 + get_skill_scale(p_ptr, SKILL_DEVICE, 11), 8), p_ptr->attacker);
3638 			ident = TRUE;
3639 			break;
3640 		}
3641 
3642 		case SV_WAND_FIRE_BOLT:
3643 		{
3644 			msg_format_near(Ind, "%s fires a fire bolt.", p_ptr->name);
3645 			sprintf(p_ptr->attacker, " fires a fire bolt for");
3646 			fire_bolt_or_beam(Ind, 20, GF_FIRE, dir, damroll(5 + get_skill_scale(p_ptr, SKILL_DEVICE, 14), 8), p_ptr->attacker);
3647 			ident = TRUE;
3648 			break;
3649 		}
3650 
3651 		case SV_WAND_COLD_BOLT:
3652 		{
3653 			msg_format_near(Ind, "%s fires a frost bolt.", p_ptr->name);
3654 			sprintf(p_ptr->attacker, " fires a frost bolt for");
3655 			fire_bolt_or_beam(Ind, 20, GF_COLD, dir, damroll(5 + get_skill_scale(p_ptr, SKILL_DEVICE, 12), 8), p_ptr->attacker);
3656 			ident = TRUE;
3657 			break;
3658 		}
3659 
3660 		case SV_WAND_ACID_BALL:
3661 		{
3662 			msg_format_near(Ind, "%s fires a ball of acid.", p_ptr->name);
3663 			sprintf(p_ptr->attacker, " fires a ball of acid for");
3664 			fire_ball(Ind, GF_ACID, dir, 60 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 2, p_ptr->attacker);
3665 			ident = TRUE;
3666 			break;
3667 		}
3668 
3669 		case SV_WAND_ELEC_BALL:
3670 		{
3671 			msg_format_near(Ind, "%s fires a ball of electricity.", p_ptr->name);
3672 			sprintf(p_ptr->attacker, " fires a ball of electricity for");
3673 			fire_ball(Ind, GF_ELEC, dir, 40 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 2, p_ptr->attacker);
3674 			ident = TRUE;
3675 			break;
3676 		}
3677 
3678 		case SV_WAND_FIRE_BALL:
3679 		{
3680 			msg_format_near(Ind, "%s fires a fire ball.", p_ptr->name);
3681 			sprintf(p_ptr->attacker, " fires a fire ball for");
3682 			fire_ball(Ind, GF_FIRE, dir, 70 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 2, p_ptr->attacker);
3683 			ident = TRUE;
3684 			break;
3685 		}
3686 
3687 		case SV_WAND_COLD_BALL:
3688 		{
3689 			msg_format_near(Ind, "%s fires a frost ball.", p_ptr->name);
3690 			sprintf(p_ptr->attacker, " fires a frost ball for");
3691 			fire_ball(Ind, GF_COLD, dir, 50 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 2, p_ptr->attacker);
3692 			ident = TRUE;
3693 			break;
3694 		}
3695 
3696 		case SV_WAND_WONDER:
3697 		{
3698 			msg_print(Ind, "SERVER ERROR: Oops.  Wand of wonder activated.");
3699 			break;
3700 		}
3701 
3702 		case SV_WAND_DRAGON_FIRE:
3703 		{
3704 			msg_format_near(Ind, "%s shoots dragon fire!", p_ptr->name);
3705 			sprintf(p_ptr->attacker, " shoots dragon fire for");
3706 			fire_ball(Ind, GF_FIRE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3707 			ident = TRUE;
3708 			break;
3709 		}
3710 
3711 		case SV_WAND_DRAGON_COLD:
3712 		{
3713 			msg_format_near(Ind, "%s shoots dragon frost!", p_ptr->name);
3714 			sprintf(p_ptr->attacker, " shoots dragon frost for");
3715 			fire_ball(Ind, GF_COLD, dir, 320 + get_skill_scale(p_ptr, SKILL_DEVICE, 320), 3, p_ptr->attacker);
3716 			ident = TRUE;
3717 			break;
3718 		}
3719 
3720 		case SV_WAND_DRAGON_BREATH:
3721 		{
3722 			switch (randint(5))
3723 			{
3724 				case 1:
3725 					{
3726 						msg_format_near(Ind, "%s shoots dragon acid!", p_ptr->name);
3727 						sprintf(p_ptr->attacker, " shoots dragon acid for");
3728 						fire_ball(Ind, GF_ACID, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3729 						break;
3730 					}
3731 
3732 				case 2:
3733 					{
3734 						msg_format_near(Ind, "%s shoots dragon lightning!", p_ptr->name);
3735 						sprintf(p_ptr->attacker, " shoots dragon lightning for");
3736 						fire_ball(Ind, GF_ELEC, dir, 320 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3737 						break;
3738 					}
3739 
3740 				case 3:
3741 					{
3742 						msg_format_near(Ind, "%s shoots dragon fire!", p_ptr->name);
3743 						sprintf(p_ptr->attacker, " shoots dragon fire for");
3744 						fire_ball(Ind, GF_FIRE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3745 						break;
3746 					}
3747 
3748 				case 4:
3749 					{
3750 						msg_format_near(Ind, "%s shoots dragon frost!", p_ptr->name);
3751 						sprintf(p_ptr->attacker, " shoots dragon frost for");
3752 						fire_ball(Ind, GF_COLD, dir, 320 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3753 						break;
3754 					}
3755 
3756 				default:
3757 					{
3758 						msg_format_near(Ind, "%s shoots dragon poison!", p_ptr->name);
3759 						sprintf(p_ptr->attacker, " shoots dragon poison for");
3760 						fire_ball(Ind, GF_POIS, dir, 240 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 3, p_ptr->attacker);
3761 						break;
3762 					}
3763 			}
3764 
3765 			ident = TRUE;
3766 			break;
3767 		}
3768 
3769 		case SV_WAND_ANNIHILATION:
3770 		{
3771 			if (annihilate(Ind, dir, 15 + get_skill_scale(p_ptr, SKILL_DEVICE, 10))) {
3772 				ident = TRUE;
3773 			}
3774 			break;
3775 		}
3776 
3777 		/* Additions from PernAngband	- Jir - */
3778 		case SV_WAND_ROCKETS:
3779 		{
3780 			msg_print(Ind, "You launch a rocket!");
3781 			sprintf(p_ptr->attacker, " launches a rocket for");
3782 			fire_ball(Ind, GF_ROCKET, dir, 600 + (randint(100) + get_skill_scale(p_ptr, SKILL_DEVICE, 600)), 2, p_ptr->attacker);
3783 			ident = TRUE;
3784 			break;
3785 		}
3786 #if 0
3787 		/* Hope we can port this someday.. */
3788 		case SV_WAND_CHARM_MONSTER:
3789 		{
3790 			if (charm_monster(dir, 45))
3791 				ident = TRUE;
3792 			break;
3793 		}
3794 
3795 #endif	// 0
3796 
3797 		case SV_WAND_WALL_CREATION:
3798 		{
3799 			project_hook(Ind, GF_STONE_WALL, dir, 1, PROJECT_NORF | PROJECT_BEAM | PROJECT_KILL | PROJECT_GRID, "");
3800 			ident = TRUE;
3801 			break;
3802 		}
3803 
3804 		/* TomeNET addition */
3805 		case SV_WAND_TELEPORT_TO:
3806 		{
3807 			ident = project_hook(Ind, GF_TELE_TO, dir, 1, PROJECT_STOP | PROJECT_KILL, "");
3808 			break;
3809 		}
3810 
3811 	}
3812 
3813 
3814 	/* Combine / Reorder the pack (later) */
3815 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3816 
3817 	break_cloaking(Ind, 3);
3818 	break_shadow_running(Ind);
3819 	stop_precision(Ind);
3820 	stop_shooting_till_kill(Ind);
3821 
3822 	/* Extract the item level */
3823 	lev = k_info[o_ptr->k_idx].level;
3824 
3825 	/* Apply identification */
3826 	if (ident && !object_aware_p(Ind, o_ptr))
3827 	{
3828 		flipped = object_aware(Ind, o_ptr);
3829 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3830 	}
3831 
3832 	/* Mark it as tried */
3833 	object_tried(Ind, o_ptr, flipped);
3834 
3835 	/* Window stuff */
3836 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3837 
3838 
3839 	/* Use a single charge */
3840 	o_ptr->pval--;
3841 
3842 	/* Describe the charges in the pack */
3843 	if (item >= 0)
3844 	{
3845 		inven_item_charges(Ind, item);
3846 	}
3847 
3848 	/* Describe the charges on the floor */
3849 	else
3850 	{
3851 		floor_item_charges(0 - item);
3852 	}
3853 }
3854 
3855 
3856 bool zap_rod(int Ind, int sval, int rad, object_type *o_ptr, bool *use_charge) {
3857 	player_type *p_ptr = Players[Ind];
3858 	bool ident = FALSE;
3859 
3860 	/* Analyze the rod */
3861 	switch (sval) {
3862 		case SV_ROD_DETECT_TRAP:
3863 		{
3864 			if (detect_trap(Ind, rad)) ident = TRUE;
3865 			//if (o_ptr) o_ptr->pval = 50;
3866 			/* up to 50% faster with maxed MD - the_sandman */
3867 			o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
3868 			break;
3869 		}
3870 
3871 		case SV_ROD_DETECT_DOOR:
3872 		{
3873 			if (detect_sdoor(Ind, rad)) ident = TRUE;
3874 			//if (o_ptr) o_ptr->pval = 70;
3875 			/* up to 50% faster with maxed MD - the_sandman */
3876 			if (o_ptr) o_ptr->pval = 70 - get_skill_scale(p_ptr, SKILL_DEVICE, 35);
3877 			break;
3878 		}
3879 
3880 		case SV_ROD_IDENTIFY:
3881 		{
3882 			ident = TRUE;
3883 			if (!ident_spell(Ind)) use_charge = FALSE;
3884 			//if (o_ptr) o_ptr->pval = 10;
3885 			/* up to 50% faster with maxed MD - the_sandman */
3886 //at 0 skill, this is like auto-id	if (o_ptr) o_ptr->pval = 10 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 5);
3887 			if (o_ptr) o_ptr->pval = 55 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 50);
3888 			break;
3889 		}
3890 
3891 		case SV_ROD_RECALL:
3892 		{
3893 			if (!o_ptr) break;
3894 
3895 			set_recall(Ind, rand_int(20) + 15, o_ptr);
3896 			ident = TRUE;
3897 			//o_ptr->pval = 60;
3898 			/* up to a 50% faster with maxed MD - the_sandman */
3899 			o_ptr->pval = 60 - get_skill_scale(p_ptr, SKILL_DEVICE, 30);
3900 			break;
3901 		}
3902 
3903 		case SV_ROD_ILLUMINATION:
3904 		{
3905 			if (o_ptr) msg_format_near(Ind, "%s calls light.", p_ptr->name);
3906 			else msg_print_near(Ind, "A light appears.");
3907 			if (lite_area(Ind, damroll(2, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 50)), 2)) ident = TRUE;
3908 			if (p_ptr->suscep_lite && !p_ptr->resist_lite) take_hit(Ind, damroll(10, 3), "a rod of illumination", 0);
3909 			if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind) (void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
3910 			//if (o_ptr) o_ptr->pval = 30;
3911 			/* up to a 50% faster with maxed MD - the_sandman */
3912 			if (o_ptr) o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
3913 			break;
3914 		}
3915 
3916 		case SV_ROD_MAPPING:
3917 		{
3918 			map_area(Ind);
3919 			ident = TRUE;
3920 			//if (o_ptr) o_ptr->pval = 99;
3921 			/* up to a 50% faster with maxed MD - the_sandman */
3922 			if (o_ptr) o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
3923 			break;
3924 		}
3925 
3926 		case SV_ROD_DETECTION:
3927 		{
3928 			detection(Ind, rad);
3929 			ident = TRUE;
3930 			//if (o_ptr) o_ptr->pval = 99;
3931 			/* up to a 50% faster with maxed MD - the_sandman */
3932 			if (o_ptr) o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
3933 			break;
3934 		}
3935 
3936 		case SV_ROD_PROBING:
3937 		{
3938 			probing(Ind);
3939 			ident = TRUE;
3940 			//if (o_ptr) o_ptr->pval = 50;
3941 			/* up to a 50% faster with maxed MD - the_sandman */
3942 			if (o_ptr) o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
3943 			break;
3944 		}
3945 
3946 		case SV_ROD_CURING:
3947 		{
3948 			if (set_image(Ind, 0)) ident = TRUE;
3949 			if (set_blind(Ind, 0)) ident = TRUE;
3950 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
3951 			if (set_confused(Ind, 0)) ident = TRUE;
3952 			if (set_stun(Ind, 0)) ident = TRUE;
3953 			if (set_cut(Ind, 0, 0)) ident = TRUE;
3954 			if (p_ptr->food >= PY_FOOD_MAX)
3955 			if (set_food(Ind, PY_FOOD_MAX - 1)) ident = TRUE;
3956 			if (o_ptr) o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 20);
3957 			break;
3958 		}
3959 
3960 		case SV_ROD_HEALING:
3961 		{
3962 //scale moar!		if (hp_player(Ind, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
3963 			if (hp_player(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 300))) ident = TRUE;
3964 			if (set_stun(Ind, 0)) ident = TRUE;
3965 			if (set_cut(Ind, 0, 0)) ident = TRUE;
3966 //a bit too much?	if (o_ptr) o_ptr->pval = 10 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 7);
3967 			if (o_ptr) o_ptr->pval = 15 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 5);
3968 			break;
3969 		}
3970 
3971 		case SV_ROD_RESTORATION:
3972 		{
3973 			if (restore_level(Ind)) ident = TRUE;
3974 			if (do_res_stat(Ind, A_STR)) ident = TRUE;
3975 			if (do_res_stat(Ind, A_INT)) ident = TRUE;
3976 			if (do_res_stat(Ind, A_WIS)) ident = TRUE;
3977 			if (do_res_stat(Ind, A_DEX)) ident = TRUE;
3978 			if (do_res_stat(Ind, A_CON)) ident = TRUE;
3979 			if (do_res_stat(Ind, A_CHR)) ident = TRUE;
3980 			if (o_ptr) o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);//adjusted it here too..
3981 			break;
3982 		}
3983 
3984 		case SV_ROD_SPEED:
3985 		{
3986 			if (set_fast(Ind, randint(30) + 15, 10)) ident = TRUE; /* removed stacking */
3987 			if (o_ptr) o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
3988 			break;
3989 		}
3990 
3991 		case SV_ROD_NOTHING:
3992 		{
3993 			break;
3994 		}
3995 
3996 		default:
3997 		{
3998 			msg_print(Ind, "SERVER ERROR: Directional rod zapped in non-directional function!");
3999 			return FALSE;
4000 		}
4001 	}
4002 
4003 	return ident;
4004 }
4005 
4006 /*
4007  * Activate (zap) a Rod
4008  *
4009  * Unstack fully charged rods as needed.
4010  *
4011  * Hack -- rods of perception/genocide can be "cancelled"
4012  * All rods can be cancelled at the "Direction?" prompt
4013  */
4014 void do_cmd_zap_rod(int Ind, int item, int dir) {
4015 	player_type *p_ptr = Players[Ind];
4016 	int lev, ident, rad = DEFAULT_RADIUS_DEV(p_ptr);
4017 	object_type *o_ptr;
4018 	u32b f4, dummy;
4019 
4020 	/* Hack -- let perception get aborted */
4021 	bool use_charge = TRUE, flipped = FALSE;
4022 
4023 	/* Break goi/manashield */
4024 #if 0
4025 	if (p_ptr->invuln)
4026 		set_invuln(Ind, 0);
4027 	if (p_ptr->tim_manashield)
4028 		set_tim_manashield(Ind, 0);
4029 	if (p_ptr->tim_wraith)
4030 		set_tim_wraith(Ind, 0);
4031 #endif	// 0
4032 
4033 
4034 #if 1
4035 	if (p_ptr->anti_magic) {
4036 		msg_format(Ind, "\377%cYour anti-magic shell disrupts your attempt.", COLOUR_AM_OWN);
4037 		return;
4038 	}
4039 #endif	// 0
4040 	if (get_skill(p_ptr, SKILL_ANTIMAGIC)) {
4041 		msg_format(Ind, "\377%cYou don't believe in magic.", COLOUR_AM_OWN);
4042 		return;
4043 	}
4044         if (magik((p_ptr->antimagic * 8) / 5)) {
4045                 msg_format(Ind, "\377%cYour anti-magic field disrupts your attempt.", COLOUR_AM_OWN);
4046                 return;
4047         }
4048 
4049 	/* Restrict choices to rods */
4050 	item_tester_tval = TV_ROD;
4051 
4052 	/* Get the item (in the pack) */
4053 	if (item >= 0)
4054 		o_ptr = &p_ptr->inventory[item];
4055 	/* Get the item (on the floor) */
4056 	else {
4057 		if (-item >= o_max)
4058 			return; /* item doesn't exist */
4059 
4060 		o_ptr = &o_list[0 - item];
4061 	}
4062 	if (check_guard_inscription(o_ptr->note, 'z')) {
4063                 msg_print(Ind, "The item's inscription prevents it.");
4064                 return;
4065         };
4066 
4067 
4068 	if (o_ptr->tval != TV_ROD) {
4069 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to zap non-rod!");
4070 		return;
4071 	}
4072 
4073 	/* Mega-Hack -- refuse to zap a pile from the ground */
4074 	if ((item < 0) && (o_ptr->number > 1)) {
4075 		msg_print(Ind, "You must first pick up the rods.");
4076 		return;
4077 	}
4078 
4079         if (!can_use_verbose(Ind, o_ptr)) return;
4080 
4081 	/* Get a direction (unless KNOWN not to need it) */
4082 	/* Pfft, dirty, dirty, diiirrrrtie!! (FIXME) */
4083 	if (rod_requires_direction(Ind, o_ptr)) {
4084 		if (dir != 0 && dir != 11) {
4085 		//redundant: lower versions cant have dir != 0. ---  && is_newer_than(&p_ptr->version, 4, 4, 5, 10, 0, 0)) {
4086 			p_ptr->current_rod = item;
4087 			do_cmd_zap_rod_dir(Ind, dir);
4088 			return;
4089 		}
4090 
4091 		/* Get a direction, then return */
4092 		p_ptr->current_rod = item;
4093 		get_aim_dir(Ind);
4094 		return;
4095 	}
4096 
4097 	/* Extract object flags */
4098 	object_flags(o_ptr, &dummy, &dummy, &dummy, &f4, &dummy, &dummy, &dummy);
4099 
4100 	/* S(he) is no longer afk */
4101 	un_afk_idle(Ind);
4102 
4103 	/* Take a turn */
4104 	p_ptr->energy -= level_speed(&p_ptr->wpos) /
4105 	        ((f4 & TR4_FAST_CAST)?2:1);
4106 
4107 	/* Not identified yet */
4108 	ident = FALSE;
4109 
4110 	if (!activate_magic_device(Ind, o_ptr)) {
4111 		msg_format(Ind, "\377%cYou failed to use the rod properly." , COLOUR_MD_FAIL);
4112 		return;
4113 	}
4114 
4115 	/* Still charging */
4116 	if (o_ptr->pval) {
4117 		msg_print(Ind, "The rod is still charging.");
4118 		return;
4119 	}
4120 
4121 	process_hooks(HOOK_ZAP, "d", Ind);
4122 
4123 	ident = zap_rod(Ind, o_ptr->sval, rad, o_ptr, &use_charge);
4124 
4125 	if (f4 & TR4_CHARGING) o_ptr->pval /= 2;
4126 
4127 	break_cloaking(Ind, 3);
4128 	break_shadow_running(Ind);
4129 	stop_precision(Ind);
4130 	stop_shooting_till_kill(Ind);
4131 
4132 	/* Combine / Reorder the pack (later) */
4133 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
4134 
4135 	/* Extract the item level */
4136 	lev = k_info[o_ptr->k_idx].level;
4137 
4138 	/* Successfully determined the object function */
4139 	if (ident && !object_aware_p(Ind, o_ptr))
4140 	{
4141 		flipped = object_aware(Ind, o_ptr);
4142 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
4143 	}
4144 
4145 	/* Tried the object */
4146 	object_tried(Ind, o_ptr, flipped);
4147 
4148 	/* Window stuff */
4149 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
4150 
4151 	/* Hack -- deal with cancelled zap */
4152 	if (!use_charge)
4153 	{
4154 		o_ptr->pval = 0;
4155 		return;
4156 	}
4157 
4158 
4159 	/* XXX Hack -- unstack if necessary */
4160 	if ((item >= 0) && (o_ptr->number > 1))
4161 	{
4162 		/* Make a fake item */
4163 		object_type tmp_obj;
4164 		tmp_obj = *o_ptr;
4165 		tmp_obj.number = 1;
4166 
4167 		/* Restore "charge" */
4168 		o_ptr->pval = 0;
4169 
4170 		/* Unstack the used item */
4171 		o_ptr->number--;
4172 		p_ptr->total_weight -= tmp_obj.weight;
4173 		item = inven_carry(Ind, &tmp_obj);
4174 
4175 		/* Message */
4176 		msg_print(Ind, "You unstack your rod.");
4177 	}
4178 }
4179 
4180 
4181 
4182 /*
4183  * Activate (zap) a Rod that requires a direction (passed through to here from do_cmd_zap_rod())
4184  *
4185  * Unstack fully charged rods as needed.
4186  *
4187  * Hack -- rods of perception/genocide can be "cancelled"
4188  * All rods can be cancelled at the "Direction?" prompt
4189  */
4190 void do_cmd_zap_rod_dir(int Ind, int dir)
4191 {
4192 	player_type *p_ptr = Players[Ind];
4193 	int lev, item, ident, rad = DEFAULT_RADIUS_DEV(p_ptr);
4194 	object_type *o_ptr;
4195 	u32b f4, dummy;
4196 	/* Hack -- let perception get aborted */
4197 	bool use_charge = TRUE, flipped = FALSE;
4198 
4199 	item = p_ptr->current_rod;
4200 
4201 	/* Get the item (in the pack) */
4202 	if (item >= 0) {
4203 		o_ptr = &p_ptr->inventory[item];
4204 	}
4205 	/* Get the item (on the floor) */
4206 	else {
4207 		if (-item >= o_max)
4208 			return; /* item doesn't exist */
4209 
4210 		o_ptr = &o_list[0 - item];
4211 	}
4212 	if (check_guard_inscription( o_ptr->note, 'z')) {
4213                 msg_print(Ind, "The item's inscription prevents it.");
4214                 return;
4215         };
4216 
4217 	if (o_ptr->tval != TV_ROD) {
4218 //(may happen on death, from macro spam)		msg_print(Ind, "SERVER ERROR: Tried to zap non-rod!");
4219 		return;
4220 	}
4221 
4222 	/* Mega-Hack -- refuse to zap a pile from the ground */
4223 	if ((item < 0) && (o_ptr->number > 1)) {
4224 		msg_print(Ind, "You must first pick up the rods.");
4225 		return;
4226 	}
4227 
4228         if (!can_use_verbose(Ind, o_ptr)) return;
4229 
4230 	/* Hack -- verify potential overflow */
4231 	/*if ((inven_cnt >= INVEN_PACK) &&
4232 	    (o_ptr->number > 1))
4233 	{*/
4234 		/* Verify with the player */
4235 		/*if (other_query_flag &&
4236 		    !get_check("Your pack might overflow.  Continue? ")) return;
4237 	}*/
4238 
4239 	/* Extract object flags */
4240 	object_flags(o_ptr, &dummy, &dummy, &dummy, &f4, &dummy, &dummy, &dummy);
4241 
4242 
4243 	/* S(he) is no longer afk */
4244 	un_afk_idle(Ind);
4245 
4246 	/* Take a turn */
4247 	p_ptr->energy -= level_speed(&p_ptr->wpos) /
4248 	        ((f4 & TR4_FAST_CAST)?2:1);
4249 
4250 	/* Not identified yet */
4251 	ident = FALSE;
4252 
4253 	/* Roll for usage */
4254 	if (!activate_magic_device(Ind, o_ptr)) {
4255 		msg_format(Ind, "\377%cYou failed to use the rod properly." , COLOUR_MD_FAIL);
4256 		return;
4257 	}
4258 
4259 	/* Still charging */
4260 	if (o_ptr->pval) {
4261 		msg_print(Ind, "The rod is still charging.");
4262 		return;
4263 	}
4264 
4265 	process_hooks(HOOK_ZAP, "d", Ind);
4266 
4267 	/* Analyze the rod */
4268 	switch (o_ptr->sval) {
4269 		case SV_ROD_TELEPORT_AWAY:
4270 		{
4271 			if (teleport_monster(Ind, dir)) ident = TRUE;
4272 			//o_ptr->pval = 25;
4273 			/* up to 50% faster with maxed MD - the_sandman */
4274 			o_ptr->pval = 25 - get_skill_scale(p_ptr, SKILL_DEVICE, 12);
4275 			break;
4276 		}
4277 
4278 		case SV_ROD_DISARMING:
4279 		{
4280 			if (disarm_trap(Ind, dir)) ident = TRUE;
4281 			//o_ptr->pval = 30;
4282 			/* up to 50% faster with maxed MD - the_sandman */
4283 			o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
4284 			break;
4285 		}
4286 
4287 		case SV_ROD_LITE:
4288 		{
4289 			msg_print(Ind, "A line of blue shimmering light appears.");
4290 			lite_line(Ind, dir, damroll(6, 8) + get_skill_scale(p_ptr, SKILL_DEVICE, 50));
4291 			ident = TRUE;
4292 			//o_ptr->pval = 9;
4293 			/* up to 50% faster with maxed MD - the_sandman */
4294 			o_ptr->pval = 9 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 4);
4295 			break;
4296 		}
4297 
4298 		case SV_ROD_SLEEP_MONSTER:
4299 		{
4300 			if (sleep_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
4301 			//o_ptr->pval = 18;
4302 			/* up to 50% faster with maxed MD - the_sandman */
4303 			o_ptr->pval = 18 - get_skill_scale(p_ptr, SKILL_DEVICE, 9);
4304 			break;
4305 		}
4306 
4307 		case SV_ROD_SLOW_MONSTER:
4308 		{
4309 			if (slow_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
4310 			//o_ptr->pval = 20;
4311 			/* up to 50% faster with maxed MD - the_sandman */
4312 			o_ptr->pval = 20 - get_skill_scale(p_ptr, SKILL_DEVICE, 10);
4313 			break;
4314 		}
4315 
4316 		case SV_ROD_DRAIN_LIFE:
4317 		{
4318 			if (drain_life(Ind, dir, 10 + get_skill_scale(p_ptr, SKILL_DEVICE, 10))) {
4319 				ident = TRUE;
4320 				hp_player(Ind, p_ptr->ret_dam / 4);
4321 				p_ptr->ret_dam = 0;
4322 			}
4323 			//o_ptr->pval = 23;
4324 			/* up to 50% faster with maxed MD - the_sandman */
4325 			o_ptr->pval = 23 - get_skill_scale(p_ptr, SKILL_DEVICE, 12);
4326 			break;
4327 		}
4328 
4329 		case SV_ROD_POLYMORPH:
4330 		{
4331 			//todo for IDDC maybe: change all rods to wands (disallow rod drops), if poly should be enabled
4332 			if (poly_monster(Ind, dir)) ident = TRUE;
4333 			//o_ptr->pval = 25;
4334 			/* up to 50% faster with maxed MD - the_sandman */
4335 			o_ptr->pval = 25 - get_skill_scale(p_ptr, SKILL_DEVICE, 12);
4336 			break;
4337 		}
4338 
4339 		case SV_ROD_ACID_BOLT:
4340 		{
4341 			msg_format_near(Ind, "%s fires an acid bolt.", p_ptr->name);
4342 			sprintf(p_ptr->attacker, " fires an acid bolt for");
4343 			fire_bolt_or_beam(Ind, 10, GF_ACID, dir, damroll(6, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 20)) + 20 + get_skill_scale(p_ptr, SKILL_DEVICE, 180), p_ptr->attacker);
4344 			ident = TRUE;
4345 			//o_ptr->pval = 12;
4346 			/* up to 50% faster with maxed MD - the_sandman */
4347 			o_ptr->pval = 12 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 6);
4348 			break;
4349 		}
4350 
4351 		case SV_ROD_ELEC_BOLT:
4352 		{
4353 			msg_format_near(Ind, "%s fires a lightning bolt.", p_ptr->name);
4354 			sprintf(p_ptr->attacker, " fires a lightning bolt for");
4355 			fire_bolt_or_beam(Ind, 10, GF_ELEC, dir, damroll(4, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 20)) + 20 + get_skill_scale(p_ptr, SKILL_DEVICE, 120), p_ptr->attacker);
4356 			ident = TRUE;
4357 			//o_ptr->pval = 11;
4358 			/* up to 50% faster with maxed MD - the_sandman */
4359 			o_ptr->pval = 11 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 5);
4360 			break;
4361 		}
4362 
4363 		case SV_ROD_FIRE_BOLT:
4364 		{
4365 			msg_format_near(Ind, "%s fires a fire bolt.", p_ptr->name);
4366 			sprintf(p_ptr->attacker, " fires a fire bolt for");
4367 			fire_bolt_or_beam(Ind, 10, GF_FIRE, dir, damroll(8, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 20)) + 20 + get_skill_scale(p_ptr, SKILL_DEVICE, 210), p_ptr->attacker);
4368 			ident = TRUE;
4369 			//o_ptr->pval = 15;
4370 			/* up to 50% faster with maxed MD - the_sandman */
4371 			o_ptr->pval = 15 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 7);
4372 			break;
4373 		}
4374 
4375 		case SV_ROD_COLD_BOLT:
4376 		{
4377 			msg_format_near(Ind, "%s fires a frost bolt.", p_ptr->name);
4378 			sprintf(p_ptr->attacker, " fires a frost bolt for");
4379 			fire_bolt_or_beam(Ind, 10, GF_COLD, dir, damroll(5, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 20)) + 20 + get_skill_scale(p_ptr, SKILL_DEVICE, 180), p_ptr->attacker);
4380 			ident = TRUE;
4381 			//o_ptr->pval = 13;
4382 			/* up to 50% faster with maxed MD - the_sandman */
4383 			o_ptr->pval = 13 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 6);
4384 			break;
4385 		}
4386 
4387 		case SV_ROD_ACID_BALL:
4388 		{
4389 			msg_format_near(Ind, "%s fires an acid ball.", p_ptr->name);
4390 			sprintf(p_ptr->attacker, " fires an acid ball for");
4391 			fire_ball(Ind, GF_ACID, dir, 60 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 2, p_ptr->attacker);
4392 			ident = TRUE;
4393 			//o_ptr->pval = 27;
4394 			/* up to 50% faster with maxed MD - the_sandman */
4395 			o_ptr->pval = 27 - get_skill_scale(p_ptr, SKILL_DEVICE, 13);
4396 			break;
4397 		}
4398 
4399 		case SV_ROD_ELEC_BALL:
4400 		{
4401 			msg_format_near(Ind, "%s fires a lightning ball.", p_ptr->name);
4402 			sprintf(p_ptr->attacker, " fires a lightning ball for");
4403 			fire_ball(Ind, GF_ELEC, dir, 32 + get_skill_scale(p_ptr, SKILL_DEVICE, 160), 2, p_ptr->attacker);
4404 			ident = TRUE;
4405 			//o_ptr->pval = 23;
4406 			/* up to 50% faster with maxed MD - the_sandman */
4407 			o_ptr->pval = 23 - get_skill_scale(p_ptr, SKILL_DEVICE, 11);
4408 			break;
4409 		}
4410 
4411 		case SV_ROD_FIRE_BALL:
4412 		{
4413 			msg_format_near(Ind, "%s fires a fire ball.", p_ptr->name);
4414 			sprintf(p_ptr->attacker, " fires a fire ball for");
4415 			fire_ball(Ind, GF_FIRE, dir, 72 + get_skill_scale(p_ptr, SKILL_DEVICE, 360), 2, p_ptr->attacker);
4416 			ident = TRUE;
4417 			//o_ptr->pval = 30;
4418 			/* up to 50% faster with maxed MD - the_sandman */
4419 			o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
4420 			break;
4421 		}
4422 
4423 		case SV_ROD_COLD_BALL:
4424 		{
4425 			msg_format_near(Ind, "%s fires a frost ball.", p_ptr->name);
4426 			sprintf(p_ptr->attacker, " fires a frost ball for");
4427 			fire_ball(Ind, GF_COLD, dir, 48 + get_skill_scale(p_ptr, SKILL_DEVICE, 240), 2, p_ptr->attacker);
4428 			ident = TRUE;
4429 			//o_ptr->pval = 25;
4430 			/* up to 50% faster with maxed MD - the_sandman */
4431 			o_ptr->pval = 25 - get_skill_scale(p_ptr, SKILL_DEVICE, 12);
4432 			break;
4433 		}
4434 
4435 		/* All of the following are needed if we tried zapping one of */
4436 		/* these but we didn't know what it was. */
4437 		case SV_ROD_DETECT_TRAP:
4438 		{
4439 			if (detect_trap(Ind, rad)) ident = TRUE;
4440 			//o_ptr->pval = 50;
4441 			/* up to 50% faster with maxed MD - the_sandman */
4442 			o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
4443 			break;
4444 		}
4445 
4446 		case SV_ROD_DETECT_DOOR:
4447 		{
4448 			if (detect_sdoor(Ind, rad)) ident = TRUE;
4449 			//o_ptr->pval = 70;
4450 			/* up to 50% faster with maxed MD - the_sandman */
4451 			o_ptr->pval = 70 - get_skill_scale(p_ptr, SKILL_DEVICE, 35);
4452 			break;
4453 		}
4454 
4455 		case SV_ROD_IDENTIFY:
4456 		{
4457 			ident = TRUE;
4458 			if (!ident_spell(Ind)) use_charge = FALSE;
4459 			//o_ptr->pval = 10;
4460 			/* up to 50% faster with maxed MD - the_sandman */
4461 //at 0 skill, this is like auto-id	o_ptr->pval = 10 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 5);
4462 			o_ptr->pval = 55 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 50);
4463 			break;
4464 		}
4465 
4466 		case SV_ROD_RECALL:
4467 		{
4468 			set_recall(Ind, rand_int(20) + 15, o_ptr);
4469 			ident = TRUE;
4470 			//o_ptr->pval = 60;
4471 			/* up to a 50% faster with maxed MD - the_sandman */
4472 			o_ptr->pval = 60 - get_skill_scale(p_ptr, SKILL_DEVICE, 30);
4473 			break;
4474 		}
4475 
4476 		case SV_ROD_ILLUMINATION:
4477 		{
4478 			msg_format_near(Ind, "%s calls light.", p_ptr->name);
4479 			if (lite_area(Ind, damroll(2, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 50)), 2)) ident = TRUE;
4480 			if (p_ptr->suscep_lite && !p_ptr->resist_lite) take_hit(Ind, damroll(10, 3), "a rod of illumination", 0);
4481                     	if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind) (void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
4482 			//o_ptr->pval = 30;
4483 			/* up to a 50% faster with maxed MD - the_sandman */
4484 			o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
4485 			break;
4486 		}
4487 
4488 		case SV_ROD_MAPPING:
4489 		{
4490 			map_area(Ind);
4491 			ident = TRUE;
4492 			//o_ptr->pval = 99;
4493 			/* up to a 50% faster with maxed MD - the_sandman */
4494 			o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
4495 			break;
4496 		}
4497 
4498 		case SV_ROD_DETECTION:
4499 		{
4500 			detection(Ind, rad);
4501 			ident = TRUE;
4502 			//o_ptr->pval = 99;
4503 			/* up to a 50% faster with maxed MD - the_sandman */
4504 			o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
4505 			break;
4506 		}
4507 
4508 		case SV_ROD_PROBING:
4509 		{
4510 			probing(Ind);
4511 			ident = TRUE;
4512 			//o_ptr->pval = 50;
4513 			/* up to a 50% faster with maxed MD - the_sandman */
4514 			o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
4515 			break;
4516 		}
4517 
4518 		case SV_ROD_CURING:
4519 		{
4520 			if (set_image(Ind, 0)) ident = TRUE;
4521 			if (set_blind(Ind, 0)) ident = TRUE;
4522 			if (set_poisoned(Ind, 0, 0)) ident = TRUE;
4523 			if (set_confused(Ind, 0)) ident = TRUE;
4524 			if (set_stun(Ind, 0)) ident = TRUE;
4525 			if (set_cut(Ind, 0, 0)) ident = TRUE;
4526 			if (p_ptr->food >= PY_FOOD_MAX)
4527 			if (set_food(Ind, PY_FOOD_MAX - 1)) ident = TRUE;
4528 			o_ptr->pval = 30 - get_skill_scale(p_ptr, SKILL_DEVICE, 20);
4529 			break;
4530 		}
4531 
4532 		case SV_ROD_HEALING:
4533 		{
4534 //scale moar!		if (hp_player(Ind, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 50))) ident = TRUE;
4535 			if (hp_player(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 300))) ident = TRUE;
4536 			if (set_stun(Ind, 0)) ident = TRUE;
4537 			if (set_cut(Ind, 0, 0)) ident = TRUE;
4538 //a bit too much?	o_ptr->pval = 10 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 7);
4539 			o_ptr->pval = 15 - get_skill_scale_fine(p_ptr, SKILL_DEVICE, 5);
4540 			break;
4541 		}
4542 
4543 		case SV_ROD_RESTORATION:
4544 		{
4545 			if (restore_level(Ind)) ident = TRUE;
4546 			if (do_res_stat(Ind, A_STR)) ident = TRUE;
4547 			if (do_res_stat(Ind, A_INT)) ident = TRUE;
4548 			if (do_res_stat(Ind, A_WIS)) ident = TRUE;
4549 			if (do_res_stat(Ind, A_DEX)) ident = TRUE;
4550 			if (do_res_stat(Ind, A_CON)) ident = TRUE;
4551 			if (do_res_stat(Ind, A_CHR)) ident = TRUE;
4552 			o_ptr->pval = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);//adjusted it here too..
4553 			break;
4554 		}
4555 
4556 		case SV_ROD_SPEED:
4557 		{
4558 			if (set_fast(Ind, randint(30) + 15, 10)) ident = TRUE; /* removed stacking */
4559 			o_ptr->pval = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 49);
4560 			break;
4561 		}
4562 
4563 		case SV_ROD_HAVOC:
4564 		{
4565 #if 0
4566 			call_chaos(Ind, dir, get_skill_scale(p_ptr, SKILL_DEVICE, 1000));
4567 			ident = TRUE;
4568 			o_ptr->pval = 90; //50% faster recharge here -> too powerful, perhaps?
4569 			break;
4570 
4571 #else			//Nerf the initial damage spam.
4572 			//pfft. the third argument here is the extra damage.
4573 			sprintf(p_ptr->attacker, " invokes havoc for");
4574 			call_chaos(Ind, dir, get_skill_scale(p_ptr, SKILL_DEVICE, 675));
4575 			ident = TRUE;
4576 			o_ptr->pval = 45 - get_skill_scale(p_ptr, SKILL_DEVICE, 23);
4577 			break;
4578 #endif
4579 		}
4580 		case SV_ROD_NOTHING: //lol?
4581 		{
4582 			break;
4583 		}
4584 
4585 		default:
4586 		{
4587 			msg_print(Ind, "SERVER ERROR: Tried to zap non-directional rod in directional function!");
4588 			return;
4589 		}
4590 	}
4591 
4592 	break_cloaking(Ind, 3);
4593 	break_shadow_running(Ind);
4594 	stop_precision(Ind);
4595 	stop_shooting_till_kill(Ind);
4596 
4597 	/* Clear the current rod */
4598 	p_ptr->current_rod = -1;
4599 
4600 	/* Combine / Reorder the pack (later) */
4601 	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
4602 
4603 	/* Extract the item level */
4604 	lev = k_info[o_ptr->k_idx].level;
4605 
4606 	/* Successfully determined the object function */
4607 	if (ident && !object_aware_p(Ind, o_ptr)) {
4608 		flipped = object_aware(Ind, o_ptr);
4609 		if (!(p_ptr->mode & MODE_PVP)) gain_exp(Ind, (lev + (p_ptr->lev >> 1)) / p_ptr->lev);
4610 	}
4611 
4612 	/* Tried the object */
4613 	object_tried(Ind, o_ptr, flipped);
4614 
4615 	/* Window stuff */
4616 	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
4617 
4618 	/* Hack -- deal with cancelled zap */
4619 	if (!use_charge) {
4620 		o_ptr->pval = 0;
4621 		return;
4622 	}
4623 
4624 
4625 	/* XXX Hack -- unstack if necessary */
4626 	if ((item >= 0) && (o_ptr->number > 1)) {
4627 		/* Make a fake item */
4628 		object_type tmp_obj;
4629 		tmp_obj = *o_ptr;
4630 		tmp_obj.number = 1;
4631 
4632 		/* Restore "charge" */
4633 		o_ptr->pval = 0;
4634 
4635 		/* Unstack the used item */
4636 		o_ptr->number--;
4637 		p_ptr->total_weight -= tmp_obj.weight;
4638 		item = inven_carry(Ind, &tmp_obj);
4639 
4640 		/* Message */
4641 		msg_print(Ind, "You unstack your rod.");
4642 	}
4643 }
4644 
4645 
4646 
4647 /*
4648  * Hook to determine if an object is activatable
4649  */
4650 static bool item_tester_hook_activate(int Ind, object_type *o_ptr)
4651 {
4652 	u32b f3, dummy;
4653 
4654 	/* Not known */
4655 	if (!object_known_p(Ind, o_ptr)) return (FALSE);
4656 
4657 	/* Extract the flags */
4658 	object_flags(o_ptr, &dummy, &dummy, &f3, &dummy, &dummy, &dummy, &dummy);
4659 
4660 	/* Check activation flag */
4661 	if (f3 & TR3_ACTIVATE) return (TRUE);
4662 
4663 	/* Assume not */
4664 	return (FALSE);
4665 }
4666 
4667 
4668 
4669 /*
4670  * Hack -- activate the ring of power
4671  */
4672 static void ring_of_power(int Ind, int dir)
4673 {
4674 	player_type *p_ptr = Players[Ind];
4675 
4676 	/* Pick a random effect */
4677 	switch (randint(10))
4678 	{
4679 		case 1:
4680 		case 2:
4681 		{
4682 			/* Message */
4683 			msg_print(Ind, "You are surrounded by a malignant aura.");
4684 
4685 			/* Decrease all stats (permanently) */
4686 			(void)dec_stat(Ind, A_STR, 50, STAT_DEC_NORMAL);
4687 			(void)dec_stat(Ind, A_INT, 50, STAT_DEC_NORMAL);
4688 			(void)dec_stat(Ind, A_WIS, 50, STAT_DEC_NORMAL);
4689 			(void)dec_stat(Ind, A_DEX, 50, STAT_DEC_NORMAL);
4690 			(void)dec_stat(Ind, A_CON, 50, STAT_DEC_NORMAL);
4691 			(void)dec_stat(Ind, A_CHR, 50, STAT_DEC_NORMAL);
4692 
4693 			/* Lose some experience (permanently) */
4694 			take_xp_hit(Ind, p_ptr->exp / 4, "Ring of Power", TRUE, FALSE, TRUE);
4695 #if 0
4696 			p_ptr->exp -= (p_ptr->exp / 4);
4697 			p_ptr->max_exp -= (p_ptr->exp / 4);
4698 			check_experience(Ind);
4699 #endif	// 0
4700 
4701 			break;
4702 		}
4703 
4704 		case 3:
4705 		{
4706 			/* Message */
4707 			msg_print(Ind, "You are surrounded by a powerful aura.");
4708 
4709 			/* Dispel monsters */
4710 			dispel_monsters(Ind, 1000);
4711 
4712 			break;
4713 		}
4714 
4715 		case 4:
4716 		case 5:
4717 		case 6:
4718 		{
4719 			/* Mana Ball */
4720 			sprintf(p_ptr->attacker, " invokes a mana storm for");
4721 			fire_ball(Ind, GF_MANA, dir, 500, 3, p_ptr->attacker);
4722 
4723 			break;
4724 		}
4725 
4726 		case 7:
4727 		case 8:
4728 		case 9:
4729 		case 10:
4730 		{
4731 			/* Mana Bolt */
4732 			sprintf(p_ptr->attacker, " fires a mana bolt for");
4733 			fire_bolt(Ind, GF_MANA, dir, 250, p_ptr->attacker);
4734 
4735 			break;
4736 		}
4737 	}
4738 }
4739 
4740 
4741 
4742 
4743 /*
4744  * Enchant some bolts
4745  */
4746 static bool brand_bolts(int Ind)
4747 {
4748 	player_type *p_ptr = Players[Ind];
4749 	int i;
4750 
4751 	/* Use the first (XXX) acceptable bolts */
4752 	for (i = 0; i < INVEN_PACK; i++)
4753 	{
4754 		object_type *o_ptr = &p_ptr->inventory[i];
4755 
4756 		/* Skip non-bolts */
4757 		if (o_ptr->tval != TV_BOLT) continue;
4758 
4759 		/* Skip artifacts and ego-items */
4760 		if (artifact_p(o_ptr) || ego_item_p(o_ptr)) continue;
4761 
4762 		/* Skip cursed/broken items */
4763 		if (cursed_p(o_ptr) || broken_p(o_ptr)) continue;
4764 
4765 		/* Randomize */
4766 		if (rand_int(100) < 75) continue;
4767 
4768 		/* Message */
4769 		msg_print(Ind, "Your bolts are covered in a fiery aura!");
4770 
4771 		/* Ego-item */
4772 		o_ptr->name2 = EGO_FLAME;
4773 
4774 		/* Enchant */
4775 		enchant(Ind, o_ptr, rand_int(3) + 4, ENCH_TOHIT | ENCH_TODAM);
4776 
4777 		/* Hack -- you don't sell the wep blessed by your god, do you? :) */
4778 		o_ptr->discount = 100;
4779 
4780 		/* Notice */
4781 		return (TRUE);
4782 	}
4783 
4784 	/* Fail */
4785 	msg_print(Ind, "The fiery enchantment failed.");
4786 
4787 	/* Notice */
4788 	return (TRUE);
4789 }
4790 
4791 
4792 /* hard-coded same as the 2 functions below, do_cmd_activate() and do_cmd_activate_dir().
4793    Returns TRUE if item is activatable, for sending the client proper targetting info. - C. Blue */
4794 bool activation_requires_direction(object_type *o_ptr) {
4795 	/* Art DSMs are handled below */
4796 	if (o_ptr->tval == TV_DRAG_ARMOR && !o_ptr->name1)
4797 		return TRUE;
4798 
4799 	/* Artifacts activate by name */
4800 	if (o_ptr->name1) {
4801 		/* This needs to be changed */
4802 		switch (o_ptr->name1) {
4803 		case ART_NARTHANC:
4804 		case ART_NIMTHANC:
4805 		case ART_DETHANC:
4806 		case ART_RILIA:
4807 		case ART_BELANGIL:
4808 		case ART_RINGIL:
4809 		case ART_ANDURIL:
4810 		case ART_FIRESTAR:
4811 		case ART_THEODEN:
4812 		case ART_TURMIL:
4813 		case ART_ARUNRUTH:
4814 		case ART_AEGLOS:
4815 		case ART_OROME:
4816 		case ART_ULMO:
4817 		case ART_TOTILA:
4818 		case ART_CAMMITHRIM:
4819 		case ART_PAURHACH:
4820 		case ART_PAURNIMMEN:
4821 		case ART_PAURAEGEN:
4822 		case ART_PAURNEN:
4823 		case ART_FINGOLFIN:
4824 		case ART_NARYA:
4825 		case ART_NENYA:
4826 		case ART_VILYA:
4827 		case ART_POWER:
4828 		case ART_MEDIATOR:
4829 		case ART_AXE_GOTHMOG:
4830 		case ART_MELKOR:
4831 		case ART_NIGHT:
4832 		case ART_NAIN:
4833 		case ART_EOL:
4834 		case ART_UMBAR:
4835 		case ART_HELLFIRE:
4836 		case ART_HAVOC:
4837 			return TRUE;
4838 		}
4839 	}
4840 
4841         /* Hack -- Amulet of the Serpents can be activated as well */
4842 	else if ((o_ptr->tval == TV_AMULET) && (o_ptr->sval == SV_AMULET_SERPENT)) {
4843 		return TRUE;
4844         }
4845 
4846 	else if (o_ptr->tval == TV_RING) {
4847 		switch (o_ptr->sval) {
4848                 case SV_RING_ELEC:
4849 		case SV_RING_ACID:
4850 		case SV_RING_ICE:
4851 		case SV_RING_FLAMES:
4852 			return TRUE;
4853 		}
4854         }
4855 
4856 	/* All other items aren't activatable */
4857 	return FALSE;
4858 }
4859 
4860 bool rod_requires_direction(int Ind, object_type *o_ptr) {
4861 	int sval = o_ptr->sval;
4862 
4863 	if (Ind && !object_aware_p(Ind, o_ptr)) return TRUE;
4864 
4865 	if ((sval >= SV_ROD_MIN_DIRECTION) &&
4866 	    !(sval == SV_ROD_DETECT_TRAP) &&
4867 	    //!(sval == SV_ROD_HAVOC) &&
4868 	    !(sval == SV_ROD_HOME))
4869 		return TRUE;
4870 
4871 	return FALSE;
4872 }
4873 
4874 /*
4875  * Activate a wielded object.  Wielded objects never stack.
4876  * And even if they did, activatable objects never stack.
4877  *
4878  * Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
4879  * But one could, for example, easily make an activatable "Ring of Plasma".
4880  *
4881  * Note that it always takes a turn to activate an artifact, even if
4882  * the user hits "escape" at the "direction" prompt.
4883  */
4884 void do_cmd_activate(int Ind, int item, int dir) {
4885 	player_type *p_ptr = Players[Ind];
4886 	int         i, k;
4887 	bool done = FALSE;
4888 //	int md = get_skill_scale(p_ptr, SKILL_DEVICE, 100);
4889 	object_type *o_ptr;
4890 
4891 	/* Break goi/manashield */
4892 #if 0
4893 	if (p_ptr->invuln)
4894 		set_invuln(Ind, 0);
4895 	if (p_ptr->tim_manashield)
4896 		set_tim_manashield(Ind, 0);
4897 	if (p_ptr->tim_wraith)
4898 		set_tim_wraith(Ind, 0);
4899 #endif	// 0
4900 
4901 
4902 	/* Get the item (in the pack) */
4903 	if (item >= 0) {
4904 		o_ptr = &p_ptr->inventory[item];
4905 	}
4906 	/* Get the item (on the floor) */
4907 	else {
4908 		if (-item >= o_max)
4909 			return; /* item doesn't exist */
4910 
4911 		o_ptr = &o_list[0 - item];
4912 	}
4913 
4914 	/* dual-wield hack: cannot activate items if armour is too heavy.
4915 	   Spectral weapons will not drain life either ;). */
4916 	if (item == INVEN_ARM && o_ptr->tval != TV_SHIELD && p_ptr->rogue_heavyarmor) {
4917 		msg_format(Ind, "\377oYour armour is too heavy for dual-wielding, preventing activation of your secondary weapon.");
4918 		return;
4919 	}
4920 
4921 	if (o_ptr->tval != TV_BOTTLE) { /* hack.. */
4922 		if (p_ptr->anti_magic) {
4923 			msg_format(Ind, "\377%cYour anti-magic shell disrupts your attempt.", COLOUR_AM_OWN);
4924 			return;
4925 		}
4926 		if (get_skill(p_ptr, SKILL_ANTIMAGIC)) {
4927 			msg_format(Ind, "\377%cYou don't believe in magic.", COLOUR_AM_OWN);
4928 			return;
4929 		}
4930 		if (magik((p_ptr->antimagic * 8) / 5)) {
4931 			msg_format(Ind, "\377%cYour anti-magic field disrupts your attempt.", COLOUR_AM_OWN);
4932 			return;
4933 		}
4934 	}
4935 
4936 	/* If the item can be equipped, it MUST be equipped to be activated */
4937 	if ((item < INVEN_WIELD) && wearable_p(o_ptr)) {
4938 		msg_print(Ind, "You must be using this item to activate it.");
4939 		return;
4940 	}
4941 
4942 	if (check_guard_inscription( o_ptr->note, 'A')) {
4943 		msg_print(Ind, "The item's inscription prevents it..");
4944 		return;
4945 	}
4946 
4947 	if (!can_use_verbose(Ind, o_ptr)) return;
4948 
4949 	/* Test the item */
4950 	if (!item_tester_hook_activate(Ind, o_ptr)) {
4951 		/* Hack -- activating bottles */
4952 		if (o_ptr->tval == TV_BOTTLE) {
4953 			do_cmd_fill_bottle(Ind);
4954 			return;
4955 		}
4956 
4957 		msg_print(Ind, "You cannot activate that item.");
4958 		return;
4959 	}
4960 
4961 	/* S(he) is no longer afk */
4962 	un_afk_idle(Ind);
4963 
4964 	/* Take a turn */
4965 	p_ptr->energy -= level_speed(&p_ptr->wpos);
4966 
4967 	/* Roll for usage */
4968 	if (!activate_magic_device(Ind, o_ptr) &&
4969 	    o_ptr->tval != TV_BOOK) /* hack: blank books can always be 'activated' */
4970 	{
4971 		msg_print(Ind, "\377yYou failed to activate it properly.");
4972 		return;
4973 	}
4974 
4975 	/* Check the recharge */
4976 	if ((o_ptr->timeout) && !((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_POLYMORPH))) {
4977 		msg_print(Ind, "It whines, glows and fades...");
4978 		return;
4979 	}
4980 
4981 	process_hooks(HOOK_ACTIVATE, "d", Ind);
4982 
4983 	if (o_ptr->tval != TV_RUNE) { //Disable rune 'you activate it' text.
4984 		if (o_ptr->tval != TV_BOOK) {
4985 			/* Wonder Twin Powers... Activate! */
4986 			msg_print(Ind, "You activate it...");
4987 		} else {
4988 			msg_print(Ind, "You open the book to add another new spell..");
4989 		}
4990 	}
4991 
4992 	break_cloaking(Ind, 0);
4993 	stop_precision(Ind);
4994 	stop_shooting_till_kill(Ind);
4995 
4996 
4997         if (activation_requires_direction(o_ptr)
4998 //appearently not for A'able items >_>	    || !object_aware_p(Ind, o_ptr)
4999 	    )
5000 	{
5001 		if (dir != 0 && dir != 11) {
5002 		//redundant: lower versions cant have dir != 0. ---  && is_newer_than(&p_ptr->version, 4, 4, 5, 10, 0, 0)) {
5003 			p_ptr->current_activation = item;
5004 			do_cmd_activate_dir(Ind, dir);
5005 			return;
5006 		}
5007 	}
5008 
5009 	// -------------------- special basic items that can't vary -------------------- //
5010 	//(could be moved down to 'base items' for less efficiency but better sort order)
5011 
5012 	/* Rune de/re-combination */
5013 	if (o_ptr->tval == TV_RUNE) {
5014 		if (o_ptr->sval < RCRAFT_MAX_ELEMENTS) { //basic rune, so combine; keep lowest sale value, highest level
5015 			/* Remember the original rune */
5016 			p_ptr->current_activation = item;
5017 
5018 			/* Get the rune to combine with */
5019 			rune_combine(Ind);
5020 
5021 			return;
5022 		} else { //top-tier rune, so decombine
5023 			if (o_ptr->level || o_ptr->owner == p_ptr->id) { //Do we own it..?
5024 				/* Lookup Component Rune SVALS (matched to tables.c index) */
5025 				u16b e_flags = r_projections[o_ptr->sval].flags;
5026 				byte element[RCRAFT_MAX_ELEMENTS];
5027 				byte elements = 0; // = flags_to_elements(element, e_flags);
5028 				for (i = 0; i < RCRAFT_MAX_ELEMENTS; i++)
5029 					if ((e_flags & r_elements[i].flag) == r_elements[i].flag) {
5030 						element[elements] = i;
5031 						elements++;
5032 					}
5033 
5034 				/* Remember the original info */
5035 				s32b owner = o_ptr->owner;
5036 				byte mode = o_ptr->mode;
5037 				s16b level = o_ptr->level;
5038 				byte discount = o_ptr->discount;
5039 				byte number = o_ptr->number;
5040 				s16b note = o_ptr->note;
5041 
5042 				/* Destroy the rune stack in the pack */
5043 				msg_format(Ind, "There is a decoupling of magic.");
5044 				inven_item_increase(Ind, item, -number);
5045 				inven_item_optimize(Ind, item);
5046 
5047 				/* Make new stacks */
5048 				object_type *q_ptr, forge;
5049 				for (i = 0; i < RSPELL_MAX_ELEMENTS; i++) {
5050 
5051 					/* Default rune template */
5052 					q_ptr = &forge;
5053 					object_wipe(q_ptr);
5054 					invcopy(q_ptr, lookup_kind(TV_RUNE, element[i]));
5055 
5056 					/* Recall original parameters */
5057 					q_ptr->owner = owner;
5058 					q_ptr->mode = mode;
5059 					q_ptr->level = level;
5060 					q_ptr->discount = discount;
5061 					q_ptr->number = number;
5062 					q_ptr->note = note;
5063 
5064 					/* Create the rune stack */
5065 					inven_carry(Ind, q_ptr);
5066 				}
5067 			}
5068 			return;
5069 		}
5070 	}
5071 
5072 	if (o_ptr->tval == TV_GOLEM) {
5073 		int m_idx = 0, k;
5074 		monster_type *m_ptr;
5075 
5076 		/* Process the monsters */
5077 		for (k = m_top - 1; k >= 0; k--) {
5078 			/* Access the index */
5079 			i = m_fast[k];
5080 
5081 			/* Access the monster */
5082 			m_ptr = &m_list[i];
5083 
5084 			/* Excise "dead" monsters */
5085 			if (!m_ptr->r_idx) continue;
5086 
5087 			if (m_ptr->owner != p_ptr->id) continue;
5088 
5089 			m_idx = i;
5090 			if (!m_idx) continue;
5091 			m_ptr = &m_list[m_idx];
5092 
5093 			if (!(m_ptr->r_ptr->extra & (1 << (o_ptr->sval - 200)))) {
5094 				msg_print(Ind, "I do not understand, master.");
5095 				continue;
5096 			}
5097 
5098 			switch (o_ptr->sval) {
5099 			case SV_GOLEM_ATTACK:
5100 				if (m_ptr->mind & (1 << (o_ptr->sval - 200))) {
5101 					msg_print(Ind, "I wont attack your target anymore, master.");
5102 					m_ptr->mind &= ~(1 << (o_ptr->sval - 200));
5103 				} else {
5104 					msg_print(Ind, "I will attack your target, master.");
5105 					m_ptr->mind |= (1 << (o_ptr->sval - 200));
5106 				}
5107 				break;
5108 			case SV_GOLEM_FOLLOW:
5109 				if (m_ptr->mind & (1 << (o_ptr->sval - 200))) {
5110 					msg_print(Ind, "I wont follow you, master.");
5111 					m_ptr->mind &= ~(1 << (o_ptr->sval - 200));
5112 				} else {
5113 					msg_print(Ind, "I will follow you, master.");
5114 					m_ptr->mind |= (1 << (o_ptr->sval - 200));
5115 				}
5116 				break;
5117 			case SV_GOLEM_GUARD:
5118 				if (m_ptr->mind & (1 << (o_ptr->sval - 200))) {
5119 					msg_print(Ind, "I wont guard my position anymore, master.");
5120 					m_ptr->mind &= ~(1 << (o_ptr->sval - 200));
5121 				} else {
5122 					msg_print(Ind, "I will guard my position, master.");
5123 					m_ptr->mind |= (1 << (o_ptr->sval - 200));
5124 				}
5125 				break;
5126 			}
5127 		}
5128 		return;
5129 	}
5130 
5131 	/* add a single spell to the player's customizable tome */
5132 	if (o_ptr->tval == TV_BOOK && is_custom_tome(o_ptr->sval)) {
5133 	        /* free space left? */
5134 	        i = 1;
5135 		/* k_info-pval dependant */
5136                 switch (o_ptr->bpval) {
5137 		case 0: i = 0; break;
5138 		case 1: if (o_ptr->xtra1) i = 0; break;
5139 		case 2: if (o_ptr->xtra2) i = 0; break;
5140 		case 3: if (o_ptr->xtra3) i = 0; break;
5141 		case 4: if (o_ptr->xtra4) i = 0; break;
5142 		case 5: if (o_ptr->xtra5) i = 0; break;
5143 		case 6: if (o_ptr->xtra6) i = 0; break;
5144 		case 7: if (o_ptr->xtra7) i = 0; break;
5145 		case 8: if (o_ptr->xtra8) i = 0; break;
5146 		default: if (o_ptr->xtra9) i = 0; break;
5147 		}
5148 		if (!i) {
5149 			msg_print(Ind, "That book has no blank pages left!");
5150 			return;
5151 		}
5152 
5153 		tome_creation(Ind);
5154 		p_ptr->using_up_item = item; /* hack - gets swapped later */
5155 		return;
5156 	}
5157 
5158 	// -------------------- artifacts -------------------- //
5159 
5160 	if (o_ptr->name1 && o_ptr->name1 != ART_RANDART) {
5161 		done = TRUE;
5162 		/* Choose effect */
5163 		switch (o_ptr->name1) {
5164 		case ART_NARTHANC:
5165 			msg_print(Ind, "Your dagger is covered in fire...");
5166 			p_ptr->current_activation = item;
5167 			get_aim_dir(Ind);
5168 			return;
5169 		case ART_NIMTHANC:
5170 			msg_print(Ind, "Your dagger is covered in frost...");
5171 			p_ptr->current_activation = item;
5172 			get_aim_dir(Ind);
5173 			return;
5174 		case ART_DETHANC:
5175 			msg_print(Ind, "Your dagger is covered in sparks...");
5176 			p_ptr->current_activation = item;
5177 			get_aim_dir(Ind);
5178 			return;
5179 		case ART_RILIA:
5180 			msg_print(Ind, "Your dagger throbs deep green...");
5181 			p_ptr->current_activation = item;
5182 			get_aim_dir(Ind);
5183 			return;
5184 		case ART_BELANGIL:
5185 			msg_print(Ind, "Your dagger is covered in frost...");
5186 			p_ptr->current_activation = item;
5187 			get_aim_dir(Ind);
5188 			return;
5189 		case ART_DAL:
5190 			msg_print(Ind, "\377GYou feel energy flow through your feet...");
5191 			(void)set_afraid(Ind, 0);
5192 			(void)set_res_fear(Ind, 5);
5193 			(void)set_poisoned(Ind, 0, 0);
5194 			o_ptr->timeout = 5;
5195 			break;
5196 		case ART_RINGIL:
5197 			msg_print(Ind, "Your sword glows an intense blue...");
5198 			p_ptr->current_activation = item;
5199 			get_aim_dir(Ind);
5200 			return;
5201 		case ART_ANDURIL:
5202 			msg_print(Ind, "Your sword glows an intense red...");
5203 			p_ptr->current_activation = item;
5204 			get_aim_dir(Ind);
5205 			return;
5206 		case ART_FIRESTAR:
5207 			msg_print(Ind, "Your morningstar rages in fire...");
5208 			p_ptr->current_activation = item;
5209 			get_aim_dir(Ind);
5210 			return;
5211 		case ART_FEANOR:
5212 			(void)set_fast(Ind, randint(20) + 20, 15); /* removed stacking */
5213 			o_ptr->timeout = 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
5214 			break;
5215 		case ART_THEODEN:
5216 			msg_print(Ind, "The blade of your axe glows black...");
5217 			p_ptr->current_activation = item;
5218 			get_aim_dir(Ind);
5219 			return;
5220 		case ART_TURMIL:
5221 			msg_print(Ind, "The head of your hammer glows white...");
5222 			p_ptr->current_activation = item;
5223 			get_aim_dir(Ind);
5224 			return;
5225 		case ART_CASPANION:
5226 			msg_print(Ind, "Your armour glows bright red...");
5227 			destroy_doors_touch(Ind, 1);
5228 			o_ptr->timeout = 10 - get_skill_scale(p_ptr, SKILL_DEVICE, 6);
5229 			break;
5230 		case ART_AVAVIR:
5231 			set_recall(Ind, rand_int(20) + 15, o_ptr);
5232 			o_ptr->timeout = 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5233 			break;
5234 		case ART_TARATOL:
5235 			(void)set_fast(Ind, randint(20) + 20, 15); /* removed stacking */
5236 			o_ptr->timeout = rand_int(50) + 100 - get_skill_scale(p_ptr, SKILL_DEVICE, 70);
5237 			break;
5238 		case ART_ERIRIL:
5239 			/* Identify and combine pack */
5240 			(void)ident_spell(Ind);
5241 			/* XXX Note that the artifact is always de-charged */
5242 			o_ptr->timeout = 10 - get_skill_scale(p_ptr, SKILL_DEVICE, 8);
5243 			break;
5244 		case ART_OLORIN:
5245 			probing(Ind);
5246 			detection(Ind, DEFAULT_RADIUS * 2);
5247 			o_ptr->timeout = 20 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
5248 			break;
5249 		case ART_EONWE:
5250 			msg_print(Ind, "Your axe lets out a long, shrill note...");
5251 			(void)obliteration(Ind);
5252 			o_ptr->timeout = 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 500);
5253 			break;
5254 		case ART_LOTHARANG:
5255 			msg_print(Ind, "Your battle axe radiates deep purple...");
5256 			hp_player(Ind, damroll(4, 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 20)));
5257 			(void)set_cut(Ind, (p_ptr->cut / 2) - 50, p_ptr->cut_attacker);
5258 			o_ptr->timeout = rand_int(3) + 3 - get_skill_scale(p_ptr, SKILL_DEVICE, 2);//o_o
5259 			break;
5260 		case ART_CUBRAGOL:
5261 			(void)brand_bolts(Ind);
5262 			o_ptr->timeout = 999 - get_skill_scale(p_ptr, SKILL_DEVICE, 777);
5263 			break;
5264 		case ART_ARUNRUTH:
5265 			msg_print(Ind, "Your sword glows a pale blue...");
5266 			p_ptr->current_activation = item;
5267 			get_aim_dir(Ind);
5268 			return;
5269 		case ART_AEGLOS:
5270 			msg_print(Ind, "Your spear glows a bright white...");
5271 			p_ptr->current_activation = item;
5272 			get_aim_dir(Ind);
5273 			return;
5274 		case ART_OROME:
5275 			msg_print(Ind, "Your spear pulsates...");
5276 			p_ptr->current_activation = item;
5277 			get_aim_dir(Ind);
5278 			return;
5279 		case ART_SOULKEEPER:
5280 			msg_print(Ind, "Your armour glows a bright white...");
5281 			msg_print(Ind, "\377GYou feel much better...");
5282 			(void)hp_player(Ind, 1000);
5283 			(void)set_cut(Ind, 0, 0);
5284 			o_ptr->timeout = 888 - get_skill_scale(p_ptr, SKILL_DEVICE, 666);
5285 			break;
5286 		case ART_BELEGENNON:
5287 			teleport_player(Ind, 10, TRUE);
5288 			o_ptr->timeout = 2 - get_skill_scale(p_ptr, SKILL_DEVICE, 1);//>_>
5289 			break;
5290 		case ART_CELEBORN:
5291 			(void)genocide(Ind);
5292 			o_ptr->timeout = 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 400);
5293 			break;
5294 		case ART_LUTHIEN:
5295 			restore_level(Ind);
5296 			o_ptr->timeout = 450 - get_skill_scale(p_ptr, SKILL_DEVICE, 350);
5297 			break;
5298 		case ART_ULMO:
5299 			msg_print(Ind, "Your trident glows deep red...");
5300 			p_ptr->current_activation = item;
5301 			get_aim_dir(Ind);
5302 			return;
5303 		case ART_COLLUIN:
5304 			msg_print(Ind, "Your cloak glows many colours...");
5305 			(void)set_oppose_acid(Ind, randint(20) + 20); /* removed stacking */
5306 			(void)set_oppose_elec(Ind, randint(20) + 20);
5307 			(void)set_oppose_fire(Ind, randint(20) + 20);
5308 			(void)set_oppose_cold(Ind, randint(20) + 20);
5309 			(void)set_oppose_pois(Ind, randint(20) + 20);
5310 			o_ptr->timeout = 111 - get_skill_scale(p_ptr, SKILL_DEVICE, 56);
5311 			break;
5312 		case ART_HOLCOLLETH:
5313 			msg_print(Ind, "Your cloak glows deep blue...");
5314 			sleep_monsters_touch(Ind);
5315 			o_ptr->timeout = 55 - get_skill_scale(p_ptr, SKILL_DEVICE, 40);
5316 			break;
5317 		case ART_THINGOL:
5318 			msg_print(Ind, "You hear a low humming noise...");
5319 			recharge(Ind, 60 + get_skill_scale(p_ptr, SKILL_DEVICE, 40));
5320 			o_ptr->timeout = 70 - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
5321 			break;
5322 		case ART_COLANNON:
5323 			teleport_player(Ind, 100, FALSE);
5324 			o_ptr->timeout = 45 - get_skill_scale(p_ptr, SKILL_DEVICE, 35);
5325 			break;
5326 		case ART_TOTILA:
5327 			msg_print(Ind, "Your flail glows in scintillating colours...");
5328 			p_ptr->current_activation = item;
5329 			get_aim_dir(Ind);
5330 			return;
5331 		case ART_CAMMITHRIM:
5332 			msg_print(Ind, "Your gloves glow extremely brightly...");
5333 			p_ptr->current_activation = item;
5334 			get_aim_dir(Ind);
5335 			return;
5336 		case ART_PAURHACH:
5337 			msg_print(Ind, "Your gauntlets are covered in fire...");
5338 			p_ptr->current_activation = item;
5339 			get_aim_dir(Ind);
5340 			return;
5341 		case ART_PAURNIMMEN:
5342 			msg_print(Ind, "Your gauntlets are covered in frost...");
5343 			p_ptr->current_activation = item;
5344 			get_aim_dir(Ind);
5345 			return;
5346 		case ART_PAURAEGEN:
5347 			msg_print(Ind, "Your gauntlets are covered in sparks...");
5348 			p_ptr->current_activation = item;
5349 			get_aim_dir(Ind);
5350 			return;
5351 		case ART_PAURNEN:
5352 			msg_print(Ind, "Your gauntlets look very acidic...");
5353 			p_ptr->current_activation = item;
5354 			get_aim_dir(Ind);
5355 			return;
5356 		case ART_FINGOLFIN:
5357 			msg_print(Ind, "Magical spikes appear on your cesti...");
5358 			p_ptr->current_activation = item;
5359 			get_aim_dir(Ind);
5360 			return;
5361 		case ART_HOLHENNETH:
5362 			msg_print(Ind, "An image forms in your mind...");
5363 			detection(Ind, DEFAULT_RADIUS * 2);
5364 			o_ptr->timeout = rand_int(25) + 55 - get_skill_scale(p_ptr, SKILL_DEVICE, 40);
5365 			break;
5366 		case ART_GONDOR:
5367 			msg_print(Ind, "\377GYou feel a warm tingling inside...");
5368 			(void)hp_player(Ind, 500);
5369 			(void)set_cut(Ind, 0, 0);
5370 			o_ptr->timeout = 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 400);
5371 			break;
5372 		case ART_RAZORBACK:
5373 			msg_print(Ind, "You are surrounded by lightning!");
5374 			sprintf(p_ptr->attacker, " casts a lightning ball for");
5375 			for (i = 0; i < 8; i++) fire_ball(Ind, GF_ELEC, ddd[i], 150 + get_skill_scale(p_ptr, SKILL_DEVICE, 450), 3, p_ptr->attacker);
5376 			o_ptr->timeout = 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 700);
5377 			break;
5378 		case ART_BLADETURNER:
5379 			msg_print(Ind, "Your armour glows in many colours...");
5380 			(void)hp_player(Ind, 30);
5381 			(void)set_afraid(Ind, 0);
5382 			(void)set_res_fear(Ind, 20);
5383 			(void)set_shero(Ind, randint(50) + 50); /* removed stacking */
5384 			p_ptr->blessed_power = 20;
5385 			(void)set_blessed(Ind, randint(50) + 50); /* removed stacking */
5386 			(void)set_oppose_acid(Ind, randint(50) + 50); /* removed stacking */
5387 			(void)set_oppose_elec(Ind, randint(50) + 50);
5388 			(void)set_oppose_fire(Ind, randint(50) + 50);
5389 			(void)set_oppose_cold(Ind, randint(50) + 50);
5390 			(void)set_oppose_pois(Ind, randint(50) + 50);
5391 			o_ptr->timeout = 400 - get_skill_scale(p_ptr, SKILL_DEVICE, 200);
5392 			break;
5393 		case ART_GALADRIEL:
5394 			msg_print(Ind, "The phial wells with clear light...");
5395 			lite_area(Ind, damroll(2, 15 + get_skill_scale(p_ptr, SKILL_DEVICE, 50)), 3);
5396 			if (p_ptr->suscep_lite) take_hit(Ind, damroll(50, 4), "the phial of galadriel", 0);
5397                         	if (p_ptr->suscep_lite && !p_ptr->resist_lite && !p_ptr->resist_blind) (void)set_blind(Ind, p_ptr->blind + 5 + randint(10));
5398 			o_ptr->timeout = rand_int(10) + 10 - get_skill_scale(p_ptr, SKILL_DEVICE, 5);
5399 			break;
5400 		case ART_ELENDIL:
5401 			msg_print(Ind, "The star shines brightly...");
5402 			map_area(Ind);
5403 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 40);
5404 			break;
5405 		case ART_THRAIN:
5406 			msg_print(Ind, "The stone glows a deep green...");
5407 			wiz_lite(Ind);
5408 			(void)detect_sdoor(Ind, DEFAULT_RADIUS * 2);
5409 			(void)detect_trap(Ind, DEFAULT_RADIUS * 2);
5410 			o_ptr->timeout = rand_int(150) + 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 800);
5411 			break;
5412 		case ART_INGWE:
5413 			msg_print(Ind, "An aura of good floods the area...");
5414 			dispel_evil(Ind, p_ptr->lev * 10 + get_skill_scale(p_ptr, SKILL_DEVICE, 500));
5415 			o_ptr->timeout = rand_int(150) + 300 - get_skill_scale(p_ptr, SKILL_DEVICE, 250);
5416 			break;
5417 		case ART_CARLAMMAS:
5418 			msg_print(Ind, "The amulet lets out a shrill wail...");
5419 			(void)set_protevil(Ind, randint(15) + 30); /* removed stacking */
5420 			o_ptr->timeout = rand_int(125) + 225 - get_skill_scale(p_ptr, SKILL_DEVICE, 200);
5421 			break;
5422 		case ART_TULKAS:
5423 			msg_print(Ind, "The ring glows brightly...");
5424 			(void)set_fast(Ind, randint(50) + 75, 15); /* removed stacking */
5425 			o_ptr->timeout = rand_int(100) + 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5426 			break;
5427 		case ART_NARYA:
5428 			msg_print(Ind, "The ring glows deep red...");
5429 			p_ptr->current_activation = item;
5430 			get_aim_dir(Ind);
5431 			return;
5432 		case ART_NENYA:
5433 			msg_print(Ind, "The ring glows bright white...");
5434 			p_ptr->current_activation = item;
5435 			get_aim_dir(Ind);
5436 			return;
5437 		case ART_VILYA:
5438 			msg_print(Ind, "The ring glows deep blue...");
5439 			p_ptr->current_activation = item;
5440 			get_aim_dir(Ind);
5441 			return;
5442 		case ART_POWER:
5443 			msg_print(Ind, "The ring glows intensely black...");
5444 			p_ptr->current_activation = item;
5445 			get_aim_dir(Ind);
5446 			return;
5447 		case ART_GILGALAD:
5448 			for (k = 1; k < 10; k++)
5449 				if (k - 5) fire_beam(Ind, GF_LITE, k, 75 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), " emits a beam of light for");
5450 
5451 			o_ptr->timeout = rand_int(50) + 75 - get_skill_scale(p_ptr, SKILL_DEVICE, 60);
5452 			break;
5453 		case ART_CELEBRIMBOR:
5454 			set_tim_esp(Ind, p_ptr->tim_esp + randint(20) + 20);
5455 			 /* not removed stacking */
5456 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
5457 			break;
5458 		case ART_SKULLCLEAVER:
5459 			destroy_area(&p_ptr->wpos, p_ptr->py, p_ptr->px, 15, TRUE, FEAT_FLOOR, 120);
5460 			o_ptr->timeout = rand_int(200) + 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5461 			break;
5462 		case ART_HARADRIM:
5463 			set_afraid(Ind, 0);
5464 			set_shero(Ind, randint(25) + 25); /* removed stacking */
5465 			hp_player(Ind, 30);
5466 			o_ptr->timeout = rand_int(40) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 35);
5467 			break;
5468 		case ART_FUNDIN:
5469 			dispel_evil(Ind, p_ptr->lev * 8 + get_skill_scale(p_ptr, SKILL_DEVICE, 400));
5470 			o_ptr->timeout = rand_int(50) + 100 - get_skill_scale(p_ptr, SKILL_DEVICE, 80);
5471 			break;
5472 		case ART_NAIN:
5473 		case ART_EOL:
5474 		case ART_UMBAR:
5475 			p_ptr->current_activation = item;
5476 			get_aim_dir(Ind);
5477 			return;
5478 		case ART_NUMENOR:
5479 #if 0
5480 			/* Give full knowledge */
5481 			/* Hack -- Maximal info */
5482 			monster_race *r_ptr;
5483 			cave_type *c_ptr;
5484 			int x, y, m;
5485 
5486 			if (!tgt_pt(&x, &y)) break;
5487 
5488 			c_ptr = &cave[y][x];
5489 			if (!c_ptr->m_idx) break;
5490 
5491 			r_ptr = race_inf(m_list[c_ptr->m_idx]);
5492 
5493  #ifdef OLD_MONSTER_LORE
5494 			/* Observe "maximal" attacks */
5495 			for (m = 0; m < 4; m++) {
5496 				/* Examine "actual" blows */
5497 				if (r_ptr->blow[m].effect || r_ptr->blow[m].method) {
5498 					/* Hack -- maximal observations */
5499 					r_ptr->r_blows[m] = MAX_UCHAR;
5500 				}
5501 			}
5502 
5503 			/* Hack -- maximal drops */
5504 			r_ptr->r_drop_gold = r_ptr->r_drop_item =
5505 				(((r_ptr->flags1 & (RF1_DROP_4D2)) ? 8 : 0) +
5506 				 ((r_ptr->flags1 & (RF1_DROP_3D2)) ? 6 : 0) +
5507 				 ((r_ptr->flags1 & (RF1_DROP_2D2)) ? 4 : 0) +
5508 				 ((r_ptr->flags1 & (RF1_DROP_1D2)) ? 2 : 0) +
5509 				 ((r_ptr->flags0 & (RF0_DROP_1))   ? 1 : 0) +
5510 				 ((r_ptr->flags1 & (RF1_DROP_90))  ? 1 : 0) +
5511 				 ((r_ptr->flags1 & (RF1_DROP_60))  ? 1 : 0));
5512 
5513 			/* Hack -- but only "valid" drops */
5514 			if (r_ptr->flags1 & (RF1_ONLY_GOLD)) r_ptr->r_drop_item = 0;
5515 			if (r_ptr->flags1 & (RF1_ONLY_ITEM)) r_ptr->r_drop_gold = 0;
5516 
5517 			/* Hack -- observe many spells */
5518 			r_ptr->r_cast_innate = MAX_UCHAR;
5519 			r_ptr->r_cast_spell = MAX_UCHAR;
5520 
5521 			/* Hack -- know all the flags */
5522 			r_ptr->r_flags1 = r_ptr->flags1;
5523 			r_ptr->r_flags2 = r_ptr->flags2;
5524 			r_ptr->r_flags3 = r_ptr->flags3;
5525 			r_ptr->r_flags4 = r_ptr->flags4;
5526 			r_ptr->r_flags5 = r_ptr->flags5;
5527 			r_ptr->r_flags6 = r_ptr->flags6;
5528 			r_ptr->r_flags7 = r_ptr->flags7;
5529 			r_ptr->r_flags8 = r_ptr->flags8;
5530 			r_ptr->r_flags9 = r_ptr->flags9;
5531  #endif
5532 
5533 			o_ptr->timeout = rand_int(200) + 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 350);
5534 #else
5535 			probing(Ind);
5536 			o_ptr->timeout = rand_int(200) + 300 - get_skill_scale(p_ptr, SKILL_DEVICE, 250);
5537 #endif
5538 			break;
5539 		case ART_KNOWLEDGE:
5540 			identify_fully(Ind);
5541 			msg_print(Ind, "\377RYou hear horrible, otherworldy sounds of the dead in your head..");
5542                                 take_sanity_hit(Ind, damroll(2, 7), "the sounds of the dead");
5543 //				take_hit(Ind, damroll(10, 7), "the sounds of the dead", 0);
5544 			o_ptr->timeout = rand_int(100) + 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5545 			break;
5546 		case ART_UNDEATH:
5547 			msg_print(Ind, "The phial wells with dark light...");
5548 			unlite_area(Ind, damroll(2, 15 + get_skill_scale(p_ptr, SKILL_DEVICE, 50)), 3);
5549 			take_hit(Ind, damroll(10, 10), "activating The Phial of Undeath", 0);
5550 			if (!p_ptr->suscep_life) {
5551 				(void)dec_stat(Ind, A_DEX, 25, STAT_DEC_PERMANENT);
5552 				(void)dec_stat(Ind, A_WIS, 25, STAT_DEC_PERMANENT);
5553 				(void)dec_stat(Ind, A_CON, 25, STAT_DEC_PERMANENT);
5554 				(void)dec_stat(Ind, A_STR, 25, STAT_DEC_PERMANENT);
5555 				(void)dec_stat(Ind, A_CHR, 25, STAT_DEC_PERMANENT);
5556 				(void)dec_stat(Ind, A_INT, 25, STAT_DEC_PERMANENT);
5557 			}
5558 			o_ptr->timeout = rand_int(10) + 10 - get_skill_scale(p_ptr, SKILL_DEVICE, 5);
5559 			break;
5560 		case ART_HIMRING:
5561 			(void)set_protevil(Ind, randint(15) + 30); /* removed stacking */
5562 			o_ptr->timeout = rand_int(125) + 225 - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
5563 			break;
5564 		case ART_FLAR:
5565 #if 0
5566 			/* Check for CAVE_STCK */
5567 
5568 			msg_print(Ind, "You open a between gate. Choose a destination.");
5569 			if (!tgt_pt(&ii,&ij)) return;
5570 			p_ptr->energy -= 60 - plev;
5571 			if (!cave_empty_bold(ij,ii) || (cave[ij][ii].info & CAVE_ICKY) ||
5572 					(distance(ij,ii,py,px) > plev + 2) ||
5573 					(!rand_int(plev * plev / 2)))
5574 			{
5575 				msg_print(Ind, "You fail to exit the between correctly!");
5576 				p_ptr->energy -= 100;
5577 				teleport_player(Ind, 10, TRUE);
5578 			}
5579 			else teleport_player_to(ij,ii);
5580 			o_ptr->timeout = 100 - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
5581 #else
5582 			/* Initiate or complete gateway creation. - C. Blue
5583 			   If we initiated it, do not set a timeout, so we can activate
5584 			   F'lar a second time at will to complete the spell, then timeout. */
5585 			if (py_create_gateway(Ind) == 2) o_ptr->timeout = 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 500);
5586 #endif
5587 			break;
5588 		case ART_BARAHIR:
5589 			msg_print(Ind, "You exterminate small life.");
5590 			(void)dispel_monsters(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 300));
5591 			o_ptr->timeout = rand_int(55) + 55 - get_skill_scale(p_ptr, SKILL_DEVICE, 40);
5592 			break;
5593 		/* The Stone of Lore is perilous, for the sake of game balance. */
5594 		case ART_STONE_LORE:
5595 			msg_print(Ind, "The stone reveals hidden mysteries...");
5596 			if (!ident_spell(Ind)) return;
5597 			//                                if (!p_ptr->realm1)
5598 			if (1) {
5599 				/* Sufficient mana */
5600 				if (20 <= p_ptr->csp) {
5601 					/* Use some mana */
5602 					p_ptr->csp -= 20;
5603 
5604 					/* Confusing. */
5605 					if (rand_int(5) == 0) (void)set_confused(Ind, p_ptr->confused + randint(5));
5606 				}
5607 
5608 				/* Over-exert the player */
5609 				else {
5610 					/* No mana left */
5611 					p_ptr->csp = 0;
5612 					p_ptr->csp_frac = 0;
5613 
5614 					/* Message */
5615 					msg_print(Ind, "You do not have enough mana to control the stone!");
5616 
5617 					/* Confusing. */
5618 					(void)set_confused(Ind, p_ptr->confused + 5 + randint(5));
5619 				}
5620 
5621 				/* Redraw mana */
5622 				p_ptr->redraw |= (PR_MANA);
5623 			}
5624 
5625 			/* Exercise a little care... */
5626 			//if (rand_int(20) == 0) take_hit(Ind, damroll(4, 10), "perilous secrets", 0); else
5627 			take_hit(Ind, damroll(1, 12), "perilous secrets", 0);
5628 
5629 			o_ptr->timeout = 10 - get_skill_scale(p_ptr, SKILL_DEVICE, 6);
5630 			break;
5631 		case ART_MEDIATOR:
5632 			p_ptr->current_activation = item;
5633 			get_aim_dir(Ind);
5634 			return;
5635 		case ART_DOR:
5636 		case ART_GORLIM:
5637 			turn_monsters(Ind, 40 + p_ptr->lev);
5638 			o_ptr->timeout = 3 * (p_ptr->lev + 10);
5639 			break;
5640 		case ART_ANGUIREL:
5641 			switch (randint(13)) {
5642 				case 1: case 2: case 3: case 4: case 5:
5643 					teleport_player(Ind, 10, TRUE);
5644 					break;
5645 				case 6: case 7: case 8: case 9: case 10:
5646 					teleport_player(Ind, 222, FALSE);
5647 					break;
5648 				case 11: case 12:
5649 				default:
5650 					(void)stair_creation(Ind);
5651 					break;
5652 			}
5653 			o_ptr->timeout = 35 - get_skill_scale(p_ptr, SKILL_DEVICE, 20);
5654 			break;
5655 		case ART_ERU:
5656 			msg_print(Ind, "Your sword glows an intense white...");
5657 			hp_player(Ind, 1000);
5658 			heal_insanity(Ind, 50);
5659 			set_blind(Ind, 0);
5660 			set_poisoned(Ind, 0, 0);
5661 			set_confused(Ind, 0);
5662 			set_stun(Ind, 0);
5663 			set_cut(Ind, 0, 0);
5664 			set_image(Ind, 0);
5665 			o_ptr->timeout = 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 250);
5666 			break;
5667 		case ART_DAWN:
5668 #if 0 /* needs pet code */
5669 			msg_print(Ind, "You summon the Legion of the Dawn.");
5670 			(void)summon_specific_friendly(py, px, dlev, SUMMON_DAWN, TRUE, 0);
5671 #else
5672 			do_banish_undead(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 30));
5673 #endif
5674 			o_ptr->timeout = 500 + randint(100) - get_skill_scale(p_ptr, SKILL_DEVICE, 400);
5675 			break;
5676 #if 0
5677 		case ART_AVAVIR:
5678 			if (dlev && (max_dlv[dungeon_type] > dlev)) {
5679 				if (get_check("Reset recall depth? "))
5680 					max_dlv[dungeon_type] = dlev;
5681 			}
5682 
5683 			msg_print(Ind, "Your scythe glows soft white...");
5684 			if (!p_ptr->word_recall) {
5685 				p_ptr->word_recall = randint(20) + 15;
5686 				msg_print(Ind, "The air about you becomes charged...");
5687 			} else {
5688 				p_ptr->word_recall = 0;
5689 				msg_print(Ind, "A tension leaves the air around you...");
5690 			}
5691 			o_ptr->timeout = 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5692 			break;
5693 #endif
5694 		case ART_EVENSTAR:
5695 			restore_level(Ind);
5696 			(void)do_res_stat(Ind, A_STR);
5697 			(void)do_res_stat(Ind, A_DEX);
5698 			(void)do_res_stat(Ind, A_CON);
5699 			(void)do_res_stat(Ind, A_INT);
5700 			(void)do_res_stat(Ind, A_WIS);
5701 			(void)do_res_stat(Ind, A_CHR);
5702 			o_ptr->timeout = 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5703 			break;
5704 #if 1
5705 		case ART_ELESSAR:
5706 			if (p_ptr->black_breath)
5707 				msg_print(Ind, "The hold of the Black Breath on you is broken!");
5708 			p_ptr->black_breath = FALSE;
5709 			hp_player(Ind, 100);
5710 			o_ptr->timeout = 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5711 			break;
5712 #endif
5713 		case ART_GANDALF:
5714 			msg_print(Ind, "Your mage staff glows deep blue...");
5715 			if (p_ptr->csp < p_ptr->msp) {
5716 				p_ptr->csp = p_ptr->msp;
5717 				p_ptr->csp_frac = 0;
5718 				msg_print(Ind, "You feel your head clearing.");
5719 				p_ptr->redraw |= (PR_MANA);
5720 				p_ptr->window |= (PW_PLAYER);
5721 			}
5722 			o_ptr->timeout = 666 - get_skill_scale(p_ptr, SKILL_DEVICE, 444);
5723 			break;
5724 		case ART_MARDRA:
5725 #if 0	// needing pet code
5726 			if (randint(3) == 1) {
5727 				if (summon_specific(py, px, ((plev * 3) / 2), SUMMON_DRAGONRIDER, 0, 1)) {
5728 					msg_print(Ind, "A DragonRider comes from the BETWEEN !");
5729 					msg_print(Ind, "'I will burn you!'");
5730 				}
5731 			} else {
5732 				if (summon_specific_friendly(py, px, ((plev * 3) / 2),
5733 				    SUMMON_DRAGONRIDER, (bool)(plev == 50 ? TRUE : FALSE))) {
5734 					msg_print(Ind, "A DragonRider comes from the BETWEEN !");
5735 					msg_print(Ind, "'I will help you in your difficult task.'");
5736 				}
5737 			}
5738 #else
5739 			do_banish_dragons(Ind, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 30));
5740 #endif
5741 			o_ptr->timeout = 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 500);
5742 			break;
5743 		case ART_PALANTIR_ITHIL:
5744 		case ART_PALANTIR:
5745 			msg_print(Ind, "The stone glows a deep green...");
5746 			wiz_lite_extra(Ind);
5747 			(void)detect_trap(Ind, DEFAULT_RADIUS * 2);
5748 			(void)detect_sdoor(Ind, DEFAULT_RADIUS * 2);
5749 			//(void)detect_stair(Ind);
5750 			o_ptr->timeout = rand_int(150) + 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 800);
5751 			break;
5752 #if 0	// Instruments
5753 		case ART_ROBINTON:
5754 			msg_format(Ind, "Your instrument starts %s",music_info[3].desc);
5755 			p_ptr->music = 3; /* Full ID */
5756 			o_ptr->timeout = music_info[p_ptr->music].init_recharge;
5757 			break;
5758 		case ART_PIEMUR:
5759 			msg_format(Ind, "Your instrument starts %s",music_info[9].desc);
5760 			p_ptr->music = 9;
5761 			o_ptr->timeout = music_info[p_ptr->music].init_recharge;
5762 			break;
5763 		case ART_MENOLLY:
5764 			msg_format(Ind, "Your instrument starts %s",music_info[10].desc);
5765 			p_ptr->music = 10;
5766 			o_ptr->timeout = music_info[p_ptr->music].init_recharge;
5767 			break;
5768 #endif
5769 		case ART_EREBOR:
5770 			msg_print(Ind, "Your pick twists in your hands.");
5771 			p_ptr->current_activation = item;
5772 			get_aim_dir(Ind);
5773 			return;
5774 #if 0
5775 		case ART_DRUEDAIN:
5776 			msg_print(Ind, "Your drum shows you the world.");
5777 			detect_all();
5778 			o_ptr->timeout = 99 - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
5779 			break;
5780 		case ART_ROHAN:
5781 			msg_print(Ind, "Your horn glows deep red.");
5782 			set_afraid(0);
5783 			set_shero(Ind, damroll(5,10) + 30); /* removed stacking */
5784 			set_afraid(0);
5785 			set_hero(Ind, damroll(5,10) + 30); /* removed stacking */
5786 			set_fast(Ind, damroll(5,10) + 30, 20); /* removed stacking */
5787 			hp_player(30);
5788 			o_ptr->timeout = 250 + randint(50) - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
5789 			break;
5790 		case ART_HELM:
5791 			msg_print(Ind, "Your horn emits a loud sound.");
5792 			if (!get_aim_dir(Ind)) return;
5793 			sprintf(p_ptr->attacker, "'s horn emits a loud sound for");
5794 			fire_ball(GF_SOUND, dir, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 6, p_ptr->attacker);
5795 			o_ptr->timeout = 300;
5796 			break;
5797 		case ART_BOROMIR:
5798 			msg_print(Ind, "Your horn calls for help.");
5799 			for(i = 0; i < 15; i++)
5800 				summon_specific_friendly(py, px, ((plev * 3) / 2), SUMMON_HUMAN, TRUE);
5801 			o_ptr->timeout = 1000 - get_skill_scale(p_ptr, SKILL_DEVICE, 500);
5802 			break;
5803 #endif	// 0
5804 		case ART_HURIN:
5805 			(void)set_fast(Ind, randint(50) + 50, 10); /* removed stacking */
5806 			hp_player(Ind, 30);
5807 			set_afraid(Ind, 0);
5808 			set_shero(Ind, randint(50) + 50); /* removed stacking */
5809 			o_ptr->timeout = rand_int(75) + 175 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5810 			break;
5811 		case ART_AXE_GOTHMOG:
5812 			msg_print(Ind, "Your lochaber axe erupts in fire...");
5813 			p_ptr->current_activation = item;
5814 			get_aim_dir(Ind);
5815 			return;
5816 		case ART_MELKOR:
5817 			msg_print(Ind, "Your spear is covered of darkness...");
5818 			p_ptr->current_activation = item;
5819 			get_aim_dir(Ind);
5820 			return;
5821 #if 0 /* not suited for multiplayer, and it's like an amulet of life-saving anyway */
5822 		case ART_GROND:
5823 			msg_print(Ind, "Your hammer hits the floor...");
5824 			alter_reality();
5825 			o_ptr->timeout = 20000;
5826 			break;
5827 #endif
5828 		case ART_NATUREBANE:
5829 			msg_print(Ind, "Your axe glows blood red...");
5830 			//dispel_monsters(500 + get_skill_scale(p_ptr, SKILL_DEVICE, 500));
5831 			do_banish_animals(Ind, 80);
5832 			o_ptr->timeout = 200 + randint(200) - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5833 			break;
5834 		case ART_NIGHT:
5835 			msg_print(Ind, "Your axe emits a black aura...");
5836 			p_ptr->current_activation = item;
5837 			get_aim_dir(Ind);
5838 			return;
5839 #if 1
5840 		case ART_ORCHAST:
5841 			msg_print(Ind, "Your weapon glows brightly...");
5842 			(void)detect_monsters_xxx(Ind, RF3_ORC);
5843 			o_ptr->timeout = 10;
5844 			break;
5845 #endif	// 0
5846 		/* ToNE-NET additions */
5847 		case ART_BILBO:
5848 			msg_print(Ind, "Your picklock flashes...");
5849 			destroy_doors_touch(Ind, 2);
5850 			o_ptr->timeout = 30 + randint(10) - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
5851 			break;
5852 		case ART_SOULCURE:
5853 			if (p_ptr->blessed_power <= 20) {
5854 				msg_print(Ind, "Your gloves glow golden...");
5855 				p_ptr->blessed_power = 20;
5856 				set_blessed(Ind, randint(48) + 24); /* removed stacking */
5857 				o_ptr->timeout = 150 + randint(100) - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5858 			} else {
5859 				msg_print(Ind, "Your gloves shimmer..");
5860 			}
5861 			break;
5862 		case ART_AMUGROM:
5863 			msg_print(Ind, "The amulet sparkles in scintillating colours...");
5864 			o_ptr->timeout = 150 + randint(50) - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5865 			(void)set_oppose_acid(Ind, randint(30) + 40); /* removed stacking */
5866 			(void)set_oppose_elec(Ind, randint(30) + 40);
5867 			(void)set_oppose_fire(Ind, randint(30) + 40);
5868 			(void)set_oppose_cold(Ind, randint(30) + 40);
5869 			(void)set_oppose_pois(Ind, randint(30) + 40);
5870 			break;
5871 		case ART_SPIRITSHARD:
5872 			msg_print(Ind, "Shimmers and flashes travel over the surface of the amulet...");
5873 			o_ptr->timeout = 100 + randint(50) - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
5874 			(void)set_tim_wraith(Ind, 50 + rand_int(11));
5875 			break;
5876 		case ART_PHASING:
5877 			msg_print(Ind, "Your surroundings fade.. you are carried away through a tunnel of light!");
5878 //			msg_print(Ind, "You hear a voice, saying 'Sorry, not yet implemented!'");
5879 			o_ptr->timeout = 1000;
5880 			p_ptr->auto_transport = AT_VALINOR;
5881 			//p_ptr->paralyzed = 1; /* Paranoia? In case there is a timing glitch, allowing to drop the Ring of Phasing before arriving in Valinor ;) */
5882 			break;
5883 		case ART_LEBOHAUM:
5884 			msg_print(Ind, "\377wYou hear a little song in your head in some unknown tongue:");
5885 			msg_print(Ind, "\377u ~'Avec le casque Lebohaum y a jamais d'anicroches, je parcours les dongeons,~");
5886 			msg_print(Ind, "\377u ~j'en prend plein la caboche. Avec le casque Lebohaum, tout ces monstres a la~");
5887 			msg_print(Ind, "\377u ~con, je leur met bien profond: c'est moi le maitre du dongeon!~'");
5888 			o_ptr->timeout = 30;
5889 			break;
5890 		default: done = FALSE;
5891 		}
5892 
5893 		/* Window stuff */
5894 		p_ptr->window |= (PW_INVEN | PW_EQUIP);
5895 
5896 		if (o_ptr->timeout) return;
5897 	}
5898 
5899 	// -------------------- ego items -------------------- //
5900 
5901 	if (!done) {
5902 		if (is_ego_p(o_ptr, EGO_DRAGON)) {
5903 			teleport_player(Ind, 100, FALSE);
5904 			o_ptr->timeout = 50 + randint(35) - get_skill_scale(p_ptr, SKILL_DEVICE, 35);
5905 			/* Window stuff */
5906 			p_ptr->window |= (PW_INVEN | PW_EQUIP);
5907 			/* Done */
5908 			return;
5909 		} else if (is_ego_p(o_ptr, EGO_JUMP)) {
5910 			teleport_player(Ind, 10, TRUE);
5911 			o_ptr->timeout = 10 + randint(10);
5912 			/* Window stuff */
5913 			p_ptr->window |= (PW_INVEN | PW_EQUIP);
5914 			/* Done */
5915 			return;
5916 		} else if (is_ego_p(o_ptr, EGO_SPINNING)) {
5917 			//do_spin(Ind);
5918 			spin_attack(Ind); /* this one is nicer than do_spin */
5919 			o_ptr->timeout = 50 + randint(25);
5920 			/* Window stuff */
5921 			p_ptr->window |= (PW_INVEN | PW_EQUIP);
5922 			/* Done */
5923 			return;
5924 		} else if (is_ego_p(o_ptr, EGO_FURY)) {
5925 			set_afraid(Ind, 0);
5926 			set_fury(Ind, rand_int(5) + 15); /* removed stacking */
5927 			hp_player(Ind, 40);
5928 			o_ptr->timeout = 100 + randint(50) - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
5929 			/* Window stuff */
5930 			p_ptr->window |= (PW_INVEN | PW_EQUIP);
5931 			/* Done */
5932 			return;
5933 		} else if (is_ego_p(o_ptr, EGO_NOLDOR)) {
5934 			detect_treasure(Ind, DEFAULT_RADIUS * 2);
5935 			o_ptr->timeout = 10 + randint(20);
5936 			/* Window stuff */
5937 			p_ptr->window |= (PW_INVEN | PW_EQUIP);
5938 			/* Done */
5939 			return;
5940 		} else if (is_ego_p(o_ptr, EGO_SPECTRAL)) {
5941 			//set_shadow(Ind, 20 + randint(20));
5942 			set_tim_wraith(Ind, 15 + randint(10));
5943 			o_ptr->timeout = 50 + randint(50) - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
5944 			/* Window stuff */
5945 			p_ptr->window |= PW_INVEN | PW_EQUIP;
5946 			/* Done */
5947 			return;
5948 		} else if (is_ego_p(o_ptr, EGO_CLOAK_LORDLY_RES)) {
5949 			msg_print(Ind, "Your cloak flashes many colors...");
5950 			(void)set_oppose_acid(Ind, randint(20) + 50); /* removed stacking */
5951 			(void)set_oppose_elec(Ind, randint(20) + 50);
5952 			(void)set_oppose_fire(Ind, randint(20) + 50);
5953 			(void)set_oppose_cold(Ind, randint(20) + 50);
5954 			(void)set_oppose_pois(Ind, randint(20) + 50);
5955 			o_ptr->timeout = rand_int(40) + 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5956 			return;
5957 		} else if (is_ego_p(o_ptr, EGO_AURA_FIRE2)) {
5958 		//else if (is_ego_p(o_ptr, EGO_AURA_FIRE) || is_ego_p(o_ptr, EGO_AURA_FIRE2)) {
5959 			msg_print(Ind, "Your cloak flashes in flames...");
5960 			(void)set_oppose_fire(Ind, randint(40) + 40);
5961 			o_ptr->timeout = rand_int(40) + 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5962 			return;
5963 		} else if (is_ego_p(o_ptr, EGO_AURA_ELEC2)) {
5964 		//else if (is_ego_p(o_ptr, EGO_AURA_ELEC) || is_ego_p(o_ptr, EGO_AURA_ELEC2)) {
5965 			msg_print(Ind, "Your cloak sparkles with lightning...");
5966 			(void)set_oppose_elec(Ind, randint(40) + 40);
5967 			o_ptr->timeout = rand_int(40) + 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5968 			return;
5969 		} else if (is_ego_p(o_ptr, EGO_AURA_COLD2)) {
5970 		//else if (is_ego_p(o_ptr, EGO_AURA_COLD) || is_ego_p(o_ptr, EGO_AURA_COLD2)) {
5971 			msg_print(Ind, "Your cloak shines with frost...");
5972 			(void)set_oppose_cold(Ind, randint(40) + 40);
5973 			o_ptr->timeout = rand_int(40) + 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
5974 			return;
5975 		}
5976 	}
5977 
5978 	// -------------------- base items -------------------- //
5979 
5980 	/* Hack -- Dragon Scale Mail can be activated as well */
5981 	/* Yikes, hard-coded r_idx.. */
5982 	if (!done && o_ptr->tval == TV_DRAG_ARMOR && item == INVEN_BODY) {
5983 		/* Breath activation */
5984 		p_ptr->current_activation = item;
5985 		get_aim_dir(Ind);
5986 		return;
5987 	}
5988 
5989 	/* Hack -- Amulet of the Serpents can be activated as well */
5990 	if (!done && o_ptr->tval == TV_AMULET) {
5991 		switch (o_ptr->sval) {
5992 		case SV_AMULET_SERPENT:
5993 			/* Get a direction for breathing (or abort) */
5994 			p_ptr->current_activation = item;
5995 			get_aim_dir(Ind);
5996 			return;
5997 		/* Amulets of the moon can be activated for sleep monster */
5998 		case SV_AMULET_THE_MOON:
5999 			msg_print(Ind, "Your amulet glows a deep blue...");
6000 			sleep_monsters(Ind, 20 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 80));
6001 			o_ptr->timeout = rand_int(100) + 100;
6002 			return;
6003 		/* Amulets of rage can be activated for berserk strength */
6004 		case SV_AMULET_RAGE:
6005 			msg_print(Ind, "Your amulet sparkles bright red...");
6006     	                set_afraid(Ind, 0);
6007 		        set_fury(Ind, randint(10) + 15); /* removed stacking */
6008 	                hp_player(Ind, 40);
6009 			o_ptr->timeout = rand_int(150) + 250;
6010 			return;
6011 		}
6012 	}
6013 
6014 	if (!done && o_ptr->tval == TV_RING) {
6015 		switch (o_ptr->sval) {
6016 			case SV_RING_ELEC:
6017 			case SV_RING_ACID:
6018 			case SV_RING_ICE:
6019 			case SV_RING_FLAMES:
6020 				/* Get a direction for breathing (or abort) */
6021 				p_ptr->current_activation = item;
6022 				get_aim_dir(Ind);
6023 				return;
6024 			/* Yes, this can be activated but at the cost of it's destruction */
6025 			case SV_RING_TELEPORTATION:
6026 //				if (!get_check("This will destroy the ring, do you want to continue ?")) break;
6027 				msg_print(Ind, "The ring explode into a space distorsion.");
6028 				teleport_player(Ind, 200, FALSE);
6029 
6030 				/* It explodes, doesnt it ? */
6031 				take_hit(Ind, damroll(2, 10), "an exploding ring", 0);
6032 
6033 				inven_item_increase(Ind, item, -255);
6034 				inven_item_optimize(Ind, item);
6035 				break;
6036 			case SV_RING_POLYMORPH:
6037 				if (!(item == INVEN_LEFT || item == INVEN_RIGHT)){
6038 					msg_print(Ind, "You must be wearing the ring!");
6039 					return;
6040 				}
6041 				if (!get_skill(p_ptr, SKILL_MIMIC) ||
6042 				    (p_ptr->pclass == CLASS_DRUID) ||
6043 				    (p_ptr->prace == RACE_VAMPIRE) ||
6044 				    (p_ptr->pclass == CLASS_SHAMAN && !mimic_shaman(o_ptr->pval))) {
6045 					msg_print(Ind, "The ring starts to glow brightly, then fades again");
6046 					return;
6047 				}
6048 
6049 				/* If never used before, then set to the player form,
6050 				 * otherwise set the player form*/
6051 				if (!o_ptr->pval) {
6052 					if ((p_ptr->r_killed[p_ptr->body_monster] < r_info[p_ptr->body_monster].level) ||
6053 					    (get_skill_scale(p_ptr, SKILL_MIMIC, 100) < r_info[p_ptr->body_monster].level))
6054 						msg_print(Ind, "Nothing happens");
6055 					else if (r_info[p_ptr->body_monster].level == 0)
6056 						msg_print(Ind, "The ring starts to glow brightly, then fades again");
6057 					else {
6058 						msg_format(Ind, "The form of the ring seems to change to a small %s.", r_info[p_ptr->body_monster].name + r_name);
6059 						o_ptr->pval = p_ptr->body_monster;
6060 
6061 						/* Set appropriate level requirements */
6062 						o_ptr->level = ring_of_polymorph_level(r_info[p_ptr->body_monster].level);
6063 
6064 						/* Make the ring last only over a certain period of time >:) - C. Blue */
6065 						o_ptr->timeout = 3000 + get_skill_scale(p_ptr, SKILL_DEVICE, 2000) +
6066 								rand_int(3001 - get_skill_scale(p_ptr, SKILL_DEVICE, 2000));
6067 
6068 						msg_print(Ind, "Your knowledge is absorbed by the ring!");
6069 						p_ptr->r_killed[p_ptr->body_monster] = 0;
6070 
6071 						/* If player hasn't got high enough kill count anymore now, poly back to player form! */
6072 						if (p_ptr->r_killed[p_ptr->body_monster] < r_info[p_ptr->body_monster].level)
6073 							do_mimic_change(Ind, 0, TRUE);
6074 
6075 						object_aware(Ind, o_ptr);
6076 						object_known(o_ptr);
6077 
6078 						/* log it */
6079 						s_printf("POLYRING_CREATE: %s -> %s (%d/%d, %d).\n",
6080 						    p_ptr->name, r_info[o_ptr->pval].name + r_name,
6081 						    o_ptr->level, r_info[o_ptr->pval].level,
6082 						    o_ptr->timeout);
6083 					}
6084 				}
6085 				/* activate the ring to change into its form! */
6086 				else {
6087 					/* Need skill; no need of killing count */
6088 					if (r_info[o_ptr->pval].level > get_skill_scale(p_ptr, SKILL_MIMIC, 100)) {
6089 						msg_print(Ind, "Your mimicry is not powerful enough yet.");
6090 						return;
6091 					}
6092 
6093 #if POLY_RING_METHOD == 0
6094 					/* Poly first, break then :) */
6095 					/* reversed again since you need need to keep wearing the ring
6096 					   or you will polymorph back */
6097 					/* Take toll ('overhead energy') for activating */
6098 					if (o_ptr->timeout >= 1000) o_ptr->timeout -= 500; /* 500 are approx. 5 minutes */
6099 					else if (o_ptr->timeout > 1) o_ptr->timeout /= 2;
6100 
6101 					do_mimic_change(Ind, o_ptr->pval, TRUE);
6102 
6103 					/* log it */
6104 					s_printf("POLYRING_ACTIVATE_0: %s -> %s (%d/%d, %d).\n",
6105 					    p_ptr->name, r_info[o_ptr->pval].name + r_name,
6106 					    o_ptr->level, r_info[o_ptr->pval].level,
6107 					    o_ptr->timeout);
6108 #endif
6109 
6110 #if POLY_RING_METHOD == 1
6111 					msg_print(Ind, "\377yThe ring disintegrates, releasing a powerful magic wave!");
6112 					do_mimic_change(Ind, o_ptr->pval, TRUE);
6113 					p_ptr->tim_mimic = o_ptr->timeout;
6114 					p_ptr->tim_mimic_what = o_ptr->pval;
6115 
6116 					/* log it */
6117 					s_printf("POLYRING_ACTIVATE_1: %s -> %s (%d/%d, %d).\n",
6118 					    p_ptr->name, r_info[o_ptr->pval].name + r_name,
6119 					    o_ptr->level, r_info[o_ptr->pval].level,
6120 					    o_ptr->timeout);
6121 
6122 				        inven_item_increase(Ind, item, -1);
6123 		    		        inven_item_optimize(Ind, item);
6124 #endif
6125 
6126 				}
6127 				break;
6128 		}
6129 
6130 		/* Window stuff */
6131 		p_ptr->window |= (PW_INVEN | PW_EQUIP);
6132 
6133 		/* Success */
6134 		return;
6135 
6136 	}
6137 
6138 	/* Mistake */
6139 	msg_print(Ind, "That object cannot be activated.");
6140 }
6141 
6142 
6143 void do_cmd_activate_dir(int Ind, int dir) {
6144 	player_type *p_ptr = Players[Ind];
6145 	object_type *o_ptr;
6146 	int item;
6147 	bool done = FALSE;
6148 
6149 	item = p_ptr->current_activation;
6150 
6151 	if (p_ptr->anti_magic) {
6152 		msg_format(Ind, "\377%cYour anti-magic shell disrupts your attempt.", COLOUR_AM_OWN);
6153 		return;
6154 	}
6155 	if (get_skill(p_ptr, SKILL_ANTIMAGIC)) {
6156 		msg_format(Ind, "\377%cYou don't believe in magic.", COLOUR_AM_OWN);
6157 		return;
6158 	}
6159 	if (magik((p_ptr->antimagic * 8) / 5)) {
6160 		msg_format(Ind, "\377%cYour anti-magic field disrupts your attempt.", COLOUR_AM_OWN);
6161 		return;
6162 	}
6163 
6164 	/* Get the item (in the pack) */
6165 	if (item >= 0) o_ptr = &p_ptr->inventory[item];
6166 	/* Get the item (on the floor) */
6167 	else {
6168 		if (-item >= o_max) return; /* item doesn't exist */
6169 		o_ptr = &o_list[0 - item];
6170 	}
6171 
6172 	/* If the item can be equipped, it MUST be equipped to be activated */
6173 	if ((item < INVEN_WIELD) && wearable_p(o_ptr)) {
6174 		msg_print(Ind, "You must be using this item to activate it.");
6175 		return;
6176 	}
6177 
6178 	if (check_guard_inscription(o_ptr->note, 'A')) {
6179 		msg_print(Ind, "The item's inscription prevents it.");
6180 		return;
6181 	};
6182 
6183 	if (!can_use_verbose(Ind, o_ptr)) return;
6184 
6185 	break_cloaking(Ind, 0);
6186 	stop_precision(Ind);
6187 	stop_shooting_till_kill(Ind);
6188 
6189 	// -------------------- artifacts -------------------- //
6190 
6191 	/* Artifacts activate by name */
6192 	if (o_ptr->name1 && o_ptr->name1 != ART_RANDART) {
6193 		done = TRUE;
6194 		switch (o_ptr->name1) {
6195 		case ART_NARTHANC:
6196 			sprintf(p_ptr->attacker, " fires a fire bolt for");
6197 			fire_bolt(Ind, GF_FIRE, dir, damroll(9 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6198 			o_ptr->timeout = rand_int(4) + 8 - get_skill_scale(p_ptr, SKILL_DEVICE, 6);
6199 			break;
6200 		case ART_NIMTHANC:
6201 			sprintf(p_ptr->attacker, " fires a frost bolt for");
6202 			fire_bolt(Ind, GF_COLD, dir, damroll(6 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6203 			o_ptr->timeout = rand_int(3) + 7 - get_skill_scale(p_ptr, SKILL_DEVICE, 5);
6204 			break;
6205 		case ART_DETHANC:
6206 			sprintf(p_ptr->attacker, " fires a lightning bolt for");
6207 			fire_bolt(Ind, GF_ELEC, dir, damroll(4 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6208 			o_ptr->timeout = rand_int(3) + 6 - get_skill_scale(p_ptr, SKILL_DEVICE, 4);
6209 			break;
6210 		case ART_RILIA:
6211 			sprintf(p_ptr->attacker, " casts a stinking cloud for");
6212 			//fire_ball(Ind, GF_POIS, dir, 12 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 3, p_ptr->attacker);
6213 			fire_cloud(Ind, GF_POIS, dir, 4 + get_skill_scale_fine(p_ptr, SKILL_DEVICE, 7), 3, 4, 9, p_ptr->attacker);
6214 			o_ptr->timeout = rand_int(2) + 4 - get_skill_scale(p_ptr, SKILL_DEVICE, 2);
6215 			break;
6216 		case ART_BELANGIL:
6217 			sprintf(p_ptr->attacker, " casts a cold ball for");
6218 			fire_ball(Ind, GF_COLD, dir, 48 + get_skill_scale(p_ptr, SKILL_DEVICE, 60), 2, p_ptr->attacker);
6219 			o_ptr->timeout = rand_int(2) + 5 - get_skill_scale(p_ptr, SKILL_DEVICE, 3);
6220 			break;
6221 		case ART_RINGIL:
6222 			sprintf(p_ptr->attacker, " casts a cold ball for");
6223 			fire_ball(Ind, GF_COLD, dir, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 2, p_ptr->attacker);
6224 			o_ptr->timeout = 300 - get_skill_scale(p_ptr, SKILL_DEVICE, 225);
6225 			break;
6226 		case ART_ANDURIL:
6227 			sprintf(p_ptr->attacker, " casts a fire ball for");
6228 			fire_ball(Ind, GF_FIRE, dir, 72 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6229 			o_ptr->timeout = 400 - get_skill_scale(p_ptr, SKILL_DEVICE, 300);
6230 			break;
6231 		case ART_FIRESTAR:
6232 			sprintf(p_ptr->attacker, " casts a fire ball for");
6233 			fire_ball(Ind, GF_FIRE, dir, 72 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 3, p_ptr->attacker);
6234 			o_ptr->timeout = 100 - get_skill_scale(p_ptr, SKILL_DEVICE, 75);
6235 			break;
6236 		case ART_THEODEN:
6237 			if (drain_life(Ind, dir, 25))
6238 				hp_player(Ind, p_ptr->ret_dam / 3);
6239 			p_ptr->ret_dam = 0;
6240 			o_ptr->timeout = 400 - get_skill_scale(p_ptr, SKILL_DEVICE, 300);
6241 			break;
6242 		case ART_TURMIL:
6243 			if (drain_life(Ind, dir, 15))
6244 				hp_player(Ind, p_ptr->ret_dam / 2);
6245 			p_ptr->ret_dam = 0;
6246 			o_ptr->timeout = 70 - get_skill_scale(p_ptr, SKILL_DEVICE, 50);
6247 			break;
6248 		case ART_ARUNRUTH:
6249 			sprintf(p_ptr->attacker, " fires a frost bolt for");
6250 			fire_bolt(Ind, GF_COLD, dir, damroll(12 + get_skill_scale(p_ptr, SKILL_DEVICE, 15), 8), p_ptr->attacker);
6251 			o_ptr->timeout = 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 400);
6252 			break;
6253 		case ART_AEGLOS:
6254 			sprintf(p_ptr->attacker, " casts a cold ball for");
6255 			fire_ball(Ind, GF_COLD, dir, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6256 			o_ptr->timeout = 500 - get_skill_scale(p_ptr, SKILL_DEVICE, 400);
6257 			break;
6258 		case ART_OROME:
6259 			wall_to_mud(Ind, dir);
6260 			o_ptr->timeout = 5 - get_skill_scale(p_ptr, SKILL_DEVICE, 3);
6261 			break;
6262 		case ART_ULMO:
6263 			teleport_monster(Ind, dir);
6264 			o_ptr->timeout = 150 - get_skill_scale(p_ptr, SKILL_DEVICE, 100);
6265 			break;
6266 		case ART_TOTILA:
6267 			confuse_monster(Ind, dir, 10 + p_ptr->lev + get_skill_scale(p_ptr, SKILL_DEVICE, 50));
6268 			o_ptr->timeout = 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 40);
6269 			break;
6270 		case ART_CAMMITHRIM:
6271 			sprintf(p_ptr->attacker, " fires a missile for");
6272 			fire_bolt(Ind, GF_MISSILE, dir, damroll(2 + get_skill_scale(p_ptr, SKILL_DEVICE, 8), 6), p_ptr->attacker);
6273 			o_ptr->timeout = 2 - get_skill_scale(p_ptr, SKILL_DEVICE, 1);
6274 			break;
6275 		case ART_PAURHACH:
6276 			sprintf(p_ptr->attacker, " fires a fire bolt for");
6277 			fire_bolt(Ind, GF_FIRE, dir, damroll(9 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6278 			o_ptr->timeout = rand_int(4) + 8 - get_skill_scale(p_ptr, SKILL_DEVICE, 6);
6279 			break;
6280 		case ART_PAURNIMMEN:
6281 			sprintf(p_ptr->attacker, " fires a frost bolt for");
6282 			fire_bolt(Ind, GF_COLD, dir, damroll(6 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6283 			o_ptr->timeout = rand_int(3) + 7 - get_skill_scale(p_ptr, SKILL_DEVICE, 5);
6284 			break;
6285 		case ART_PAURAEGEN:
6286 			sprintf(p_ptr->attacker, " fires a lightning bolt for");
6287 			fire_bolt(Ind, GF_ELEC, dir, damroll(4 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6288 			o_ptr->timeout = rand_int(3) + 6 - get_skill_scale(p_ptr, SKILL_DEVICE, 4);
6289 			break;
6290 		case ART_PAURNEN:
6291 			sprintf(p_ptr->attacker, " fires an acid bolt for");
6292 			fire_bolt(Ind, GF_ACID, dir, damroll(5 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6293 			o_ptr->timeout = rand_int(2) + 5 - get_skill_scale(p_ptr, SKILL_DEVICE, 3);
6294 			break;
6295 		case ART_FINGOLFIN:
6296 			sprintf(p_ptr->attacker, " fires an arrow for");
6297 			fire_bolt(Ind, GF_ARROW, dir, 150, p_ptr->attacker);
6298 			o_ptr->timeout = rand_int(30) + 90 - get_skill_scale(p_ptr, SKILL_DEVICE, 75);
6299 			break;
6300 		case ART_NARYA:
6301 			sprintf(p_ptr->attacker, " casts a fire ball for");
6302 			fire_ball(Ind, GF_FIRE, dir, 120 + get_skill_scale(p_ptr, SKILL_DEVICE, 250), 3, p_ptr->attacker);
6303 			o_ptr->timeout = rand_int(75) + 225 - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
6304 			break;
6305 		case ART_NENYA:
6306 			sprintf(p_ptr->attacker, " casts a cold ball for");
6307 			fire_ball(Ind, GF_COLD, dir, 200 + get_skill_scale(p_ptr, SKILL_DEVICE, 250), 3, p_ptr->attacker);
6308 			o_ptr->timeout = rand_int(125) + 325 - get_skill_scale(p_ptr, SKILL_DEVICE, 225);
6309 			break;
6310 		case ART_VILYA:
6311 			sprintf(p_ptr->attacker, " casts a lightning ball for");
6312 			fire_ball(Ind, GF_ELEC, dir, 250 + get_skill_scale(p_ptr, SKILL_DEVICE, 250), 3, p_ptr->attacker);
6313 			o_ptr->timeout = rand_int(175) + 425 - get_skill_scale(p_ptr, SKILL_DEVICE, 325);
6314 			break;
6315 		case ART_POWER:
6316 			ring_of_power(Ind, dir);
6317 			o_ptr->timeout = rand_int(450) + 450;
6318 			break;
6319 		case ART_MEDIATOR:
6320 			msg_print(Ind, "You breathe the elements.");
6321 			sprintf(p_ptr->attacker, " breathes the elements for");
6322 			fire_ball(Ind, GF_MISSILE, dir, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 4, p_ptr->attacker);
6323 			msg_print(Ind, "Your armour glows in many colours...");
6324 			(void)set_afraid(Ind, 0);
6325 			(void)set_shero(Ind, randint(50) + 50); /* removed stacking */
6326 			(void)hp_player(Ind, 30);
6327 			p_ptr->blessed_power = 20;
6328 			(void)set_blessed(Ind, randint(50) + 50); /* removed stacking */
6329 			(void)set_oppose_acid(Ind, randint(50) + 50); /* removed stacking */
6330 			(void)set_oppose_elec(Ind, randint(50) + 50);
6331 			(void)set_oppose_fire(Ind, randint(50) + 50);
6332 			(void)set_oppose_cold(Ind, randint(50) + 50);
6333 			(void)set_oppose_pois(Ind, randint(50) + 50);
6334 			o_ptr->timeout = 400 - get_skill_scale(p_ptr, SKILL_DEVICE, 300);
6335 			break;
6336 		case ART_EREBOR:
6337 			if (do_prob_travel(Ind, dir)) {
6338 				msg_print(Ind, "You found a passage!");
6339 				o_ptr->timeout = 200 - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
6340 			} else msg_print(Ind, "Nothing happens!");
6341 			break;
6342 		case ART_AXE_GOTHMOG:
6343 			sprintf(p_ptr->attacker, " casts a fireball for");
6344 			fire_ball(Ind, GF_FIRE, dir, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 4, p_ptr->attacker);
6345 			o_ptr->timeout = 200 + rand_int(200) - get_skill_scale(p_ptr, SKILL_DEVICE, 150);
6346 			break;
6347 		case ART_MELKOR:
6348 			sprintf(p_ptr->attacker, " casts a darkness storm for");
6349 			fire_ball(Ind, GF_DARK, dir, 150 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 3, p_ptr->attacker);
6350 			o_ptr->timeout = 100 - get_skill_scale(p_ptr, SKILL_DEVICE, 80);
6351 			break;
6352 		case ART_NIGHT:
6353 		{
6354 			int i;
6355 			for (i = 0; i < 3; i++) {
6356 				if (drain_life(Ind, dir, 7))
6357 					hp_player(Ind, p_ptr->ret_dam / 2);
6358 				p_ptr->ret_dam = 0;
6359 			}
6360 			o_ptr->timeout = 250 - get_skill_scale(p_ptr, SKILL_DEVICE, 200);
6361 			break;
6362 		}
6363 		case ART_NAIN:
6364 			wall_to_mud(Ind, dir);
6365 			o_ptr->timeout = rand_int(5) + 7 - get_skill_scale(p_ptr, SKILL_DEVICE, 3);
6366 			break;
6367 		case ART_EOL:
6368 			sprintf(p_ptr->attacker, " fires a mana bolt for");
6369 			fire_bolt(Ind, GF_MANA, dir, damroll(9 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 8), p_ptr->attacker);
6370 			o_ptr->timeout = rand_int(3) + 7 - get_skill_scale(p_ptr, SKILL_DEVICE, 5);
6371 			break;
6372 		case ART_UMBAR:
6373 			sprintf(p_ptr->attacker, " fires a missile for");
6374 			fire_bolt(Ind, GF_MISSILE, dir, damroll(10 + get_skill_scale(p_ptr, SKILL_DEVICE, 20), 10), p_ptr->attacker);
6375 			o_ptr->timeout = rand_int(10) + 20 - get_skill_scale(p_ptr, SKILL_DEVICE, 15);
6376 			break;
6377 		case ART_HELLFIRE:
6378 			sprintf(p_ptr->attacker, " conjures up hellfire for");
6379 			fire_ball(Ind, GF_HELL_FIRE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 3, p_ptr->attacker);
6380 			o_ptr->timeout = randint(10) + 30;
6381 			break;
6382 		case ART_HAVOC:
6383 			sprintf(p_ptr->attacker, " casts a force bolt for");
6384 			fire_bolt(Ind, GF_FORCE, dir, damroll(8 + get_skill_scale(p_ptr, SKILL_DEVICE, 16), 8), p_ptr->attacker);
6385 			o_ptr->timeout = rand_int(2) + 1;
6386 			break;
6387 		default: done = FALSE;
6388 		}
6389 	}
6390 
6391 	// -------------------- ego items -------------------- //
6392 
6393 	// -------------------- base items -------------------- //
6394 
6395 	if (!done && o_ptr->tval == TV_DRAG_ARMOR && item == INVEN_BODY) {
6396 		switch (o_ptr->sval) {
6397 		case SV_DRAGON_BLACK:
6398 			msg_print(Ind, "You breathe acid.");
6399 			sprintf(p_ptr->attacker, " breathes acid for");
6400 			fire_ball(Ind, GF_ACID, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6401 			break;
6402 		case SV_DRAGON_BLUE:
6403 			msg_print(Ind, "You breathe lightning.");
6404 			sprintf(p_ptr->attacker, " breathes lightning for");
6405 			fire_ball(Ind, GF_ELEC, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6406 			break;
6407 		case SV_DRAGON_WHITE:
6408 			msg_print(Ind, "You breathe frost.");
6409 			sprintf(p_ptr->attacker, " breathes frost for");
6410 			fire_ball(Ind, GF_COLD, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6411 			break;
6412 		case SV_DRAGON_RED:
6413 			msg_print(Ind, "You breathe fire.");
6414 			sprintf(p_ptr->attacker, " breathes fire for");
6415 			fire_ball(Ind, GF_FIRE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6416 			break;
6417 		case SV_DRAGON_GREEN:
6418 			msg_print(Ind, "You breathe poison.");
6419 			sprintf(p_ptr->attacker, " breathes poison for");
6420 			fire_ball(Ind, GF_POIS, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6421 			break;
6422 		case SV_DRAGON_MULTIHUED:
6423 			switch(rand_int(5)){
6424 			case 0:	msg_print(Ind, "You breathe acid.");
6425 				sprintf(p_ptr->attacker, " breathes acid for");
6426 				fire_ball(Ind, GF_ACID, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6427 				break;
6428 			case 1:	msg_print(Ind, "You breathe lightning.");
6429 				sprintf(p_ptr->attacker, " breathes lightning for");
6430 				fire_ball(Ind, GF_ELEC, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6431 				break;
6432 			case 2:	msg_print(Ind, "You breathe frost.");
6433 				sprintf(p_ptr->attacker, " breathes frost for");
6434 				fire_ball(Ind, GF_COLD, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6435 				break;
6436 			case 3:	msg_print(Ind, "You breathe fire.");
6437 				sprintf(p_ptr->attacker, " breathes fire for");
6438 				fire_ball(Ind, GF_FIRE, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6439 				break;
6440 			case 4:	msg_print(Ind, "You breathe poison.");
6441 				sprintf(p_ptr->attacker, " breathes poison for");
6442 				fire_ball(Ind, GF_POIS, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6443 				break;
6444 			}
6445 			break;
6446 		case SV_DRAGON_PSEUDO:
6447 			if (magik(50)) {
6448 				msg_print(Ind, "You breathe light.");
6449 				sprintf(p_ptr->attacker, " breathes light for");
6450 				fire_ball(Ind, GF_LITE, dir, 200 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 4, p_ptr->attacker);
6451 			} else {
6452 				msg_print(Ind, "You breathe darkness.");
6453 				sprintf(p_ptr->attacker, " breathes darkness for");
6454 				fire_ball(Ind, GF_DARK, dir, 200 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 4, p_ptr->attacker);
6455 			}
6456 			break;
6457 		case SV_DRAGON_SHINING:
6458 			if (magik(50)) {
6459 				msg_print(Ind, "You breathe light.");
6460 				sprintf(p_ptr->attacker, " breathes light for");
6461 				fire_ball(Ind, GF_LITE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6462 			} else {
6463 				msg_print(Ind, "You breathe darkness.");
6464 				sprintf(p_ptr->attacker, " breathes darkness for");
6465 				fire_ball(Ind, GF_DARK, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6466 			}
6467 			break;
6468 		case SV_DRAGON_LAW:
6469 			switch(rand_int(2)){
6470 			case 0:	msg_print(Ind, "You breathe shards.");
6471 				sprintf(p_ptr->attacker, " breathes shards for");
6472 				fire_ball(Ind, GF_SHARDS, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6473 				break;
6474 			case 1:	msg_print(Ind, "You breathe sound.");
6475 				sprintf(p_ptr->attacker, " breathes sound for");
6476 				fire_ball(Ind, GF_SOUND, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6477 				break;
6478 			}
6479 			break;
6480 		case SV_DRAGON_BRONZE:
6481 			msg_print(Ind, "You breathe confusion.");
6482 			sprintf(p_ptr->attacker, " breathes confusion for");
6483 			fire_ball(Ind, GF_CONFUSION, dir, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 4, p_ptr->attacker);
6484 			break;
6485 		case SV_DRAGON_GOLD:
6486 			msg_print(Ind, "You breathe sound.");
6487 			sprintf(p_ptr->attacker, " breathes sound for");
6488 			fire_ball(Ind, GF_SOUND, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6489 			break;
6490 		case SV_DRAGON_CHAOS:
6491 			msg_print(Ind, "You breathe chaos.");
6492 			sprintf(p_ptr->attacker, " breathes chaos for");
6493 			fire_ball(Ind, GF_CHAOS, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6494 			break;
6495 		case SV_DRAGON_BALANCE:
6496 			msg_print(Ind, "You breathe disenchantment.");
6497 			sprintf(p_ptr->attacker, " breathes disenchantment for");
6498 			fire_ball(Ind, GF_DISENCHANT, dir, 500 + get_skill_scale(p_ptr, SKILL_DEVICE, 500), 4, p_ptr->attacker);
6499 			break;
6500 		case SV_DRAGON_POWER:
6501 			msg_print(Ind, "You breathe havoc.");
6502 			sprintf(p_ptr->attacker, " breathes havoc for");
6503 			//fire_ball(Ind, GF_MISSILE, dir, 300, 4, p_ptr->attacker);
6504 			//Increased from 1k to 2k since base dmg from call_chaos was lowered (havoc rods rebalancing)
6505 			call_chaos(Ind, dir, get_skill_scale(p_ptr, SKILL_DEVICE, 1000));
6506 			break;
6507 		case SV_DRAGON_DEATH:
6508 			msg_print(Ind, "You breathe nether.");
6509 			sprintf(p_ptr->attacker, " breathes nether for");
6510 			fire_ball(Ind, GF_NETHER, dir, 550 + get_skill_scale(p_ptr, SKILL_DEVICE, 500), 4, p_ptr->attacker);
6511 			break;
6512 		case SV_DRAGON_CRYSTAL:
6513 			msg_print(Ind, "You breathe shards.");
6514 			sprintf(p_ptr->attacker, " breathes shards for");
6515 			fire_ball(Ind, GF_SHARDS, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6516 			break;
6517 		case SV_DRAGON_DRACOLICH:
6518 			switch(rand_int(2)){
6519 			case 0:	msg_print(Ind, "You breathe nether.");
6520 				sprintf(p_ptr->attacker, " breathes nether for");
6521 				fire_ball(Ind, GF_NETHER, dir, 550 + get_skill_scale(p_ptr, SKILL_DEVICE, 550), 4, p_ptr->attacker);
6522 				break;
6523 			case 1:	msg_print(Ind, "You breathe cold.");
6524 				sprintf(p_ptr->attacker, " breathes cold for");
6525 				fire_ball(Ind, GF_COLD, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6526 				break;
6527 			}
6528 			break;
6529 		case SV_DRAGON_DRACOLISK:
6530 			switch(rand_int(2)){
6531 			case 0:	msg_print(Ind, "You breathe fire.");
6532 				sprintf(p_ptr->attacker, " breathes fire for");
6533 				fire_ball(Ind, GF_FIRE, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6534 				break;
6535 			case 1:	msg_print(Ind, "You breathe nexus.");
6536 				sprintf(p_ptr->attacker, " breathes nexus for");
6537 				fire_ball(Ind, GF_NEXUS, dir, 250 + get_skill_scale(p_ptr, SKILL_DEVICE, 250), 4, p_ptr->attacker);
6538 				break;
6539 			}
6540 			break;
6541 		case SV_DRAGON_SKY:
6542 			switch(rand_int(3)){
6543 			case 0:	msg_print(Ind, "You breathe lightning.");
6544 				sprintf(p_ptr->attacker, " breathes lightning for");
6545 				fire_ball(Ind, GF_ELEC, dir, 600 + get_skill_scale(p_ptr, SKILL_DEVICE, 600), 4, p_ptr->attacker);
6546 				break;
6547 			case 1:	msg_print(Ind, "You breathe light.");
6548 				sprintf(p_ptr->attacker, " breathes light for");
6549 				fire_ball(Ind, GF_LITE, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6550 				break;
6551 			case 2:	msg_print(Ind, "You breathe gravity.");
6552 				sprintf(p_ptr->attacker, " breathes gravity for");
6553 				fire_ball(Ind, GF_GRAVITY, dir, 300 + get_skill_scale(p_ptr, SKILL_DEVICE, 300), 4, p_ptr->attacker);
6554 				break;
6555 			}
6556 			break;
6557 		case SV_DRAGON_SILVER:
6558 			if (magik(50)) {
6559 				msg_print(Ind, "You breathe inertia.");
6560 				sprintf(p_ptr->attacker, " breathes inertia for");
6561 				fire_ball(Ind, GF_INERTIA, dir, 250 + get_skill_scale(p_ptr, SKILL_DEVICE, 250), 4, p_ptr->attacker);
6562 			} else {
6563 				msg_print(Ind, "You breathe cold.");
6564 				sprintf(p_ptr->attacker, " breathes cold for");
6565 				fire_ball(Ind, GF_COLD, dir, 400 + get_skill_scale(p_ptr, SKILL_DEVICE, 400), 4, p_ptr->attacker);
6566 			}
6567 			break;
6568 		}
6569 		o_ptr->timeout = 200 + rand_int(100);
6570 	}
6571 
6572 	/* Hack -- Amulet of the Serpents can be activated as well */
6573 	if (!done && o_ptr->tval == TV_AMULET && o_ptr->sval == SV_AMULET_SERPENT) {
6574 		msg_print(Ind, "You breathe venom...");
6575 		sprintf(p_ptr->attacker, " breathes venom for");
6576 		fire_ball(Ind, GF_POIS, dir, 100 + get_skill_scale(p_ptr, SKILL_DEVICE, 200), 2, p_ptr->attacker);
6577 		o_ptr->timeout = rand_int(60) + 40;
6578 	}
6579 	else if (!done && o_ptr->tval == TV_RING) {
6580 		switch (o_ptr->sval) {
6581 		case SV_RING_ELEC:
6582 			/* Get a direction for breathing (or abort) */
6583 			sprintf(p_ptr->attacker, " casts a lightning ball for");
6584 			fire_ball(Ind, GF_ELEC, dir, 50 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6585 			(void)set_oppose_elec(Ind, randint(20) + 20); /* removed stacking */
6586 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
6587 			break;
6588 		case SV_RING_ACID:
6589 			/* Get a direction for breathing (or abort) */
6590 			sprintf(p_ptr->attacker, " casts an acid ball for");
6591 			fire_ball(Ind, GF_ACID, dir, 50 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6592 			(void)set_oppose_acid(Ind, randint(20) + 20); /* removed stacking */
6593 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
6594 			break;
6595 		case SV_RING_ICE:
6596 			/* Get a direction for breathing (or abort) */
6597 			sprintf(p_ptr->attacker, " casts a frost ball for");
6598 			fire_ball(Ind, GF_COLD, dir, 50 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6599 			(void)set_oppose_cold(Ind, randint(20) + 20); /* removed stacking */
6600 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
6601 			break;
6602 		case SV_RING_FLAMES:
6603 			/* Get a direction for breathing (or abort) */
6604 			sprintf(p_ptr->attacker, " casts a fire ball for");
6605 			fire_ball(Ind, GF_FIRE, dir, 50 + get_skill_scale(p_ptr, SKILL_DEVICE, 150), 2, p_ptr->attacker);
6606 			(void)set_oppose_fire(Ind, randint(20) + 20); /* removed stacking */
6607 			o_ptr->timeout = rand_int(25) + 50 - get_skill_scale(p_ptr, SKILL_DEVICE, 25);
6608 			break;
6609 		}
6610         }
6611 
6612 	/* Clear current activation */
6613 	p_ptr->current_activation = -1;
6614 
6615 	/* Window stuff */
6616 	p_ptr->window |= (PW_INVEN | PW_EQUIP);
6617 
6618 	/* Success */
6619 	return;
6620 }
6621 
6622 bool unmagic(int Ind) {
6623 	player_type *p_ptr = Players[Ind];
6624 	bool ident = FALSE;
6625 
6626 	/* Unmagic has no effect when the player is invulnerable. This prevents
6627 	 * stair-GoI from being canceled prematurely by unmagic mushrooms etc.
6628 	 */
6629 	if (p_ptr->invuln) return FALSE;
6630 
6631 	if (
6632 		set_adrenaline(Ind, 0) |
6633 		set_biofeedback(Ind, 0) |
6634 		set_tim_esp(Ind, 0) |
6635 		set_st_anchor(Ind, 0) |
6636 		set_prob_travel(Ind, 0) |
6637 		set_bow_brand(Ind, 0, 0, 0) |
6638 #if 0
6639 		set_mimic(Ind, 0, 0) |
6640 #endif
6641 #if 0
6642 		(p_ptr->body_monster) |
6643 	if (p_ptr->tim_mimic) do_mimic_change(Ind, 0, TRUE)
6644 #endif
6645 		set_tim_manashield(Ind, 0) |
6646 		set_tim_traps(Ind, 0) |
6647 		set_invis(Ind, 0, 0) |
6648 		set_fury(Ind, 0) |
6649 		set_tim_meditation(Ind, 0) |
6650 		set_tim_wraith(Ind, 0) |
6651 		set_fast(Ind, 0, 0) |
6652 		set_shield(Ind, 0, 0, SHIELD_NONE, 0, 0) |
6653 		set_blessed(Ind, 0) |
6654 		set_hero(Ind, 0) |
6655 		set_shero(Ind, 0) |
6656 		set_protevil(Ind, 0) |
6657 		set_invuln(Ind, 0) |
6658 		set_tim_invis(Ind, 0) |
6659 		set_tim_infra(Ind, 0) |
6660 		set_oppose_acid(Ind, 0) |
6661 		set_oppose_elec(Ind, 0) |
6662 		set_oppose_fire(Ind, 0) |
6663 		set_oppose_cold(Ind, 0) |
6664 		set_oppose_pois(Ind, 0) |
6665 		set_zeal(Ind, 0, 0) |
6666 		set_mindboost(Ind, 0, 0) |
6667 //		set_martyr(Ind, 0) |
6668 		set_sh_fire_tim(Ind, 0) |
6669 		set_sh_cold_tim(Ind, 0) |
6670 		set_sh_elec_tim(Ind, 0) |
6671 		set_tim_deflect(Ind, 0)
6672 	) ident = TRUE;
6673 
6674 	if (p_ptr->word_recall) ident |= set_recall_timer(Ind, 0);
6675 
6676 #if 0 /* taken out because it circumvents the HEALING spell anti-cheeze */
6677 	p_ptr->supp = 0;
6678 	p_ptr->support_timer = 0;
6679 #endif
6680 	return (ident);
6681 }
6682 
6683 /*
6684  * Displays random fortune/rumour.
6685  * Thanks Mihi!		- Jir -
6686  */
6687 void fortune(int Ind, bool broadcast)
6688 {
6689 	char Rumor[MAX_CHARS_WIDE], Broadcast[MAX_CHARS];
6690 
6691 	strcpy(Broadcast, "Suddenly a thought comes to your mind:");
6692 	msg_print(Ind, NULL);
6693 
6694 //	switch(randint(20))
6695 	switch(randint(80))
6696 	{
6697 		case 1:
6698 			get_rnd_line("chainswd.txt",0 , Rumor, MAX_CHARS_WIDE);
6699 			break;
6700 		case 2:
6701 			get_rnd_line("error.txt",0 , Rumor, MAX_CHARS_WIDE);
6702 			break;
6703 		case 3:
6704 		case 4:
6705 		case 5:
6706 			get_rnd_line("death.txt",0 , Rumor, MAX_CHARS_WIDE);
6707 			break;
6708 		default:
6709 			if (magik(95)) get_rnd_line("rumors.txt",0 , Rumor, MAX_CHARS_WIDE);
6710 			else {
6711 				strcpy(Broadcast, "Suddenly an important thought comes to your mind:");
6712 				get_rnd_line("hints.txt",0 , Rumor, MAX_CHARS_WIDE);
6713 			}
6714 	}
6715 	bracer_ff(Rumor);
6716 //	msg_format(Ind, "%s", Rumor);
6717 	msg_print(Ind, Rumor);
6718 	msg_print(Ind, NULL);
6719 
6720 	if (broadcast) {
6721 		msg_broadcast(Ind, Broadcast);
6722 		msg_broadcast(Ind, Rumor);
6723 	}
6724 
6725 }
6726 
6727 char random_colour()
6728 {
6729 //	char tmp[] = "wWrRbBgGdDuUoyvs";
6730 	char tmp[] = "dwsorgbuDWvyRGBU";
6731 
6732 	return(tmp[randint(15)]);	// never 'd'
6733 }
6734 
6735 
6736 /*
6737  * These are out of place -- we should add cmd7.c in the near future.	- Jir -
6738  */
6739 
6740 /*
6741  * Hook to determine if an object is convertible in an arrow/bolt
6742  */
6743 
6744 static int fletchery_items(int Ind) {
6745 	player_type *p_ptr = Players[Ind];
6746 	object_type     *o_ptr;
6747 	int i;
6748 
6749 	for (i = 0; i < INVEN_PACK; i++) {
6750 		o_ptr = &p_ptr->inventory[i];
6751 		if (!o_ptr->k_idx) continue;
6752 		if (!can_use_admin(Ind, o_ptr)) continue;
6753 		/* Broken Stick */
6754 		if (o_ptr->tval == TV_JUNK && o_ptr->sval == 6) return (i);
6755 		if (o_ptr->tval == TV_SKELETON) return (i);
6756 	}
6757 
6758 	/* Failed */
6759 	return (-1);
6760 }
6761 
6762 /* Dirty but useful macro */
6763 #define do_fletchery_aux() \
6764 	object_aware(Ind, q_ptr); \
6765 	object_known(q_ptr); \
6766 	if (tlev > 50) q_ptr->ident |= ID_MENTAL; \
6767 	apply_magic(&p_ptr->wpos, q_ptr, tlev, FALSE, get_skill(p_ptr, SKILL_ARCHERY) >= 20, (magik(tlev / 10))?TRUE:FALSE, FALSE, RESF_NOART); \
6768 	q_ptr->ident &= ~ID_CURSED; \
6769 	q_ptr->note = quark_add("handmade"); \
6770 	/* q_ptr->discount = 50 + 25 * rand_int(3); */ \
6771 	msg_print(Ind, "You make some ammo.")
6772 /*
6773 	apply_magic(&p_ptr->wpos, q_ptr, tlev, TRUE, get_skill(p_ptr, SKILL_ARCHERY) >= 20, (magik(tlev / 10))?TRUE:FALSE, FALSE, make_resf(p_ptr)); \
6774 	apply_magic(&p_ptr->wpos, q_ptr, tlev, TRUE, TRUE, (magik(tlev / 10))?TRUE:FALSE, FALSE, make_resf(p_ptr));
6775 */
6776 
6777 /* finish creating sling ammo dug from rubble */
6778 void create_sling_ammo_aux(int Ind) {
6779 	player_type *p_ptr = Players[Ind];
6780 	int tlev = get_skill_scale(p_ptr, SKILL_ARCHERY, 50) - 20
6781 		+ get_skill_scale(p_ptr, SKILL_SLING, 35);
6782 	object_type forge, *q_ptr;
6783 
6784 	/* S(he) is no longer afk */
6785 	//un_afk_idle(Ind);
6786 	p_ptr->current_create_sling_ammo = FALSE;
6787 
6788 	/* Get local object */
6789 	q_ptr = &forge;
6790 
6791 	/* Hack -- Give the player some bullets */
6792 	invcopy(q_ptr, lookup_kind(TV_SHOT, m_bonus(2, tlev)));
6793 	q_ptr->number = (byte)rand_range(15,30);
6794 	do_fletchery_aux();
6795 
6796 	if (q_ptr->name2 == EGO_ETHEREAL || q_ptr->name2b == EGO_ETHEREAL) q_ptr->number /= ETHEREAL_AMMO_REDUCTION;
6797 
6798 	(void)inven_carry(Ind, q_ptr);
6799 
6800 //	p_ptr->update |= (PU_VIEW | PU_FLOW | PU_MON_LITE);
6801 	p_ptr->update |= (PU_VIEW | PU_FLOW);
6802 	p_ptr->window |= (PW_OVERHEAD);
6803 
6804 	p_ptr->energy -= level_speed(&p_ptr->wpos);
6805 #if 0 /* not happening anyway */
6806 	break_cloaking(Ind, 5);
6807 	break_shadow_running(Ind);
6808 	stop_precision(Ind);
6809 	stop_shooting_till_kill(Ind);
6810 #endif
6811 }
6812 
6813 /*
6814  * do_cmd_cast calls this function if the player's class
6815  * is 'archer'.
6816  */
6817 //void do_cmd_archer(void)
6818 void do_cmd_fletchery(int Ind) {
6819 	player_type *p_ptr = Players[Ind];
6820 	int ext = 0, tlev = 0, raw_materials, raw_amount;
6821 	//char ch;
6822 
6823 	object_type	forge;
6824 	object_type     *q_ptr;
6825 
6826 	//char com[80];
6827 
6828 	cave_type **zcave;
6829 	if (!(zcave = getcave(&p_ptr->wpos))) return;
6830 
6831 
6832 	if (p_ptr->confused) {
6833 		msg_print(Ind, "You are too confused!");
6834 		return;
6835 	}
6836 	if (p_ptr->blind) {
6837 		msg_print(Ind, "You are blind!");
6838 		return;
6839 	}
6840 	if (get_skill(p_ptr, SKILL_ARCHERY) < 10) {
6841 		msg_print(Ind, "You don't know how to create ammo well.");
6842 		return;
6843 	}
6844 
6845 	ext = get_archery_skill(p_ptr);
6846 	if (ext < 1) {
6847 		msg_print(Ind, "Sorry, you have to wield a launcher first.");
6848 		return;
6849 	}
6850 	if (ext == SKILL_BOOMERANG) {
6851 		msg_print(Ind, "You don't need ammo for boomerangs, naturally.");
6852 		return;
6853 	}
6854 
6855 	tlev = get_skill_scale(p_ptr, SKILL_ARCHERY, 50) - 20
6856 		+ get_skill_scale(p_ptr, ext, 35);
6857 
6858 	/* Prepare for object creation */
6859 //	q_ptr = &forge;
6860 
6861 	/**********Create shots*********/
6862 //	if (ext == 1)
6863 	if (ext == SKILL_SLING) {
6864 		int x,y, dir;
6865 		cave_type *c_ptr;
6866 
6867 		if (p_ptr->tim_wraith) { /* Not in WRAITHFORM ^^ */
6868 			msg_print(Ind, "You can't pick up rubble in incorporeal form!");
6869 			return;
6870 		}
6871 
6872 //		if (!get_rep_dir(&dir)) return;
6873 		for (dir = 1; dir <= 9; dir++) {
6874 			y = p_ptr->py + ddy[dir];
6875 			x = p_ptr->px + ddx[dir];
6876 			c_ptr = &zcave[y][x];
6877 			if (c_ptr->feat == FEAT_RUBBLE) {
6878 				/* new: actually tunnel through the rubble in order to create ammo from it - C. Blue */
6879 
6880 				/* need this here since we abuse it to reset current_create_sling_ammo */
6881 				stop_precision(Ind);
6882 
6883 				/* start digging the rubble.. */
6884 				p_ptr->current_create_sling_ammo = TRUE;
6885 				fake_Receive_tunnel(Ind, dir);
6886 				return;
6887 			}
6888 		}
6889 		msg_print(Ind, "You need rubble to create sling shots.");
6890 	}
6891 
6892 	/**********Create arrows*********/
6893 //	else if (ext == 2)
6894 	else if (ext == SKILL_BOW) {
6895 		int item;
6896 #if 0
6897 		cptr q, s;
6898 
6899 		item_tester_hook = item_tester_hook_convertible;
6900 
6901 		/* Get an item */
6902 		q = "Convert which item? ";
6903 		s = "You have no item to convert.";
6904 		if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
6905 #endif	// 0
6906 
6907 		item = fletchery_items(Ind);
6908 
6909 		/* Get the item (in the pack) */
6910 		if (item >= 0) q_ptr = &p_ptr->inventory[item];
6911 		/* Get the item (on the floor) */
6912 		else {
6913 			msg_print(Ind, "You don't have appropriate materials.");
6914 			return;
6915 
6916 //			if (-item >= o_max)
6917 //				return; /* item doesn't exist */
6918 
6919 //			q_ptr = &o_list[0 - item];
6920 		}
6921 
6922 		/* S(he) is no longer afk */
6923 		un_afk_idle(Ind);
6924 
6925 		/* Remember amount of raw materials used for this */
6926 		raw_materials = q_ptr->number;
6927 		/* Prevent large pack overflow which results in much lost ammo */
6928 		if (raw_materials > 10) raw_materials = 10;
6929 
6930 		/* Get local object */
6931 		q_ptr = &forge;
6932 
6933 		/* Hack -- Give the player some arrows */
6934 //		q_ptr->number = (byte)rand_range(15,25);
6935 		invcopy(q_ptr, lookup_kind(TV_ARROW, m_bonus(1, tlev) + 1));
6936 		q_ptr->number = p_ptr->inventory[item].weight / q_ptr->weight + randint(5);
6937 		raw_amount = q_ptr->number * raw_materials;
6938 		do_fletchery_aux();
6939 
6940 		if (item >= 0) {
6941 			inven_item_increase(Ind, item, -raw_materials);//, -1)
6942 			inven_item_describe(Ind, item);
6943 			inven_item_optimize(Ind, item);
6944 		} else {
6945 			floor_item_increase(0 - item, -raw_materials);//, -1)
6946 			floor_item_describe(0 - item);
6947 			floor_item_optimize(0 - item);
6948 		}
6949 
6950 		if (q_ptr->name2 == EGO_ETHEREAL || q_ptr->name2b == EGO_ETHEREAL) raw_amount /= ETHEREAL_AMMO_REDUCTION;
6951 
6952 		while (raw_amount > 99) {
6953 			q_ptr->number = 99;
6954 			raw_amount -= 99;
6955 			(void)inven_carry(Ind, q_ptr);
6956 		}
6957 		if (raw_amount) {
6958 			q_ptr->number = raw_amount;
6959 			(void)inven_carry(Ind, q_ptr);
6960 		}
6961 	}
6962 
6963 	/**********Create bolts*********/
6964 //	else if (ext == 3)
6965 	else if (ext == SKILL_XBOW) {
6966 		int item;
6967 #if 0
6968 		cptr q, s;
6969 
6970 		item_tester_hook = item_tester_hook_convertible;
6971 
6972 		/* Get an item */
6973 		q = "Convert which item? ";
6974 		s = "You have no item to convert.";
6975 		if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
6976 #endif	// 0
6977 
6978 		item = fletchery_items(Ind);
6979 
6980 		/* Get the item (in the pack) */
6981 		if (item >= 0) q_ptr = &p_ptr->inventory[item];
6982 		/* Get the item (on the floor) */
6983 		else {
6984 			msg_print(Ind, "You don't have appropriate materials.");
6985 			return;
6986 
6987 //			if (-item >= o_max)
6988 //				return; /* item doesn't exist */
6989 
6990 //			q_ptr = &o_list[0 - item];
6991 		}
6992 
6993 		/* S(he) is no longer afk */
6994 		un_afk_idle(Ind);
6995 
6996 		/* Remember amount of raw materials used for this */
6997 		raw_materials = q_ptr->number;
6998 		/* Prevent large pack overflow which results in much lost ammo */
6999 		if (raw_materials > 10) raw_materials = 10;
7000 
7001 		/* Get local object */
7002 		q_ptr = &forge;
7003 
7004 		/* Hack -- Give the player some bolts */
7005 		invcopy(q_ptr, lookup_kind(TV_BOLT, m_bonus(1, tlev) + 1));
7006 //		q_ptr->number = (byte)rand_range(15,25);
7007 		q_ptr->number = p_ptr->inventory[item].weight / q_ptr->weight + randint(5);
7008 		raw_amount = q_ptr->number * raw_materials;
7009 		do_fletchery_aux();
7010 
7011 		if (item >= 0) {
7012 			inven_item_increase(Ind, item, -raw_materials);//, -1)
7013 			inven_item_describe(Ind, item);
7014 			inven_item_optimize(Ind, item);
7015 		} else {
7016 			floor_item_increase(0 - item, -raw_materials);//, -1)
7017 			floor_item_describe(0 - item);
7018 			floor_item_optimize(0 - item);
7019 		}
7020 
7021 		if (q_ptr->name2 == EGO_ETHEREAL || q_ptr->name2b == EGO_ETHEREAL) raw_amount /= ETHEREAL_AMMO_REDUCTION;
7022 
7023 		while (raw_amount > 99) {
7024 			q_ptr->number = 99;
7025 			raw_amount -= 99;
7026 			(void)inven_carry(Ind, q_ptr);
7027 		}
7028 		if (raw_amount) {
7029 			q_ptr->number = raw_amount;
7030 			(void)inven_carry(Ind, q_ptr);
7031 		}
7032 	}
7033 
7034 	p_ptr->energy -= level_speed(&p_ptr->wpos);
7035 	break_cloaking(Ind, 5);
7036 	break_shadow_running(Ind);
7037 	stop_precision(Ind);
7038 	stop_shooting_till_kill(Ind);
7039 }
7040 
7041 /*
7042  * Use a combat stance for armed melee combat - C. Blue
7043  * Note: SKILL_STANCE is increased automatically by +1.000 every 5 levels!
7044  * Players start out with 1.000 skill. The skill number is just for show though ;)
7045  */
7046 void do_cmd_stance(int Ind, int stance) {
7047 	int power = 0;
7048 	player_type *p_ptr = Players[Ind];
7049 #ifndef ENABLE_STANCES
7050 	return;
7051 #endif
7052 
7053 	if (!get_skill(p_ptr, SKILL_STANCE)) return;
7054 
7055 	switch(stance) {
7056 	case 0: /* always known, no different power levels here */
7057 		if (!p_ptr->combat_stance) {
7058 			msg_print(Ind, "\377sYou already are in balanced stance!");
7059 			return;
7060 		}
7061 		msg_print(Ind, "\377sYou enter a balanced stance!");
7062 s_printf("SWITCH_STANCE: %s - balance\n", p_ptr->name);
7063 	break;
7064 	case 1:
7065 		switch(p_ptr->pclass) {
7066 		case CLASS_WARRIOR:
7067 			if (p_ptr->max_lev < 5) {
7068 				msg_print(Ind, "\377sYou haven't learned a defensive stance yet.");
7069 				return;
7070 			}
7071 		break;
7072 		case CLASS_MIMIC:
7073 			if (p_ptr->max_lev < 10) {
7074 				msg_print(Ind, "\377sYou haven't learned a defensive stance yet.");
7075 				return;
7076 			}
7077 		break;
7078 		case CLASS_PALADIN:
7079 			if (p_ptr->max_lev < 5) {
7080 				msg_print(Ind, "\377sYou haven't learned a defensive stance yet.");
7081 				return;
7082 			}
7083 		break;
7084 		case CLASS_RANGER:
7085 			if (p_ptr->max_lev < 10) {
7086 				msg_print(Ind, "\377sYou haven't learned a defensive stance yet.");
7087 				return;
7088 			}
7089 		break;
7090 		}
7091 
7092 		if (p_ptr->combat_stance == 1) {
7093 			msg_print(Ind, "\377sYou already are in defensive stance!");
7094 			return;
7095 		}
7096 #ifndef ALLOW_SHIELDLESS_DEFENSIVE_STANCE
7097 		if (!p_ptr->inventory[INVEN_ARM].k_idx ||
7098 		    p_ptr->inventory[INVEN_ARM].tval != TV_SHIELD) { /* not dual-wielding? */
7099 			msg_print(Ind, "\377yYou cannot enter defensive stance without wielding a shield.");
7100 			return;
7101 		}
7102 #else
7103 		if (!p_ptr->inventory[INVEN_WIELD].k_idx && !p_ptr->inventory[INVEN_ARM].k_idx) {
7104 			msg_print(Ind, "\377yYou cannot enter defensive stance without wielding either weapon or shield.");
7105 			return;
7106 		}
7107 #endif
7108 
7109 		switch(p_ptr->pclass) {
7110 		case CLASS_WARRIOR:
7111 			if (p_ptr->max_lev < 15) {
7112 				power = 0;
7113 				msg_print(Ind, "\377sYou enter defensive stance rank I");
7114 			} else if (p_ptr->max_lev < 35) {
7115 				power = 1;
7116 				msg_print(Ind, "\377sYou enter defensive stance rank II");
7117 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7118 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7119 				msg_print(Ind, "\377sYou enter defensive stance rank III");
7120 			} else {
7121 				power = 3; /* royal rank */
7122 				msg_print(Ind, "\377sYou enter Royal Rank defensive stance");
7123 			}
7124 			break;
7125 		case CLASS_MIMIC:
7126 			if (p_ptr->max_lev < 20) {
7127 				power = 0;
7128 				msg_print(Ind, "\377sYou enter defensive stance rank I");
7129 			} else if (p_ptr->max_lev < 40) {
7130 				power = 1;
7131 				msg_print(Ind, "\377sYou enter defensive stance rank II");
7132 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7133 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7134 				msg_print(Ind, "\377sYou enter defensive stance rank III");
7135 			} else {
7136 				power = 3; /* royal rank */
7137 				msg_print(Ind, "\377sYou enter Royal Rank defensive stance");
7138 			}
7139 			break;
7140 		case CLASS_PALADIN:
7141 			if (p_ptr->max_lev < 20) {
7142 				power = 0;
7143 				msg_print(Ind, "\377sYou enter defensive stance rank I");
7144 			} else if (p_ptr->max_lev < 35) {
7145 				power = 1;
7146 				msg_print(Ind, "\377sYou enter defensive stance rank II");
7147 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7148 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7149 				msg_print(Ind, "\377sYou enter defensive stance rank III");
7150 			} else {
7151 				power = 3; /* royal rank */
7152 				msg_print(Ind, "\377sYou enter Royal Rank defensive stance");
7153 			}
7154 			break;
7155 		case CLASS_RANGER:
7156 			if (p_ptr->max_lev < 20) {
7157 				power = 0;
7158 				msg_print(Ind, "\377sYou enter defensive stance rank I");
7159 			} else if (p_ptr->max_lev < 40) {
7160 				power = 1;
7161 				msg_print(Ind, "\377sYou enter defensive stance rank II");
7162 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7163 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7164 				msg_print(Ind, "\377sYou enter defensive stance rank III");
7165 			} else {
7166 				power = 3; /* royal rank */
7167 				msg_print(Ind, "\377sYou enter Royal Rank defensive stance");
7168 			}
7169 			break;
7170 		}
7171 s_printf("SWITCH_STANCE: %s - defensive\n", p_ptr->name);
7172 		break;
7173 
7174 	case 2:
7175 		switch(p_ptr->pclass) {
7176 		case CLASS_WARRIOR:
7177 			if (p_ptr->max_lev < 10) {
7178 				msg_print(Ind, "\377sYou haven't learned an offensive stance yet.");
7179 				return;
7180 			}
7181 			break;
7182 		case CLASS_MIMIC:
7183 			if (p_ptr->max_lev < 15) {
7184 				msg_print(Ind, "\377sYou haven't learned an offensive stance yet.");
7185 				return;
7186 			}
7187 			break;
7188 		case CLASS_PALADIN:
7189 			if (p_ptr->max_lev < 15) {
7190 				msg_print(Ind, "\377sYou haven't learned an offensive stance yet.");
7191 				return;
7192 			}
7193 			break;
7194 		case CLASS_RANGER:
7195 			if (p_ptr->max_lev < 15) {
7196 				msg_print(Ind, "\377sYou haven't learned an offensive stance yet.");
7197 				return;
7198 			}
7199 			break;
7200 		}
7201 
7202 		if (p_ptr->combat_stance == 2) {
7203 			msg_print(Ind, "\377sYou already are in offensive stance!");
7204 			return;
7205 		}
7206 		if (!p_ptr->inventory[INVEN_WIELD].k_idx || p_ptr->inventory[INVEN_ARM].k_idx) {
7207 			msg_print(Ind, "\377yYou need to wield one weapon with both your hands for offensive stances.");
7208 			return;
7209 		}
7210 		if (!(k_info[p_ptr->inventory[INVEN_WIELD].k_idx].flags4 & (TR4_MUST2H | TR4_SHOULD2H | TR4_COULD2H))) {
7211 			msg_print(Ind, "\377yYour weapon is too small to use it in offensive stance effectively.");
7212 			return;
7213 		}
7214 
7215 		switch(p_ptr->pclass) {
7216 		case CLASS_WARRIOR:
7217 			if (p_ptr->max_lev < 20) {
7218 				power = 0;
7219 				msg_print(Ind, "\377sYou enter offensive stance rank I");
7220 			} else if (p_ptr->max_lev < 40) {
7221 				power = 1;
7222 				msg_print(Ind, "\377sYou enter offensive stance rank II");
7223 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7224 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7225 				msg_print(Ind, "\377sYou enter offensive stance rank III");
7226 			} else {
7227 				power = 3; /* royal rank */
7228 				msg_print(Ind, "\377sYou enter Royal Rank offensive stance");
7229 			}
7230 			break;
7231 		case CLASS_MIMIC:
7232 			if (p_ptr->max_lev < 25) {
7233 				power = 0;
7234 				msg_print(Ind, "\377sYou enter offensive stance rank I");
7235 			} else if (p_ptr->max_lev < 40) {
7236 				power = 1;
7237 				msg_print(Ind, "\377sYou enter offensive stance rank II");
7238 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7239 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7240 				msg_print(Ind, "\377sYou enter offensive stance rank III");
7241 			} else {
7242 				power = 3; /* royal rank */
7243 				msg_print(Ind, "\377sYou enter Royal Rank offensive stance");
7244 			}
7245 			break;
7246 		case CLASS_PALADIN:
7247 			if (p_ptr->max_lev < 25) {
7248 				power = 0;
7249 				msg_print(Ind, "\377sYou enter offensive stance rank I");
7250 			} else if (p_ptr->max_lev < 40) {
7251 				power = 1;
7252 				msg_print(Ind, "\377sYou enter offensive stance rank II");
7253 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7254 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7255 				msg_print(Ind, "\377sYou enter offensive stance rank III");
7256 			} else {
7257 				power = 3; /* royal rank */
7258 				msg_print(Ind, "\377sYou enter Royal Rank offensive stance");
7259 			}
7260 			break;
7261 		case CLASS_RANGER:
7262 			if (p_ptr->max_lev < 25) {
7263 				power = 0;
7264 				msg_print(Ind, "\377sYou enter offensive stance rank I");
7265 			} else if (p_ptr->max_lev < 40) {
7266 				power = 1;
7267 				msg_print(Ind, "\377sYou enter offensive stance rank II");
7268 			} else if (!p_ptr->total_winner || p_ptr->max_lev < 45) {
7269 				power = 2; /* up to level 50, and highest rank for non-totalwinners! */
7270 				msg_print(Ind, "\377sYou enter offensive stance rank III");
7271 			} else {
7272 				power = 3; /* royal rank */
7273 				msg_print(Ind, "\377sYou enter Royal Rank offensive stance");
7274 			}
7275 			break;
7276 		}
7277 s_printf("SWITCH_STANCE: %s - offensive\n", p_ptr->name);
7278 		break;
7279 	}
7280 
7281 	p_ptr->energy -= level_speed(&p_ptr->wpos) / 2; /* takes half a turn to switch */
7282 	p_ptr->combat_stance = stance;
7283 	p_ptr->combat_stance_power = power;
7284 	p_ptr->update |= (PU_BONUS);
7285 	p_ptr->redraw |= (PR_PLUSSES | PR_STATE);
7286 //	handle_stuff();
7287 }
7288 
7289 void do_cmd_melee_technique(int Ind, int technique) {
7290 	player_type *p_ptr = Players[Ind];
7291 
7292 	if (p_ptr->ghost) {
7293 		msg_print(Ind, "You cannot use techniques as a ghost.");
7294 		return;
7295 	}
7296 	if (p_ptr->confused) {
7297 		msg_print(Ind, "You cannot use techniques while confused.");
7298 		return;
7299 	}
7300 	if (p_ptr->blind) {
7301 		switch (technique) {
7302 		case 1: case 3: case 9:
7303 		case 10: case 14:
7304 			msg_print(Ind, "You cannot use this technique while blind.");
7305 			return;
7306 		}
7307 	}
7308 /*	it's superfluous, and rogues now get techniques too but don't have stances..
7309 	if (!get_skill(p_ptr, SKILL_STANCE)) return;
7310 */
7311 
7312 	if ((p_ptr->pclass == CLASS_ROGUE || p_ptr->pclass == CLASS_RUNEMASTER) &&
7313 	    p_ptr->rogue_heavyarmor) {
7314 		msg_print(Ind, "You cannot utilize techniques well while wearing too heavy armour.");
7315 		return;
7316 	}
7317 
7318 	disturb(Ind, 1, 0); /* stop resting, searching and running */
7319 
7320 	switch (technique) {
7321 	case 0:	if (!(p_ptr->melee_techniques & MT_SPRINT)) return; /* Sprint */
7322 		if (p_ptr->cst < 7) { msg_print(Ind, "Not enough stamina!"); return; }
7323 		p_ptr->cst -= 7;
7324 		un_afk_idle(Ind);
7325 		set_melee_sprint(Ind, 9 + rand_int(3)); /* number of turns it lasts */
7326 s_printf("TECHNIQUE_MELEE: %s - sprint\n", p_ptr->name);
7327 		p_ptr->warning_technique_melee = 1;
7328 		break;
7329 	case 1:	if (!(p_ptr->melee_techniques & MT_TAUNT)) return; /* Taunt */
7330 		if (p_ptr->cst < 2) { msg_print(Ind, "Not enough stamina!"); return; }
7331 //		if (p_ptr->energy < level_speed(&p_ptr->wpos) / 4) return;
7332 		if (p_ptr->energy <= 0) return;
7333 		p_ptr->cst -= 2;
7334 		p_ptr->energy -= level_speed(&p_ptr->wpos) / 4; /* doing it while fighting no prob */
7335 		un_afk_idle(Ind);
7336 		taunt_monsters(Ind);
7337 s_printf("TECHNIQUE_MELEE: %s - taunt\n", p_ptr->name);
7338 		p_ptr->warning_technique_melee = 1;
7339 		break;
7340 	case 3:	if (!(p_ptr->melee_techniques & MT_DISTRACT)) return; /* Distract */
7341 		if (p_ptr->cst < 1) { msg_print(Ind, "Not enough stamina!"); return; }
7342 		p_ptr->cst -= 1;
7343 		p_ptr->energy -= level_speed(&p_ptr->wpos) / 2; /* just a quick grimace and mimicking ;) */
7344 		un_afk_idle(Ind);
7345 		distract_monsters(Ind);
7346 s_printf("TECHNIQUE_MELEE: %s - distract\n", p_ptr->name);
7347 		p_ptr->warning_technique_melee = 1;
7348 		break;
7349 	case 7:	if (!(p_ptr->melee_techniques & MT_FLASH)) return; /* Flash bomb */
7350 		if (p_ptr->cst < 4) { msg_print(Ind, "Not enough stamina!"); return; }
7351 //		if (p_ptr->energy < level_speed(&p_ptr->wpos)) return;
7352 		if (p_ptr->energy <= 0) return;
7353 		p_ptr->cst -= 4;
7354 		p_ptr->energy -= level_speed(&p_ptr->wpos);
7355 		un_afk_idle(Ind);
7356 		flash_bomb(Ind);
7357 s_printf("TECHNIQUE_MELEE: %s - flash bomb\n", p_ptr->name);
7358 		p_ptr->warning_technique_melee = 1;
7359 		break;
7360 	case 9:	if (!(p_ptr->melee_techniques & MT_SPIN)) return; /* Spin */
7361 		if (p_ptr->cst < 5) { msg_print(Ind, "Not enough stamina!"); return; }
7362 		if (p_ptr->afraid) {
7363 			msg_print(Ind, "You are too afraid to attack!");
7364 			return;
7365 		}
7366 		if (p_ptr->energy < level_speed(&p_ptr->wpos)) return; // ?
7367 		p_ptr->cst -= 5;
7368 		un_afk_idle(Ind);
7369 		spin_attack(Ind);
7370 		p_ptr->energy -= level_speed(&p_ptr->wpos);
7371 s_printf("TECHNIQUE_MELEE: %s - spin\n", p_ptr->name);
7372 		p_ptr->warning_technique_melee = 1;
7373 		break;
7374 #ifdef ENABLE_ASSASSINATE
7375 	case 10:if (!(p_ptr->melee_techniques & MT_ASSA)) return; /* Assassinate */
7376 		if (p_ptr->piercing_charged) {
7377 			msg_print(Ind, "You drop your preparations for assassination.");
7378 			p_ptr->piercing_charged = FALSE;
7379 			p_ptr->piercing = 0;
7380 			return;
7381 		}
7382 		if (p_ptr->cst < 9) { msg_print(Ind, "Not enough stamina!"); return; }
7383 		if (!p_ptr->dual_wield || !p_ptr->dual_mode) {
7384 			msg_print(Ind, "This attack requires two dual-wielded weapons!");
7385 			return;
7386 		}
7387 		msg_print(Ind, "You prepare an armour-piercing attack combination..");
7388 		p_ptr->piercing = 1000; /* [1000] : one round of piercing blows */
7389 		p_ptr->piercing_charged = TRUE; /* Prepared and ready - ST won't regenerate until we use it! */
7390 s_printf("TECHNIQUE_MELEE: %s - assassinate\n", p_ptr->name);
7391 		p_ptr->warning_technique_melee = 1;
7392 		break;
7393 #endif
7394 	case 11:if (!(p_ptr->melee_techniques & MT_BERSERK)) return; /* Berserk */
7395 		if (p_ptr->cst < 10) { msg_print(Ind, "Not enough stamina!"); return; }
7396 		p_ptr->cst -= 10;
7397 		un_afk_idle(Ind);
7398 		hp_player(Ind, 20);
7399 		set_afraid(Ind, 0);
7400 		set_berserk(Ind, randint(5) + 15);
7401 s_printf("TECHNIQUE_MELEE: %s - berserk\n", p_ptr->name);
7402 		p_ptr->warning_technique_melee = 1;
7403 		break;
7404 	case 14:if (!(p_ptr->melee_techniques & MT_SRUN)) return; /* Shadow Run */
7405 		shadow_run(Ind);
7406 s_printf("TECHNIQUE_MELEE: %s - shadow run\n", p_ptr->name);
7407 		p_ptr->warning_technique_melee = 1;
7408 		break;
7409 	default:
7410 		msg_print(Ind, "Invalid technique.");
7411 		s_printf("TECHNIQUE_MELEE: %s used invalid code %d.\n", p_ptr->name, technique);
7412 		return;
7413 	}
7414 
7415 	p_ptr->redraw |= (PR_STAMINA);
7416 	redraw_stuff(Ind);
7417 }
7418 
7419 void do_cmd_ranged_technique(int Ind, int technique) {
7420 	player_type *p_ptr = Players[Ind];
7421 	int i;
7422 
7423 	if (p_ptr->ghost) {
7424 		msg_print(Ind, "You cannot use techniques as a ghost.");
7425 		return;
7426 	}
7427 	if (p_ptr->confused) {
7428 		msg_print(Ind, "You cannot use techniques while confused.");
7429 		return;
7430 	}
7431 	if (p_ptr->blind) {
7432 		msg_print(Ind, "You cannot use ranged techniques while confused.");
7433 		return;
7434 	}
7435 
7436 	if (!get_skill(p_ptr, SKILL_ARCHERY)) return; /* paranoia */
7437 
7438 	if (technique != 3 || !p_ptr->ranged_double) { /* just toggling that one off? */
7439 		if (technique != 2) {
7440 			if (!p_ptr->inventory[INVEN_AMMO].tval) {
7441 				msg_print(Ind, "You have no ammunition equipped.");
7442 				return;
7443 			}
7444 			if (p_ptr->inventory[INVEN_AMMO].sval == SV_AMMO_CHARRED) {
7445 				msg_print(Ind, "Charred ammunition is too brittle to use.");
7446 				return;
7447 			}
7448 		}
7449 		if (p_ptr->inventory[INVEN_BOW].tval == TV_BOOMERANG) {
7450 			msg_print(Ind, "You cannot use techniques with a boomerang.");
7451 			return;
7452 		}
7453 		if (p_ptr->inventory[INVEN_ARM].tval == TV_SHIELD) {
7454 			msg_print(Ind, "You cannot use techniques with a shield equipped.");
7455 			return;
7456 		}
7457 	}
7458 
7459 	disturb(Ind, 1, 0); /* stop things like running, resting.. */
7460 
7461 	switch (technique) {
7462 	case 0:	if (!(p_ptr->ranged_techniques & RT_FLARE)) return; /* Flare missile */
7463 		if (p_ptr->ranged_flare) {
7464 			msg_print(Ind, "You dispose of the flare missile.");
7465 			p_ptr->ranged_flare = FALSE;
7466 			return;
7467 		}
7468 		if (p_ptr->cst < 2) { msg_print(Ind, "Not enough stamina!"); return; }
7469 		if (check_guard_inscription(p_ptr->inventory[INVEN_AMMO].note, 'k')) {
7470 			msg_print(Ind, "Your ammo's inscription (!k) prevents using it as flare missile.");
7471 			return;
7472 		}
7473 #if 0 /* using !k inscription in birth.c instead? */
7474 		/* warn about and prevent using up the only magic ammo we got */
7475 		if (p_ptr->inventory[INVEN_AMMO].name1 == 0 &&
7476 		    p_ptr->inventory[INVEN_AMMO].sval == SV_AMMO_MAGIC &&
7477 		    p_ptr->inventory[INVEN_AMMO].number == 1) {
7478 			msg_print(Ind, "Flare would consume your only magic piece of ammo!");
7479 			return;
7480 		}
7481 #endif
7482 		for (i = 0; i < INVEN_WIELD; i++)
7483 			if (p_ptr->inventory[i].tval == TV_FLASK) { /* oil */
7484 //				p_ptr->cst -= 2;
7485 				p_ptr->ranged_flare = TRUE;
7486 				inven_item_increase(Ind, i, -1);
7487 				inven_item_describe(Ind, i);
7488 				inven_item_optimize(Ind, i);
7489 				break;
7490 			}
7491 		if (!p_ptr->ranged_flare) {
7492 			msg_print(Ind, "You are missing a flask of oil.");
7493 			return;
7494 		}
7495 		p_ptr->ranged_precision = FALSE; p_ptr->ranged_double = FALSE; p_ptr->ranged_barrage = FALSE;
7496 		p_ptr->energy -= level_speed(&p_ptr->wpos); /* prepare the shit.. */
7497 		msg_print(Ind, "You prepare an oil-drenched shot..");
7498 s_printf("TECHNIQUE_RANGED: %s - flare missile\n", p_ptr->name);
7499 		p_ptr->warning_technique_ranged = 1;
7500 		break;
7501 	case 1:	if (!(p_ptr->ranged_techniques & RT_PRECS)) return; /* Precision shot */
7502 		if (p_ptr->ranged_precision) {
7503 			msg_print(Ind, "You stop aiming overly precisely.");
7504 			p_ptr->ranged_precision = FALSE;
7505 			return;
7506 		}
7507 		if (p_ptr->cst < 7) { msg_print(Ind, "Not enough stamina!"); return; }
7508 //		p_ptr->cst -= 7;
7509 		p_ptr->ranged_flare = FALSE; p_ptr->ranged_double = FALSE; p_ptr->ranged_barrage = FALSE;
7510 		p_ptr->ranged_precision = TRUE;
7511 		p_ptr->energy -= level_speed(&p_ptr->wpos); /* focus.. >:) (maybe even 2 turns oO) */
7512 		msg_print(Ind, "You aim carefully for a precise shot..");
7513 s_printf("TECHNIQUE_RANGED: %s - precision\n", p_ptr->name);
7514 		p_ptr->warning_technique_ranged = 1;
7515 		break;
7516 	case 2:	if (!(p_ptr->ranged_techniques & RT_CRAFT)) return; /* Craft some ammunition */
7517 s_printf("TECHNIQUE_RANGED: %s - ammo\n", p_ptr->name);
7518 		p_ptr->warning_technique_ranged = 1;
7519 		do_cmd_fletchery(Ind); /* was previously MKEY_FLETCHERY (9) */
7520 		return;
7521 	case 3:	if (!(p_ptr->ranged_techniques & RT_DOUBLE)) return; /* Double-shot */
7522 		if (!p_ptr->ranged_double) {
7523 //			if (p_ptr->cst < 1) { msg_print(Ind, "Not enough stamina!"); return; }
7524 			if (p_ptr->inventory[INVEN_AMMO].tval && p_ptr->inventory[INVEN_AMMO].number < 2) {
7525 				msg_print(Ind, "You need at least 2 projectiles for a dual-shot!");
7526 				return;
7527 			}
7528 			p_ptr->ranged_double_used = 0;
7529 			p_ptr->ranged_flare = FALSE; p_ptr->ranged_precision = FALSE; p_ptr->ranged_barrage = FALSE;
7530 		}
7531 		p_ptr->ranged_double = !p_ptr->ranged_double; /* toggle */
7532 		if (p_ptr->ranged_double) msg_print(Ind, "You switch to shooting double-shots.");
7533 		else msg_print(Ind, "You stop using double-shots.");
7534 s_printf("TECHNIQUE_RANGED: %s - double\n", p_ptr->name);
7535 		p_ptr->warning_technique_ranged = 1;
7536 		break;
7537 	case 4:	if (!(p_ptr->ranged_techniques & RT_BARRAGE)) return; /* Barrage */
7538 		if (p_ptr->ranged_barrage) {
7539 			msg_print(Ind, "You cancel preparations for barrage.");
7540 			p_ptr->ranged_barrage = FALSE;
7541 			return;
7542 		}
7543 		if (p_ptr->cst < 9) { msg_print(Ind, "Not enough stamina!"); return; }
7544 		if (p_ptr->inventory[INVEN_AMMO].tval && p_ptr->inventory[INVEN_AMMO].number < 6) {
7545 			msg_print(Ind, "You need at least 6 projectiles for a barrage!");
7546 			return;
7547 		}
7548 //		p_ptr->cst -= 9;
7549 		p_ptr->ranged_flare = FALSE; p_ptr->ranged_precision = FALSE; p_ptr->ranged_double = FALSE;
7550 		p_ptr->ranged_barrage = TRUE;
7551 		msg_print(Ind, "You prepare a powerful multi-shot barrage...");
7552 s_printf("TECHNIQUE_RANGED: %s - barrage\n", p_ptr->name);
7553 		p_ptr->warning_technique_ranged = 1;
7554 //in cmd2.c!	p_ptr->energy -= level_speed(&p_ptr->wpos) / 2; /* You _prepare_ it.. */
7555 		break;
7556 	}
7557 }
7558 
7559 void do_cmd_breathe(int Ind) {
7560 	player_type *p_ptr = Players[Ind];
7561 
7562 #ifndef ENABLE_DRACONIAN_TRAITS
7563 	return;
7564 #endif
7565 
7566         p_ptr->current_breath = 1;
7567         get_aim_dir(Ind);
7568 }
7569 void do_cmd_breathe_aux(int Ind, int dir) {
7570 	player_type *p_ptr = Players[Ind];
7571 	int trait;
7572 
7573 #ifndef ENABLE_DRACONIAN_TRAITS
7574 	return;
7575 #endif
7576 	/* feature not available? */
7577 	if (!p_ptr->ptrait) return;
7578 
7579         if (!is_newer_than(&p_ptr->version, 4, 4, 5, 10, 0, 0)) {
7580                 /* Only fire in direction 5 if we have a target */
7581                 if ((dir == 5) && !target_okay(Ind)) {
7582                         /* Reset current breath */
7583                         p_ptr->current_breath = 0;
7584                         return;
7585                 }
7586         }
7587 
7588 	if (p_ptr->prace != RACE_DRACONIAN || !p_ptr->ptrait) {
7589 		msg_print(Ind, "You cannot breathe elements.");
7590 		return;
7591 	}
7592 	if (p_ptr->ghost) {
7593 		msg_print(Ind, "You cannot use your elemental breath as a ghost.");
7594 		return;
7595 	}
7596 	if (p_ptr->confused) {
7597 		msg_print(Ind, "You cannot use your elemental breath while confused.");
7598 		return;
7599 	}
7600 	if (p_ptr->body_monster && !strchr("dDJRM", r_info[p_ptr->body_monster].d_char)) {
7601 		msg_print(Ind, "You cannot use your elemental breath in your current form.");
7602 		return;
7603 	}
7604 	if (p_ptr->lev < 8) {
7605 		msg_print(Ind, "You need to be at least level 8 to breathe elements.");
7606 		return;
7607 	}
7608 	if (p_ptr->cst < 3) { msg_print(Ind, "Not enough stamina!"); return; }
7609 
7610         /* New '+' feat in 4.4.6.2 */
7611         if (dir == 11) {
7612                 get_aim_dir(Ind);
7613                 p_ptr->current_breath = 1;
7614                 return;
7615         }
7616 
7617         break_cloaking(Ind, 0);
7618         break_shadow_running(Ind);
7619         stop_precision(Ind);
7620         stop_shooting_till_kill(Ind);
7621         un_afk_idle(Ind);
7622 	disturb(Ind, 1, 0); /* stop things like running, resting.. */
7623 
7624 	p_ptr->cst -= 3;
7625 	p_ptr->redraw |= PR_STAMINA;
7626         p_ptr->current_breath = 0;
7627 	p_ptr->energy -= level_speed(&p_ptr->wpos);
7628 
7629 	trait = p_ptr->ptrait;
7630 	if (trait == TRAIT_MULTI) /* Draconic Multi-hued */
7631 		trait = rand_int(5) + TRAIT_BLUE;
7632 	if (trait == TRAIT_POWER) {
7633 		trait = rand_int(10) + TRAIT_BLUE;
7634 		if (trait >= TRAIT_MULTI) trait++;
7635 	}
7636 
7637 	switch (trait) {
7638         case TRAIT_BLUE: /* Draconic Blue */
7639 	        sprintf(p_ptr->attacker, " breathes lightning for");
7640 	        msg_print(Ind, "You breathe lightning.");
7641 	        fire_ball(Ind, GF_ELEC, dir, ((p_ptr->chp / 3) > 500) ? 500 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7642                 break;
7643         case TRAIT_WHITE: /* Draconic White */
7644 	        sprintf(p_ptr->attacker, " breathes frost for");
7645 	        msg_print(Ind, "You breathe frost.");
7646 	        fire_ball(Ind, GF_COLD, dir, ((p_ptr->chp / 3) > 500) ? 500 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7647                 break;
7648         case TRAIT_RED: /* Draconic Red */
7649 	        sprintf(p_ptr->attacker, " breathes fire for");
7650 	        msg_print(Ind, "You breathe fire.");
7651 	        fire_ball(Ind, GF_FIRE, dir, ((p_ptr->chp / 3) > 500) ? 500 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7652                 break;
7653         case TRAIT_BLACK: /* Draconic Black */
7654 	        sprintf(p_ptr->attacker, " breathes acid for");
7655 	        msg_print(Ind, "You breathe acid.");
7656 	        fire_ball(Ind, GF_ACID, dir, ((p_ptr->chp / 3) > 500) ? 500 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7657                 break;
7658         case TRAIT_GREEN: /* Draconic Green */
7659 	        sprintf(p_ptr->attacker, " breathes poison for");
7660 	        msg_print(Ind, "You breathe poison.");
7661 	        fire_ball(Ind, GF_POIS, dir, ((p_ptr->chp / 3) > 450) ? 450 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7662                 break;
7663         case TRAIT_BRONZE: /* Draconic Bronze */
7664 	        sprintf(p_ptr->attacker, " breathes confusion for");
7665 	        msg_print(Ind, "You breathe confusion.");
7666 	        fire_ball(Ind, GF_CONFUSION, dir, ((p_ptr->chp / 3) > 350) ? 350 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7667                 break;
7668         case TRAIT_SILVER: /* Draconic Silver */
7669 	        sprintf(p_ptr->attacker, " breathes inertia for");
7670 	        msg_print(Ind, "You breathe inertia.");
7671 	        fire_ball(Ind, GF_INERTIA, dir, ((p_ptr->chp / 3) > 500) ? 500 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7672                 break;
7673         case TRAIT_GOLD: /* Draconic Gold */
7674 	        sprintf(p_ptr->attacker, " breathes sound for");
7675 	        msg_print(Ind, "You breathe sound.");
7676 	        fire_ball(Ind, GF_SOUND, dir, ((p_ptr->chp / 3) > 350) ? 350 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7677                 break;
7678         case TRAIT_LAW: /* Draconic Law */
7679 	        sprintf(p_ptr->attacker, " breathes shards for");
7680 	        msg_print(Ind, "You breathe shards.");
7681 	        fire_ball(Ind, GF_SHARDS, dir, ((p_ptr->chp / 3) > 350) ? 350 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7682                 break;
7683         case TRAIT_CHAOS: /* Draconic Chaos */
7684 	        sprintf(p_ptr->attacker, " breathes chaos for");
7685 	        msg_print(Ind, "You breathe chaos.");
7686 	        fire_ball(Ind, GF_CHAOS, dir, ((p_ptr->chp / 3) > 450) ? 450 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7687                 break;
7688         case TRAIT_BALANCE: /* Draconic Balance */
7689 	        sprintf(p_ptr->attacker, " breathes disenchantment for");
7690 	        msg_print(Ind, "You breathe disenchantment.");
7691 	        fire_ball(Ind, GF_DISENCHANT, dir, ((p_ptr->chp / 3) > 400) ? 400 : (p_ptr->chp / 3), 2, p_ptr->attacker);
7692                 break;
7693         default: /* paranoia */
7694 		msg_print(Ind, "\377yYou fail to breathe elements.");
7695 		p_ptr->cst += 3; /* reimburse */
7696         }
7697 }
7698