ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_effect.C
Revision: 1.143
Committed: Mon Nov 12 03:48:34 2012 UTC (11 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.142: +5 -2 lines
Log Message:
respect mapspace limits in create food/missile

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.77 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.142 *
4 root 1.140 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.119 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 root 1.142 *
8 root 1.110 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 root 1.142 *
13 root 1.62 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 root 1.142 *
18 root 1.110 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.142 *
22 root 1.77 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.35 */
24 elmex 1.1
25     #include <global.h>
26     #include <object.h>
27     #include <living.h>
28 root 1.36 #include <sproto.h>
29 elmex 1.1 #include <spells.h>
30     #include <sounds.h>
31    
32     /* cast_magic_storm: This is really used mostly for spell
33     * fumbles at the like. tmp is the object to propogate.
34     * op is what is casting this.
35     */
36 root 1.8 void
37     cast_magic_storm (object *op, object *tmp, int lvl)
38 elmex 1.1 {
39 root 1.8 if (!tmp)
40     return; /* error */
41 root 1.27
42 root 1.8 tmp->level = op->level;
43     tmp->range += lvl / 5; /* increase the area of destruction */
44     tmp->duration += lvl / 5;
45    
46     /* Put a cap on duration for this - if the player fails in their
47     * apartment, don't want it to go on so long that it kills them
48     * multiple times. Also, damge already increases with level,
49     * so don't really need to increase the duration as much either.
50     */
51     if (tmp->duration >= 40)
52     tmp->duration = 40;
53 root 1.27
54 root 1.8 tmp->stats.dam = lvl; /* nasty recoils! */
55     tmp->stats.maxhp = tmp->count; /* tract single parent */
56 elmex 1.1
57 root 1.27 tmp->insert_at (op, op);
58 elmex 1.1 }
59    
60 root 1.8 int
61     recharge (object *op, object *caster, object *spell_ob)
62     {
63     int ncharges;
64    
65 root 1.128 object *wand = op->mark ();
66    
67 root 1.84 if (!wand || wand->type != WAND)
68 root 1.8 {
69 root 1.125 op->failmsg ("You need to mark the wand you want to recharge.");
70 root 1.8 return 0;
71 elmex 1.1 }
72 root 1.125
73 root 1.8 if (!(random_roll (0, 3, op, PREFER_HIGH)))
74     {
75 root 1.125 op->failmsgf ("The %s vibrates violently, then explodes!", query_name (wand));
76 root 1.64 op->play_sound (sound_find ("ob_explode"));
77 root 1.91 wand->destroy ();
78 root 1.138 object *tmp = archetype::get (shstr_fireball);
79 root 1.8 tmp->stats.dam = (spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob)) / 10;
80 root 1.27
81 root 1.8 if (!tmp->stats.dam)
82     tmp->stats.dam = 1;
83 root 1.27
84 root 1.8 tmp->stats.hp = tmp->stats.dam / 2;
85 root 1.27
86 root 1.8 if (tmp->stats.hp < 2)
87     tmp->stats.hp = 2;
88 root 1.27
89     tmp->insert_at (op);
90 root 1.8 return 1;
91     }
92    
93     ncharges = (spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob));
94 root 1.27
95 root 1.8 if (wand->inv && wand->inv->level)
96     ncharges /= wand->inv->level;
97     else
98     {
99 root 1.125 op->failmsgf ("Your %s is broken.", query_name (wand));
100 root 1.8 return 0;
101 elmex 1.1 }
102 root 1.27
103 root 1.8 if (!ncharges)
104     ncharges = 1;
105 elmex 1.1
106 root 1.8 wand->stats.food += ncharges;
107     new_draw_info_format (NDI_UNIQUE, 0, op, "The %s glows with power.", query_name (wand));
108 root 1.27
109 root 1.124 if (wand->arch && wand->arch->flag [FLAG_ANIMATE])
110 root 1.8 {
111 root 1.124 wand->set_flag (FLAG_ANIMATE);
112 root 1.57 wand->set_speed (wand->arch->speed);
113 elmex 1.1 }
114 root 1.26
115 root 1.8 return 1;
116 elmex 1.1 }
117    
118     /* Create a missile (nonmagic - magic +4). Will either create bolts or arrows
119     * based on whether a crossbow or bow is equiped. If neither, it defaults to
120     * arrows.
121     * Sets the plus based on the casters level. It is also settable with the
122     * invoke command. If the caster attempts to create missiles with too
123     * great a plus, the default is used.
124     * The # of arrows created also goes up with level, so if a 30th level mage
125     * wants LOTS of arrows, and doesn't care what the plus is he could
126     * create nonnmagic arrows, or even -1, etc...
127     */
128 root 1.8 int
129 root 1.104 cast_create_missile (object *op, object *caster, object *spell, int dir, const char *spellparam)
130 elmex 1.1 {
131 root 1.74 int bonus_plus = 0;
132     const char *missile_name = "arrow";
133 root 1.8
134 root 1.74 for (object *tmp = op->inv; tmp; tmp = tmp->below)
135 root 1.124 if (tmp->type == BOW && tmp->flag [FLAG_APPLIED])
136 root 1.12 missile_name = tmp->race;
137 elmex 1.1
138 root 1.74 int missile_plus = spell->stats.dam + SP_level_dam_adjust (caster, spell);
139    
140     archetype *missile_arch = archetype::find (missile_name);
141 elmex 1.1
142 root 1.74 if (!missile_arch)
143 root 1.8 {
144     LOG (llevDebug, "Cast create_missile: could not find archetype %s\n", missile_name);
145     return 0;
146     }
147 root 1.12
148 root 1.74 object *missile = missile_arch->instance ();
149 elmex 1.1
150 root 1.104 if (spellparam)
151 root 1.8 {
152     /* If it starts with a letter, presume it is a description */
153 root 1.104 if (isalpha (*spellparam))
154 root 1.8 {
155     artifact *al = find_artifactlist (missile->type)->items;
156 elmex 1.1
157 root 1.45 for (; al; al = al->next)
158 root 1.104 if (!strcasecmp (al->item->name, spellparam))
159 root 1.8 break;
160    
161     if (!al)
162     {
163 root 1.91 missile->destroy ();
164 root 1.125 op->failmsgf ("No such object %ss of %s", missile_name, spellparam);
165 root 1.8 return 0;
166     }
167 root 1.12
168 root 1.8 if (al->item->slaying)
169     {
170 root 1.91 missile->destroy ();
171 root 1.125 op->failmsgf ("You are not allowed to create %ss of %s", missile_name, spellparam);
172 root 1.8 return 0;
173     }
174 root 1.12
175 root 1.8 give_artifact_abilities (missile, al->item);
176 root 1.74 /* These special arrows cost something extra. Don't have them also be magical -
177     * otherwise, in most cases, not enough will be created. I don't want to get into
178 root 1.8 * the parsing of having to do both plus and type.
179     */
180     bonus_plus = 1 + (al->item->value / 5);
181     missile_plus = 0;
182     }
183 root 1.104 else if (atoi (spellparam) < missile_plus)
184     missile_plus = atoi (spellparam);
185 root 1.8 }
186 root 1.12
187 root 1.74 missile_plus = clamp (missile_plus, -4, 4);
188 root 1.8
189     missile->nrof = spell->duration + SP_level_duration_adjust (caster, spell);
190     missile->nrof -= 3 * (missile_plus + bonus_plus);
191 root 1.12
192 root 1.8 if (missile->nrof < 1)
193     missile->nrof = 1;
194    
195     missile->magic = missile_plus;
196     /* Can't get any money for these objects */
197     missile->value = 0;
198 elmex 1.1
199 root 1.124 missile->set_flag (FLAG_IDENTIFIED);
200 elmex 1.1
201 root 1.143 cast_create_obj (op, caster, missile, dir);
202    
203     if (!dir
204     && op->type == PLAYER
205     && !missile->destroyed ())
206 root 1.12 pick_up (op, missile);
207    
208 root 1.8 return 1;
209 elmex 1.1 }
210    
211     /* allows the choice of what sort of food object to make.
212 root 1.104 * If spellparam is NULL, it will create food dependent on level --PeterM*/
213 root 1.8 int
214 root 1.104 cast_create_food (object *op, object *caster, object *spell_ob, int dir, const char *spellparam)
215 elmex 1.1 {
216 root 1.8 int food_value;
217     archetype *at = NULL;
218     object *new_op;
219    
220 root 1.76 food_value = spell_ob->stats.food + 50 * SP_level_duration_adjust (caster, spell_ob);
221 root 1.8
222 root 1.104 if (spellparam)
223 root 1.8 {
224 root 1.104 at = find_archetype_by_object_type_name (FOOD, spellparam);
225 root 1.8 if (at == NULL)
226 root 1.104 at = find_archetype_by_object_type_name (DRINK, spellparam);
227 root 1.57 if (at == NULL || at->stats.food > food_value)
228 root 1.104 spellparam = NULL;
229 root 1.8 }
230    
231 root 1.104 if (!spellparam)
232 root 1.8 {
233     archetype *at_tmp;
234    
235     /* We try to find the archetype with the maximum food value.
236     * This removes the dependancy of hard coded food values in this
237     * function, and addition of new food types is automatically added.
238     * We don't use flesh types because the weight values of those need
239     * to be altered from the donor.
240     */
241 root 1.5
242 root 1.8 /* We assume the food items don't have multiple parts */
243 elmex 1.58 for_all_archetypes (at_tmp)
244 root 1.8 {
245 root 1.57 if (at_tmp->type == FOOD || at_tmp->type == DRINK)
246 root 1.8 {
247     /* Basically, if the food value is something that is creatable
248     * under the limits of the spell and it is higher than
249     * the item we have now, take it instead.
250     */
251 elmex 1.59 if (at_tmp->stats.food <= food_value
252     && (!at
253     || at_tmp->stats.food > at->stats.food
254     || (at_tmp->stats.food == at->stats.food
255     && at_tmp->weight < at->weight)))
256 root 1.8 at = at_tmp;
257 root 1.5 }
258     }
259 elmex 1.1 }
260 root 1.65
261 root 1.8 /* Pretty unlikely (there are some very low food items), but you never
262     * know
263     */
264     if (!at)
265     {
266 root 1.125 op->failmsgf ("You don't have enough experience to create any food.");
267 root 1.8 return 0;
268 elmex 1.1 }
269    
270 root 1.57 food_value /= at->stats.food;
271 root 1.116 new_op = at->instance ();
272 root 1.8 new_op->nrof = food_value;
273 elmex 1.1
274 root 1.8 new_op->value = 0;
275     if (new_op->nrof < 1)
276     new_op->nrof = 1;
277 elmex 1.1
278 root 1.8 cast_create_obj (op, caster, new_op, dir);
279     return 1;
280 elmex 1.1 }
281 root 1.8
282     int
283     probe (object *op, object *caster, object *spell_ob, int dir)
284     {
285     int r, mflags, maxrange;
286     object *tmp;
287 root 1.13 maptile *m;
288 elmex 1.1
289 root 1.8 if (!dir)
290     {
291     examine_monster (op, op);
292     return 1;
293 elmex 1.1 }
294 root 1.65
295 root 1.8 maxrange = spell_ob->range + SP_level_range_adjust (caster, spell_ob);
296     for (r = 1; r < maxrange; r++)
297     {
298     sint16 x = op->x + r * freearr_x[dir], y = op->y + r * freearr_y[dir];
299 elmex 1.1
300 root 1.8 m = op->map;
301     mflags = get_map_flags (m, &m, x, y, &x, &y);
302 elmex 1.1
303 root 1.8 if (mflags & P_OUT_OF_MAP)
304     break;
305 elmex 1.1
306 root 1.124 if (!op->flag [FLAG_WIZCAST] && (mflags & P_NO_MAGIC))
307 root 1.8 {
308     new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your magic.");
309     return 0;
310 root 1.5 }
311 root 1.84
312 root 1.8 if (mflags & P_IS_ALIVE)
313     {
314 root 1.84 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
315 root 1.124 if (tmp->flag [FLAG_ALIVE] && (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER]))
316 root 1.8 {
317     new_draw_info (NDI_UNIQUE, 0, op, "You detect something.");
318     if (tmp->head != NULL)
319     tmp = tmp->head;
320     examine_monster (op, tmp);
321     return 1;
322     }
323 root 1.5 }
324 elmex 1.1 }
325 root 1.65
326 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "You detect nothing.");
327     return 1;
328 elmex 1.1 }
329    
330     /* This checks to see if 'pl' is invisible to 'mon'.
331     * does race check, undead check, etc
332     * Returns TRUE if mon can't see pl, false
333     * otherwise. This doesn't check range, walls, etc. It
334     * only checks the racial adjustments, and in fact that
335     * pl is invisible.
336     */
337 root 1.8 int
338     makes_invisible_to (object *pl, object *mon)
339 elmex 1.1 {
340 root 1.8 if (!pl->invisible)
341     return 0;
342 root 1.68
343 root 1.8 if (pl->type == PLAYER)
344     {
345     /* If race isn't set, then invisible unless it is undead */
346     if (!pl->contr->invis_race)
347     {
348 root 1.124 if (mon->flag [FLAG_UNDEAD])
349 root 1.8 return 0;
350 root 1.68
351 root 1.8 return 1;
352     }
353 root 1.68
354 root 1.8 /* invis_race is set if we get here */
355 root 1.95 if (pl->contr->invis_race == shstr_undead && is_true_undead (mon))
356 root 1.8 return 1;
357 root 1.68
358 root 1.8 /* No race, can't be invisible to it */
359     if (!mon->race)
360 root 1.5 return 0;
361 root 1.68
362 root 1.94 if (mon->race.contains (pl->contr->invis_race))
363 root 1.5 return 1;
364 root 1.68
365 root 1.8 /* Nothing matched above, return 0 */
366     return 0;
367     }
368     else
369     {
370     /* monsters are invisible to everything */
371     return 1;
372 elmex 1.1 }
373     }
374    
375     /* Makes the player or character invisible.
376     * Note the spells to 'stack', but perhaps in odd ways.
377     * the duration for all is cumulative.
378     * In terms of invis undead/normal invis, it is the last one cast that
379     * will determine if you are invisible to undead or normal monsters.
380     * For improved invis, if you cast it with a one of the others, you
381     * lose the improved part of it, and the above statement about undead/
382     * normal applies.
383     */
384 root 1.8 int
385     cast_invisible (object *op, object *caster, object *spell_ob)
386     {
387     if (op->invisible > 1000)
388     {
389 root 1.125 op->failmsg ("You can not extend the duration of your invisibility any further");
390 root 1.8 return 0;
391 elmex 1.1 }
392    
393 root 1.8 /* Remove the switch with 90% duplicate code - just handle the differences with
394     * and if statement or two.
395     */
396     op->invisible += spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
397 root 1.139
398     /* limit duration */
399     min_it (op->invisible, 1000);
400 root 1.8
401     if (op->type == PLAYER)
402     {
403     op->contr->invis_race = spell_ob->race;
404    
405 root 1.124 if (spell_ob->flag [FLAG_MAKE_INVIS])
406 root 1.8 op->contr->tmp_invis = 0;
407     else
408     op->contr->tmp_invis = 1;
409    
410     op->contr->hidden = 0;
411     }
412 root 1.42
413 root 1.8 if (makes_invisible_to (op, op))
414     new_draw_info (NDI_UNIQUE, 0, op, "You can't see your hands!");
415     else
416     new_draw_info (NDI_UNIQUE, 0, op, "You feel more transparent!");
417    
418 root 1.42 update_object (op, UP_OBJ_CHANGE);
419 root 1.8
420     /* Only search the active objects - only these should actually do
421     * harm to the player.
422     */
423 root 1.33 for_all_actives (tmp)
424 root 1.8 if (tmp->enemy == op)
425 root 1.33 tmp->enemy = 0;
426    
427 root 1.8 return 1;
428 elmex 1.1 }
429    
430     /* earth to dust spell. Basically destroys earthwalls in the area.
431     */
432 root 1.8 int
433     cast_earth_to_dust (object *op, object *caster, object *spell_ob)
434     {
435     int range, i, j, mflags;
436     sint16 sx, sy;
437 root 1.13 maptile *m;
438 elmex 1.1
439 root 1.8 range = spell_ob->range + SP_level_range_adjust (caster, spell_ob);
440 elmex 1.1
441 root 1.8 for (i = -range; i <= range; i++)
442     for (j = -range; j <= range; j++)
443     {
444     sx = op->x + i;
445     sy = op->y + j;
446     m = op->map;
447     mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
448 elmex 1.1
449 root 1.8 if (mflags & P_OUT_OF_MAP)
450     continue;
451 elmex 1.1
452 root 1.102 // earth to dust tears down everything that can be torn down
453     for (object *next, *tmp = m->at (sx, sy).bot; tmp; tmp = next)
454 root 1.8 {
455     next = tmp->above;
456 root 1.102
457 root 1.124 if (tmp->flag [FLAG_TEAR_DOWN])
458 root 1.8 hit_player (tmp, 9998, op, AT_PHYSICAL, 0);
459     }
460     }
461 root 1.31
462 root 1.8 return 1;
463 elmex 1.1 }
464    
465 root 1.8 void
466     execute_word_of_recall (object *op)
467     {
468 root 1.31 if (object *pl = op->in_player ())
469 root 1.131 if (pl->ms ().flags () & P_NO_CLERIC && !pl->flag [FLAG_WIZCAST])
470     new_draw_info (NDI_UNIQUE, 0, pl, "You feel something fizzle inside you.");
471     else
472     pl->player_goto (op->slaying, op->stats.hp, op->stats.sp);
473 root 1.14
474 root 1.91 op->destroy ();
475 elmex 1.1 }
476    
477     /* Word of recall causes the player to return 'home'.
478     * we put a force into the player object, so that there is a
479     * time delay effect.
480     */
481 root 1.8 int
482     cast_word_of_recall (object *op, object *caster, object *spell_ob)
483     {
484 root 1.131 if (!op->is_player ())
485 root 1.8 return 0;
486 elmex 1.1
487 root 1.8 if (find_obj_by_type_subtype (op, SPELL_EFFECT, SP_WORD_OF_RECALL))
488 elmex 1.1 {
489 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you.");
490     return 1;
491 elmex 1.1 }
492    
493 root 1.138 object *dummy = archetype::get (FORCE_NAME);
494 root 1.84
495 root 1.131 int time = max (1, spell_ob->duration - SP_level_duration_adjust (caster, spell_ob));
496 root 1.8
497     /* value of speed really doesn't make much difference, as long as it is
498     * positive. Lower value may be useful so that the problem doesn't
499     * do anything really odd if it say a -1000 or something.
500     */
501 root 1.26 dummy->set_speed (0.002);
502 root 1.8 dummy->speed_left = -dummy->speed * time;
503 root 1.131 dummy->type = SPELL_EFFECT;
504     dummy->subtype = SP_WORD_OF_RECALL;
505     dummy->slaying = op->contr->savebed_map;
506     dummy->stats.hp = op->contr->bed_x;
507     dummy->stats.sp = op->contr->bed_y;
508 root 1.8
509 root 1.31 op->insert (dummy);
510    
511 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you.");
512 root 1.31
513 root 1.8 return 1;
514 elmex 1.1 }
515    
516     /* cast_wonder
517     * wonder is really just a spell that will likely cast another
518     * spell.
519     */
520 root 1.8 int
521     cast_wonder (object *op, object *caster, int dir, object *spell_ob)
522     {
523     object *newspell;
524 elmex 1.1
525 root 1.8 if (!rndm (0, 3))
526     return cast_cone (op, caster, dir, spell_ob);
527 elmex 1.1
528 root 1.8 if (spell_ob->randomitems)
529     {
530     newspell = generate_treasure (spell_ob->randomitems, caster->level);
531     if (!newspell)
532     {
533     LOG (llevError, "cast_wonder: Unable to get a spell!\n");
534     return 0;
535 root 1.5 }
536 root 1.8 if (newspell->type != SPELL)
537     {
538     LOG (llevError, "cast_wonder: spell returned is not a spell (%d, %s)!\n", &newspell->type, &newspell->name);
539     return 0;
540 root 1.5 }
541 root 1.8 /* Prevent inifinit recursion */
542     if (newspell->subtype == SP_WONDER)
543     {
544     LOG (llevError, "cast_wonder: spell returned is another wonder spell!\n");
545     return 0;
546 root 1.5 }
547 root 1.8 return cast_spell (op, caster, dir, newspell, NULL);
548 elmex 1.1 }
549 root 1.8 return 1;
550 elmex 1.1 }
551    
552 root 1.8 int
553     perceive_self (object *op)
554     {
555 root 1.43 const char *cp = describe_item (op, op);
556 root 1.113 archetype *at = archetype::find (shstr_depletion);
557 root 1.8
558 root 1.100 dynbuf_text &buf = msg_dynbuf; buf.clear ();
559 root 1.60
560 root 1.100 if (!op->is_player ())
561     return 0;
562    
563     if (object *race = archetype::find (op->race))
564     buf << " - You are a G<male|female> " << &race->name << ".\n";
565 root 1.60
566     if (object *god = find_god (determine_god (op)))
567 root 1.87 buf << " - You worship " << &god->name << ".\n";
568 root 1.8 else
569 root 1.87 buf << " - You worship no god.\n";
570 root 1.8
571 root 1.60 object *tmp = present_arch_in_ob (at, op);
572 root 1.8
573 root 1.87 if (*cp == '\0' && !tmp)
574     buf << " - You feel very mundane. ";
575 root 1.8 else
576     {
577 root 1.87 buf << " - You have: " << cp << ".\n";
578 root 1.51
579     if (tmp)
580 root 1.60 for (int i = 0; i < NUM_STATS; i++)
581 root 1.51 if (tmp->stats.stat (i) < 0)
582 root 1.87 buf.printf (" - Your %s is depleted by %d.\n", statname[i], -tmp->stats.stat (i));
583 elmex 1.1 }
584    
585 root 1.117 if (op->is_dragon ())
586 root 1.60 /* now grab the 'dragon_ability'-force from the player's inventory */
587     for (tmp = op->inv; tmp; tmp = tmp->below)
588     {
589 root 1.69 if (tmp->type == FORCE && tmp->arch->archname == shstr_dragon_ability_force)
590 root 1.60 {
591     if (tmp->stats.exp == 0)
592 root 1.87 buf << " - Your metabolism isn't focused on anything.\n";
593 root 1.60 else
594 root 1.87 buf << " - Your metabolism is focused on " << change_resist_msg[tmp->stats.exp] << ".\n";
595 root 1.60
596     break;
597     }
598     }
599 root 1.36
600 root 1.100 op->contr->infobox (MSG_CHANNEL ("perceiveself"), buf);
601 root 1.36
602 root 1.8 return 1;
603 elmex 1.1 }
604    
605     /* This creates magic walls. Really, it can create most any object,
606     * within some reason.
607     */
608 root 1.8 int
609     magic_wall (object *op, object *caster, int dir, object *spell_ob)
610     {
611 root 1.27 object *tmp;
612 root 1.8 int i, posblocked, negblocked, maxrange;
613     sint16 x, y;
614 root 1.13 maptile *m;
615 root 1.8 const char *name;
616     archetype *at;
617    
618     if (!dir)
619     {
620     dir = op->facing;
621     x = op->x;
622     y = op->y;
623     }
624     else
625     {
626     x = op->x + freearr_x[dir];
627     y = op->y + freearr_y[dir];
628     }
629 root 1.25
630 root 1.8 m = op->map;
631    
632     if ((spell_ob->move_block || x != op->x || y != op->y) &&
633     (get_map_flags (m, &m, x, y, &x, &y) & (P_OUT_OF_MAP | P_IS_ALIVE) ||
634     ((spell_ob->move_block & GET_MAP_MOVE_BLOCK (m, x, y)) == spell_ob->move_block)))
635     {
636 root 1.125 op->failmsg ("Something is in the way.");
637 root 1.8 return 0;
638     }
639 root 1.25
640 root 1.8 if (spell_ob->other_arch)
641 root 1.116 tmp = spell_ob->other_arch->instance ();
642 root 1.8 else if (spell_ob->race)
643     {
644     char buf1[MAX_BUF];
645    
646     sprintf (buf1, spell_ob->race, dir);
647 root 1.10 at = archetype::find (buf1);
648 root 1.8 if (!at)
649     {
650     LOG (llevError, "summon_wall: Unable to find archetype %s\n", buf1);
651     new_draw_info (NDI_UNIQUE, 0, op, "This spell is broken.");
652     return 0;
653 root 1.5 }
654 root 1.27
655 root 1.116 tmp = at->instance ();
656 root 1.8 }
657     else
658     {
659     LOG (llevError, "magic_wall: spell %s lacks other_arch\n", &spell_ob->name);
660     return 0;
661     }
662    
663     if (tmp->type == SPELL_EFFECT)
664     {
665     tmp->attacktype = spell_ob->attacktype;
666     tmp->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
667     tmp->stats.dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob);
668     tmp->range = 0;
669     }
670 root 1.124 else if (tmp->flag [FLAG_ALIVE])
671 root 1.8 {
672     tmp->stats.hp = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
673     tmp->stats.maxhp = tmp->stats.hp;
674     }
675 root 1.25
676 root 1.124 if (spell_ob->flag [FLAG_IS_USED_UP] || tmp->flag [FLAG_IS_USED_UP])
677 root 1.8 {
678     tmp->stats.food = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
679 root 1.124 tmp->set_flag (FLAG_IS_USED_UP);
680 elmex 1.1 }
681 root 1.25
682 root 1.124 if (spell_ob->flag [FLAG_TEAR_DOWN])
683 root 1.8 {
684     tmp->stats.hp = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob);
685     tmp->stats.maxhp = tmp->stats.hp;
686 root 1.124 tmp->set_flag (FLAG_TEAR_DOWN);
687     tmp->set_flag (FLAG_ALIVE);
688 root 1.8 }
689    
690     /* This can't really hurt - if the object doesn't kill anything,
691 root 1.25 * these fields just won't be used. Do not set the owner for
692     * earthwalls, though, so they survive restarts.
693 root 1.8 */
694 root 1.25 if (tmp->type != EARTHWALL) //TODO
695     tmp->set_owner (op);
696    
697 root 1.8 set_spell_skill (op, caster, spell_ob, tmp);
698 root 1.89 tmp->level = casting_level (caster, spell_ob) / 2;
699 elmex 1.1
700 root 1.8 name = tmp->name;
701 root 1.27 if (!(tmp = m->insert (tmp, x, y, op)))
702 root 1.8 {
703     new_draw_info_format (NDI_UNIQUE, 0, op, "Something destroys your %s", name);
704     return 0;
705 elmex 1.1 }
706 root 1.25
707 root 1.8 /* If this is a spellcasting wall, need to insert the spell object */
708 root 1.57 if (tmp->other_arch && tmp->other_arch->type == SPELL)
709 root 1.116 insert_ob_in_ob (tmp->other_arch->instance (), tmp);
710 root 1.8
711     /* This code causes the wall to extend some distance in
712     * each direction, or until an obstruction is encountered.
713     * posblocked and negblocked help determine how far the
714     * created wall can extend, it won't go extend through
715     * blocked spaces.
716     */
717     maxrange = spell_ob->range + SP_level_range_adjust (caster, spell_ob);
718     posblocked = 0;
719     negblocked = 0;
720    
721     for (i = 1; i <= maxrange; i++)
722     {
723     int dir2;
724    
725     dir2 = (dir < 4) ? (dir + 2) : dir - 2;
726    
727     x = tmp->x + i * freearr_x[dir2];
728     y = tmp->y + i * freearr_y[dir2];
729     m = tmp->map;
730    
731     if (!(get_map_flags (m, &m, x, y, &x, &y) & (P_OUT_OF_MAP | P_IS_ALIVE)) &&
732     ((spell_ob->move_block & GET_MAP_MOVE_BLOCK (m, x, y)) != spell_ob->move_block) && !posblocked)
733     {
734 root 1.27 object *tmp2 = tmp->clone ();
735     m->insert (tmp2, x, y, op);
736    
737 root 1.8 /* If this is a spellcasting wall, need to insert the spell object */
738 root 1.57 if (tmp2->other_arch && tmp2->other_arch->type == SPELL)
739 root 1.116 tmp2->insert (tmp2->other_arch->instance ());
740 root 1.8
741     }
742     else
743     posblocked = 1;
744    
745     x = tmp->x - i * freearr_x[dir2];
746     y = tmp->y - i * freearr_y[dir2];
747     m = tmp->map;
748    
749     if (!(get_map_flags (m, &m, x, y, &x, &y) & (P_OUT_OF_MAP | P_IS_ALIVE)) &&
750     ((spell_ob->move_block & GET_MAP_MOVE_BLOCK (m, x, y)) != spell_ob->move_block) && !negblocked)
751     {
752 root 1.27 object *tmp2 = tmp->clone ();
753     m->insert (tmp2, x, y, op);
754    
755 root 1.57 if (tmp2->other_arch && tmp2->other_arch->type == SPELL)
756 root 1.116 tmp2->insert (tmp2->other_arch->instance ());
757 root 1.8 }
758     else
759     negblocked = 1;
760 elmex 1.1 }
761    
762 root 1.124 if (tmp->flag [FLAG_BLOCKSVIEW])
763 root 1.8 update_all_los (op->map, op->x, op->y);
764 elmex 1.1
765 root 1.8 return 1;
766 elmex 1.1 }
767    
768 root 1.8 int
769 root 1.104 dimension_door (object *op, object *caster, object *spob, int dir, const char *spellparam)
770 root 1.8 {
771     uint32 dist, maxdist;
772     int mflags;
773 root 1.13 maptile *m;
774 root 1.8 sint16 sx, sy;
775 elmex 1.1
776 root 1.8 if (op->type != PLAYER)
777     return 0;
778 elmex 1.1
779 root 1.8 if (!dir)
780     {
781 root 1.123 op->failmsg ("In what direction?");
782 root 1.8 return 0;
783 elmex 1.1 }
784    
785 root 1.8 /* Given the new outdoor maps, can't let players dimension door for
786     * ever, so put limits in.
787     */
788     maxdist = spob->range + SP_level_range_adjust (caster, spob);
789    
790 root 1.104 if (spellparam)
791 root 1.8 {
792 root 1.104 int count = atoi (spellparam);
793    
794     if (count > maxdist)
795 root 1.8 {
796 root 1.125 op->failmsg ("You can't dimension door that far!");
797 root 1.8 return 0;
798 root 1.5 }
799    
800 root 1.104 for (dist = 0; dist < count; dist++)
801 root 1.8 {
802     mflags = get_map_flags (op->map, &m, op->x + freearr_x[dir] * (dist + 1), op->y + freearr_y[dir] * (dist + 1), &sx, &sy);
803 root 1.5
804 root 1.8 if (mflags & (P_NO_MAGIC | P_OUT_OF_MAP))
805     break;
806 root 1.5
807 root 1.8 if ((mflags & P_BLOCKSVIEW) && OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
808     break;
809 root 1.5 }
810    
811 root 1.104 if (dist < count)
812 root 1.8 {
813     new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the spell.\n");
814     return 0;
815     }
816 root 1.27
817 root 1.8 /* Remove code that puts player on random space on maps. IMO,
818     * a lot of maps probably have areas the player should not get to,
819     * but may not be marked as NO_MAGIC (as they may be bounded
820     * by such squares). Also, there are probably treasure rooms and
821     * lots of other maps that protect areas with no magic, but the
822     * areas themselves don't contain no magic spaces.
823     */
824     /* This call here is really just to normalize the coordinates */
825     mflags = get_map_flags (op->map, &m, op->x + freearr_x[dir] * dist, op->y + freearr_y[dir] * dist, &sx, &sy);
826     if (mflags & P_IS_ALIVE || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
827     {
828     new_draw_info (NDI_UNIQUE, 0, op, "You cast your spell, but nothing happens.\n");
829     return 1; /* Maybe the penalty should be more severe... */
830 root 1.5 }
831 root 1.8 }
832     else
833     {
834     /* Player didn't specify a distance, so lets see how far
835     * we can move the player. Don't know why this stopped on
836     * spaces that blocked the players view.
837     */
838 root 1.5
839 root 1.8 for (dist = 0; dist < maxdist; dist++)
840     {
841     mflags = get_map_flags (op->map, &m, op->x + freearr_x[dir] * (dist + 1), op->y + freearr_y[dir] * (dist + 1), &sx, &sy);
842 root 1.5
843 root 1.8 if (mflags & (P_NO_MAGIC | P_OUT_OF_MAP))
844     break;
845 root 1.5
846 root 1.8 if ((mflags & P_BLOCKSVIEW) && OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
847     break;
848 root 1.5
849     }
850    
851 root 1.8 /* If the destination is blocked, keep backing up until we
852     * find a place for the player.
853     */
854     for (; dist > 0; dist--)
855     {
856     if (get_map_flags (op->map, &m, op->x + freearr_x[dir] * dist, op->y + freearr_y[dir] * dist,
857     &sx, &sy) & (P_OUT_OF_MAP | P_IS_ALIVE))
858     continue;
859 root 1.5
860    
861 root 1.8 if (!OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
862     break;
863 root 1.5
864     }
865 root 1.8 if (!dist)
866     {
867 root 1.125 op->failmsg ("Your spell failed!\n");
868 root 1.8 return 0;
869 root 1.5 }
870 elmex 1.1 }
871    
872 root 1.8 /* Actually move the player now */
873 root 1.27 if (!(op = op->map->insert (op, op->x + freearr_x[dir] * dist, op->y + freearr_y[dir] * dist, op)))
874 root 1.8 return 1;
875 elmex 1.1
876 root 1.115 op->speed_left = -5. * op->speed; /* Freeze them for a short while */
877 root 1.112
878 root 1.8 return 1;
879 elmex 1.1 }
880    
881     /* cast_heal: Heals something.
882     * op is the caster.
883     * dir is the direction he is casting it in.
884     * spell is the spell object.
885     */
886 root 1.8 int
887     cast_heal (object *op, object *caster, object *spell, int dir)
888     {
889     object *tmp;
890     archetype *at;
891     object *poison;
892     int heal = 0, success = 0;
893    
894     tmp = find_target_for_friendly_spell (op, dir);
895    
896 root 1.40 if (!tmp)
897 root 1.8 return 0;
898    
899     /* Figure out how many hp this spell might cure.
900     * could be zero if this spell heals effects, not damage.
901     */
902     heal = spell->stats.dam;
903     if (spell->stats.hp)
904     heal += random_roll (spell->stats.hp, 6, op, PREFER_HIGH) + spell->stats.hp;
905    
906     if (heal)
907     {
908     if (tmp->stats.hp >= tmp->stats.maxhp)
909 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "You are already fully healed.");
910 root 1.8 else
911     {
912     /* See how many points we actually heal. Instead of messages
913     * based on type of spell, we instead do messages based
914     * on amount of damage healed.
915     */
916 root 1.70 if (heal > tmp->stats.maxhp - tmp->stats.hp)
917 root 1.8 heal = tmp->stats.maxhp - tmp->stats.hp;
918 root 1.70
919 root 1.8 tmp->stats.hp += heal;
920    
921     if (tmp->stats.hp >= tmp->stats.maxhp)
922 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel just fine!");
923 root 1.8 else if (heal > 50)
924 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds close!");
925 root 1.8 else if (heal > 25)
926 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds mostly close.");
927 root 1.8 else if (heal > 10)
928 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to fade.");
929 root 1.8 else
930 root 1.40 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to close.");
931    
932 root 1.8 success = 1;
933     }
934     }
935 root 1.40
936 root 1.8 if (spell->attacktype & AT_DISEASE)
937 root 1.70 if (cure_disease (tmp, op, spell))
938 root 1.8 success = 1;
939    
940     if (spell->attacktype & AT_POISON)
941     {
942 root 1.113 at = archetype::find (shstr_poisoning);
943 root 1.8 poison = present_arch_in_ob (at, tmp);
944     if (poison)
945     {
946     success = 1;
947     new_draw_info (NDI_UNIQUE, 0, tmp, "Your body feels cleansed");
948     poison->stats.food = 1;
949 root 1.5 }
950 elmex 1.1 }
951 root 1.40
952 root 1.8 if (spell->attacktype & AT_CONFUSION)
953     {
954 root 1.113 poison = present_in_ob_by_name (FORCE, shstr_confusion, tmp);
955 root 1.8 if (poison)
956     {
957     success = 1;
958     new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
959     poison->duration = 1;
960 root 1.5 }
961 elmex 1.1 }
962 root 1.40
963 root 1.8 if (spell->attacktype & AT_BLIND)
964     {
965 root 1.113 at = archetype::find (shstr_blindness);
966 root 1.8 poison = present_arch_in_ob (at, tmp);
967     if (poison)
968     {
969     success = 1;
970     new_draw_info (NDI_UNIQUE, 0, tmp, "Your vision begins to return.");
971     poison->stats.food = 1;
972 root 1.5 }
973 elmex 1.1 }
974 root 1.40
975 root 1.8 if (spell->last_sp && tmp->stats.sp < tmp->stats.maxsp)
976     {
977     tmp->stats.sp += spell->last_sp;
978     if (tmp->stats.sp > tmp->stats.maxsp)
979     tmp->stats.sp = tmp->stats.maxsp;
980     success = 1;
981     new_draw_info (NDI_UNIQUE, 0, tmp, "Magical energy surges through your body!");
982     }
983 root 1.40
984 root 1.8 if (spell->last_grace && tmp->stats.grace < tmp->stats.maxgrace)
985     {
986     tmp->stats.grace += spell->last_grace;
987     if (tmp->stats.grace > tmp->stats.maxgrace)
988     tmp->stats.grace = tmp->stats.maxgrace;
989     success = 1;
990     new_draw_info (NDI_UNIQUE, 0, tmp, "You feel redeemed with your god!");
991 elmex 1.1 }
992 root 1.40
993 root 1.122 if (spell->stats.food && tmp->stats.food < MAX_FOOD)
994 root 1.8 {
995     tmp->stats.food += spell->stats.food;
996 root 1.122 min_it (tmp->stats.food, MAX_FOOD);
997 root 1.70
998 root 1.8 success = 1;
999     /* We could do something a bit better like the messages for healing above */
1000     new_draw_info (NDI_UNIQUE, 0, tmp, "You feel your belly fill with food");
1001     }
1002 root 1.40
1003 root 1.8 return success;
1004 elmex 1.1 }
1005    
1006     /* This is used for the spells that gain stats. There are no spells
1007     * right now that icnrease wis/int/pow on a temp basis, so no
1008     * good comments for those.
1009     */
1010 root 1.8 static const char *const no_gain_msgs[NUM_STATS] = {
1011     "You grow no stronger.",
1012     "You grow no more agile.",
1013     "You don't feel any healthier.",
1014 root 1.55 "You didn't grow any more intelligent.",
1015     "You do not feel any wiser.",
1016     "You don't feel any more powerful."
1017 root 1.8 "You are no easier to look at.",
1018 elmex 1.1 };
1019    
1020 root 1.8 int
1021 root 1.105 change_ability_duration (object *spell, object *caster)
1022     {
1023     return spell->duration + SP_level_duration_adjust (caster, spell) * 50;
1024     }
1025    
1026     int
1027 root 1.8 cast_change_ability (object *op, object *caster, object *spell_ob, int dir, int silent)
1028     {
1029 root 1.88 object *force = 0;
1030 root 1.8 int i;
1031    
1032     /* if dir = 99 op defaults to tmp, eat_special_food() requires this. */
1033 root 1.27 object *tmp = dir
1034 root 1.88 ? find_target_for_friendly_spell (op, dir)
1035     : op;
1036 root 1.8
1037 root 1.27 if (!tmp)
1038 root 1.8 return 0;
1039    
1040     /* If we've already got a force of this type, don't add a new one. */
1041 root 1.27 for (object *tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1042 root 1.8 {
1043     if (tmp2->type == FORCE && tmp2->subtype == FORCE_CHANGE_ABILITY)
1044     {
1045     if (tmp2->name == spell_ob->name)
1046     {
1047     force = tmp2; /* the old effect will be "refreshed" */
1048     break;
1049 root 1.5 }
1050 root 1.8 else if (spell_ob->race && spell_ob->race == tmp2->name)
1051     {
1052     if (!silent)
1053 root 1.125 op->failmsgf ("You can not cast %s while %s is in effect",
1054     &spell_ob->name, &tmp2->name_pl);
1055 root 1.88
1056 root 1.8 return 0;
1057 root 1.5 }
1058     }
1059 elmex 1.1 }
1060 root 1.88
1061 root 1.108 int duration = change_ability_duration (spell_ob, caster);
1062 root 1.88
1063 root 1.108 if (force)
1064 root 1.8 {
1065     if (duration > force->duration)
1066     {
1067     force->duration = duration;
1068     new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect.");
1069     }
1070     else
1071 root 1.88 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect.");
1072 root 1.55
1073 root 1.8 return 1;
1074     }
1075 root 1.55
1076 root 1.108 new_draw_info_format (NDI_UNIQUE, 0, op,
1077     "You create an aura of magical force. H<The effect will last for about %.10g seconds.>",
1078     TICK2TIME (duration));
1079    
1080 root 1.138 force = archetype::get (FORCE_NAME);
1081 root 1.108 force->subtype = FORCE_CHANGE_ABILITY;
1082     force->duration = duration;
1083    
1084     if (spell_ob->race)
1085     force->name = spell_ob->race;
1086     else
1087     force->name = spell_ob->name;
1088    
1089     force->name_pl = spell_ob->name;
1090    
1091 root 1.8 force->speed = 1.0;
1092     force->speed_left = -1.0;
1093 root 1.124 force->set_flag (FLAG_APPLIED);
1094 root 1.8
1095     /* Now start processing the effects. First, protections */
1096     for (i = 0; i < NROFATTACKS; i++)
1097 root 1.133 if (spell_ob->resist[i])
1098     force->resist[i] = min (100, spell_ob->resist[i] + SP_level_dam_adjust (caster, spell_ob));
1099 root 1.55
1100 root 1.8 if (spell_ob->stats.hp)
1101     force->stats.hp = spell_ob->stats.hp + SP_level_dam_adjust (caster, spell_ob);
1102    
1103     if (tmp->type == PLAYER)
1104     {
1105     /* Stat adjustment spells */
1106     for (i = 0; i < NUM_STATS; i++)
1107     {
1108 root 1.51 if (sint8 stat = spell_ob->stats.stat (i))
1109 root 1.8 {
1110 root 1.51 sint8 sm = 0;
1111     for (sint8 k = 0; k < stat; k++)
1112 root 1.8 sm += rndm (1, 3);
1113    
1114 root 1.51 if (tmp->stats.stat (i) + sm > 15 + 5 * stat)
1115     sm = max (0, (15 + 5 * stat) - tmp->stats.stat (i));
1116    
1117     force->stats.stat (i) = sm;
1118    
1119 root 1.8 if (!sm)
1120     new_draw_info (NDI_UNIQUE, 0, op, no_gain_msgs[i]);
1121 root 1.5 }
1122     }
1123 elmex 1.1 }
1124    
1125 root 1.8 force->move_type = spell_ob->move_type;
1126 elmex 1.1
1127 root 1.124 if (spell_ob->flag [FLAG_SEE_IN_DARK])
1128     force->set_flag (FLAG_SEE_IN_DARK);
1129 elmex 1.1
1130 root 1.124 if (spell_ob->flag [FLAG_XRAYS])
1131     force->set_flag (FLAG_XRAYS);
1132 elmex 1.1
1133 root 1.8 /* Haste/bonus speed */
1134     if (spell_ob->stats.exp)
1135     {
1136     if (op->speed > 0.5f)
1137     force->stats.exp = (sint64) ((float) spell_ob->stats.exp / (op->speed + 0.5f));
1138     else
1139     force->stats.exp = spell_ob->stats.exp;
1140 elmex 1.1 }
1141    
1142 root 1.8 force->stats.wc = spell_ob->stats.wc;
1143     force->stats.ac = spell_ob->stats.ac;
1144     force->attacktype = spell_ob->attacktype;
1145    
1146     insert_ob_in_ob (force, tmp);
1147     change_abil (tmp, force); /* Mostly to display any messages */
1148 root 1.24 tmp->update_stats ();
1149 root 1.55
1150 root 1.8 return 1;
1151 elmex 1.1 }
1152    
1153     /* This used to be part of cast_change_ability, but it really didn't make
1154     * a lot of sense, since most of the values it derives are from the god
1155     * of the caster.
1156     */
1157 root 1.8 int
1158     cast_bless (object *op, object *caster, object *spell_ob, int dir)
1159     {
1160     int i;
1161 root 1.85 object *god = find_god (determine_god (op)), *force = NULL, *tmp;
1162 root 1.8
1163     /* if dir = 99 op defaults to tmp, eat_special_food() requires this. */
1164     if (dir != 0)
1165     {
1166     tmp = find_target_for_friendly_spell (op, dir);
1167 root 1.85
1168     if (!tmp)
1169     return 0;
1170 root 1.8 }
1171     else
1172 root 1.85 tmp = op;
1173 root 1.8
1174     /* If we've already got a force of this type, don't add a new one. */
1175 root 1.85 for (object *tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1176 root 1.8 {
1177     if (tmp2->type == FORCE && tmp2->subtype == FORCE_CHANGE_ABILITY)
1178     {
1179     if (tmp2->name == spell_ob->name)
1180     {
1181     force = tmp2; /* the old effect will be "refreshed" */
1182     break;
1183 root 1.5 }
1184 root 1.8 else if (spell_ob->race && spell_ob->race == tmp2->name)
1185     {
1186     new_draw_info_format (NDI_UNIQUE, 0, op, "You can not cast %s while %s is in effect", &spell_ob->name, &tmp2->name_pl);
1187     return 0;
1188 root 1.5 }
1189     }
1190 elmex 1.1 }
1191 root 1.85
1192 root 1.8 if (force == NULL)
1193     {
1194 root 1.138 force = archetype::get (FORCE_NAME);
1195 root 1.8 force->subtype = FORCE_CHANGE_ABILITY;
1196     if (spell_ob->race)
1197     force->name = spell_ob->race;
1198     else
1199     force->name = spell_ob->name;
1200     force->name_pl = spell_ob->name;
1201     new_draw_info (NDI_UNIQUE, 0, op, "You create an aura of magical force.");
1202     }
1203     else
1204     {
1205     int duration;
1206    
1207     duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1208     if (duration > force->duration)
1209     {
1210     force->duration = duration;
1211     new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect.");
1212 root 1.5 }
1213 root 1.8 else
1214     {
1215     new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect.");
1216     }
1217     return 0;
1218 elmex 1.1 }
1219 root 1.133
1220 root 1.8 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1221     force->speed = 1.0;
1222     force->speed_left = -1.0;
1223 root 1.124 force->set_flag (FLAG_APPLIED);
1224 elmex 1.1
1225 root 1.8 if (!god)
1226     {
1227     new_draw_info (NDI_UNIQUE, 0, op, "Your blessing seems empty.");
1228     }
1229     else
1230     {
1231     /* Only give out good benefits, and put a max on it */
1232     for (i = 0; i < NROFATTACKS; i++)
1233 root 1.113 if (god->resist[i] > 0)
1234     force->resist[i] = min (god->resist[i], spell_ob->resist[ATNR_GODPOWER]);
1235    
1236 root 1.8 force->path_attuned |= god->path_attuned;
1237 root 1.7
1238 root 1.8 if (spell_ob->attacktype)
1239     force->slaying = god->slaying;
1240 root 1.7
1241 root 1.8 if (tmp != op)
1242     {
1243     new_draw_info_format (NDI_UNIQUE, 0, op, "You bless %s.", &tmp->name);
1244     new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s blessed you.", &op->name);
1245     }
1246     else
1247     {
1248     new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are blessed by %s!", &god->name);
1249 root 1.5 }
1250 elmex 1.1
1251     }
1252 root 1.8 force->stats.wc = spell_ob->stats.wc;
1253     force->stats.ac = spell_ob->stats.ac;
1254 elmex 1.1
1255 root 1.8 change_abil (tmp, force); /* Mostly to display any messages */
1256     insert_ob_in_ob (force, tmp);
1257 root 1.24 tmp->update_stats ();
1258 root 1.8 return 1;
1259 elmex 1.1 }
1260    
1261     /* Alchemy code by Mark Wedel
1262     *
1263     * This code adds a new spell, called alchemy. Alchemy will turn
1264 root 1.66 * objects to pyrite ("false gold"), henceforth called gold nuggets.
1265 root 1.142 *
1266 root 1.66 * The value of the gold nuggets being about 90% of that of the item
1267     * itself. It uses the value of the object before charisma adjustments,
1268     * because the nuggets themselves will be will be adjusted by charisma
1269     * when sold.
1270 elmex 1.1 *
1271     * There is also a chance (1:30) that you will get nothing at all
1272     * for the object. There is also a maximum weight that will be
1273 root 1.37 * alchemised.
1274 elmex 1.1 */
1275 root 1.8 static void
1276 root 1.38 alchemy_object (object *obj, uint64 &total_value, int &total_weight)
1277 root 1.8 {
1278     uint64 value = query_cost (obj, NULL, F_TRUE);
1279    
1280 root 1.75 /* Give third price when we alchemy money (this should hopefully
1281 root 1.8 * make it so that it isn't worth it to alchemy money, sell
1282     * the nuggets, alchemy the gold from that, etc.
1283     * Otherwise, give 9 silver on the gold for other objects,
1284     * so that it would still be more affordable to haul
1285     * the stuff back to town.
1286     */
1287 root 1.124 if (obj->flag [FLAG_UNPAID])
1288 root 1.8 value = 0;
1289     else if (obj->type == MONEY || obj->type == GEM)
1290     value /= 3;
1291     else
1292 root 1.39 value = value * 9 / 10;
1293 root 1.8
1294 root 1.37 if (obj->value > 0 && rndm (0, 29))
1295 root 1.38 total_value += value;
1296 root 1.8
1297 root 1.38 total_weight += obj->total_weight ();
1298 root 1.8
1299 root 1.91 obj->destroy ();
1300 root 1.8 }
1301    
1302     int
1303     alchemy (object *op, object *caster, object *spell_ob)
1304 elmex 1.1 {
1305 root 1.8 if (op->type != PLAYER)
1306     return 0;
1307    
1308 root 1.66 archetype *nugget[3];
1309    
1310 root 1.113 nugget[0] = archetype::find (shstr_pyrite3);
1311     nugget[1] = archetype::find (shstr_pyrite2);
1312     nugget[2] = archetype::find (shstr_pyrite);
1313 root 1.39
1314 root 1.38 /* Put a maximum weight of items that can be alchemised. Limits the power
1315     * some, and also prevents people from alchemising every table/chair/clock
1316 root 1.8 * in sight
1317     */
1318 root 1.38 int duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
1319     int weight_max = duration * 1000;
1320     uint64 value_max = duration * 1000;
1321 elmex 1.1
1322 root 1.39 int weight = 0;
1323 root 1.38
1324     for (int y = op->y - 1; y <= op->y + 1; y++)
1325 root 1.8 {
1326 root 1.38 for (int x = op->x - 1; x <= op->x + 1; x++)
1327 root 1.8 {
1328 root 1.38 uint64 value = 0;
1329    
1330     sint16 nx = x;
1331     sint16 ny = y;
1332 elmex 1.1
1333 root 1.39 maptile *mp = op->map;
1334 root 1.5
1335 root 1.39 int mflags = get_map_flags (mp, &mp, nx, ny, &nx, &ny);
1336 root 1.5
1337 root 1.8 if (mflags & (P_OUT_OF_MAP | P_NO_MAGIC))
1338     continue;
1339    
1340     /* Treat alchemy a little differently - most spell effects
1341     * use fly as the movement type - for alchemy, consider it
1342     * ground level effect.
1343     */
1344     if (GET_MAP_MOVE_BLOCK (mp, nx, ny) & MOVE_WALK)
1345     continue;
1346    
1347 root 1.38 for (object *next, *tmp = mp->at (nx, ny).bot; tmp; tmp = next)
1348 root 1.8 {
1349     next = tmp->above;
1350 root 1.37
1351 root 1.124 if (tmp->weight > 0 && !tmp->flag [FLAG_NO_PICK] &&
1352     !tmp->flag [FLAG_ALIVE] && !tmp->flag [FLAG_IS_CAULDRON])
1353 root 1.8 {
1354     if (tmp->inv)
1355     {
1356     object *next1, *tmp1;
1357    
1358 root 1.37 for (tmp1 = tmp->inv; tmp1; tmp1 = next1)
1359 root 1.8 {
1360     next1 = tmp1->below;
1361 root 1.124 if (tmp1->weight > 0 && !tmp1->flag [FLAG_NO_PICK] &&
1362     !tmp1->flag [FLAG_ALIVE] && !tmp1->flag [FLAG_IS_CAULDRON])
1363 root 1.38 alchemy_object (tmp1, value, weight);
1364 root 1.5 }
1365     }
1366 root 1.37
1367 root 1.38 alchemy_object (tmp, value, weight);
1368 root 1.8
1369     if (weight > weight_max)
1370 root 1.38 break;
1371     }
1372     }
1373    
1374 root 1.66 value -= rndm (value >> 4);
1375 root 1.38 value = min (value, value_max);
1376    
1377 root 1.132 for (int i = 0; i < array_length (nugget); ++i)
1378 root 1.66 if (int nrof = value / nugget [i]->value)
1379     {
1380     value -= nrof * nugget[i]->value;
1381    
1382 root 1.116 object *tmp = nugget[i]->instance ();
1383 root 1.66 tmp->nrof = nrof;
1384     tmp->flag [FLAG_IDENTIFIED] = true;
1385 root 1.67 op->map->insert (tmp, x, y, op, 0);
1386 root 1.66 }
1387 root 1.38
1388     if (weight > weight_max)
1389     goto bailout;
1390 root 1.8 }
1391     }
1392 root 1.17
1393 root 1.38 bailout:
1394 root 1.8 return 1;
1395 elmex 1.1 }
1396    
1397     /* This function removes the cursed/damned status on equipped
1398     * items.
1399     */
1400 root 1.8 int
1401     remove_curse (object *op, object *caster, object *spell)
1402     {
1403     int success = 0, was_one = 0;
1404    
1405 root 1.134 int num_uncurse = max (1, spell->stats.dam + SP_level_dam_adjust (caster, spell));
1406    
1407     op->splay_marked ();
1408    
1409 root 1.136 int typeflag = spell->last_sp ? FLAG_DAMNED : FLAG_CURSED;
1410    
1411 root 1.134 for (object *tmp = op->inv; tmp && num_uncurse; tmp = tmp->below)
1412 root 1.136 if (!tmp->invisible && tmp->flag [typeflag])
1413 root 1.8 {
1414 root 1.134 ++was_one;
1415 root 1.80
1416 root 1.89 if (tmp->level <= casting_level (caster, spell))
1417 root 1.8 {
1418 root 1.134 ++success;
1419     --num_uncurse;
1420    
1421 root 1.136 tmp->clr_flag (typeflag);
1422 root 1.124 tmp->clr_flag (FLAG_CURSED);
1423     tmp->clr_flag (FLAG_KNOWN_CURSED);
1424 root 1.8 tmp->value = 0; /* Still can't sell it */
1425 root 1.80
1426     if (object *pl = tmp->visible_to ())
1427     esrv_update_item (UPD_FLAGS, pl, tmp);
1428 root 1.8 }
1429     }
1430    
1431     if (op->type == PLAYER)
1432     {
1433     if (success)
1434 root 1.134 new_draw_info (NDI_UNIQUE, 0, op, "You realise that some of your items look shinier now. H<You successfully removed some curses.>");
1435 root 1.8 else
1436     {
1437     if (was_one)
1438 root 1.134 new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove any curse. H<The spell was not strong enough.>");
1439 root 1.8 else
1440 root 1.135 new_draw_info (NDI_UNIQUE, 0, op, "You are not having any cursed items. H<Epic fail.>");
1441 root 1.5 }
1442 elmex 1.1 }
1443 root 1.21
1444 root 1.8 return success;
1445 elmex 1.1 }
1446    
1447     /* Identifies objects in the players inventory/on the ground */
1448 root 1.8 int
1449     cast_identify (object *op, object *caster, object *spell)
1450     {
1451 root 1.100 dynbuf_text &buf = msg_dynbuf; buf.clear ();
1452 root 1.8
1453 root 1.101 int num_ident = max (1, spell->stats.dam + SP_level_dam_adjust (caster, spell));
1454 root 1.8
1455 root 1.134 op->splay_marked ();
1456    
1457     for (object *tmp = op->inv; tmp; tmp = tmp->below)
1458 root 1.8 {
1459 root 1.129 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ())
1460 root 1.8 {
1461     identify (tmp);
1462 root 1.21
1463 root 1.8 if (op->type == PLAYER)
1464     {
1465 root 1.87 buf.printf ("You identified: %s.\r", long_desc (tmp, op));
1466 root 1.21
1467 root 1.8 if (tmp->msg)
1468 root 1.87 buf << "The item has a story:\r" << tmp->msg << "\n\n";
1469 root 1.5 }
1470 root 1.21
1471 root 1.101 if (!--num_ident)
1472 root 1.8 break;
1473 root 1.5 }
1474 elmex 1.1 }
1475 root 1.21
1476 root 1.8 /* If all the power of the spell has been used up, don't go and identify
1477     * stuff on the floor. Only identify stuff on the floor if the spell
1478     * was not fully used.
1479     */
1480     if (num_ident)
1481     {
1482 root 1.134 for (object *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
1483 root 1.129 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ())
1484 root 1.8 {
1485 root 1.21 identify (tmp);
1486 root 1.8
1487 root 1.80 if (object *pl = tmp->visible_to ())
1488 root 1.8 {
1489 root 1.87 buf.printf ("On the ground you identified: %s.\r", long_desc (tmp, op));
1490 root 1.21
1491 root 1.8 if (tmp->msg)
1492 root 1.87 buf << "The item has a story:\r" << tmp->msg << "\n\n";
1493 root 1.8 }
1494 root 1.21
1495 root 1.101 if (!--num_ident)
1496 root 1.8 break;
1497     }
1498     }
1499 root 1.21
1500 root 1.73 if (buf.empty ())
1501     {
1502     op->failmsg ("You can't reach anything unidentified.");
1503     return 0;
1504     }
1505 root 1.8 else
1506 root 1.73 {
1507     if (op->contr)
1508     op->contr->infobox (MSG_CHANNEL ("identify"), buf);
1509 root 1.21
1510 root 1.73 spell_effect (spell, op->x, op->y, op->map, op);
1511     return 1;
1512     }
1513 elmex 1.1 }
1514    
1515 root 1.8 int
1516     cast_detection (object *op, object *caster, object *spell, object *skill)
1517     {
1518     object *tmp, *last, *god, *detect;
1519 root 1.141 int done_one, range, floor, level;
1520 root 1.8 sint16 x, y, nx, ny;
1521 root 1.13 maptile *m;
1522 root 1.8
1523     /* We precompute some values here so that we don't have to keep
1524     * doing it over and over again.
1525     */
1526     god = find_god (determine_god (op));
1527 root 1.89 level = casting_level (caster, spell);
1528 root 1.8 range = spell->range + SP_level_range_adjust (caster, spell);
1529    
1530     if (!skill)
1531     skill = caster;
1532    
1533 root 1.118 dynbuf buf;
1534     unordered_mapwalk (buf, op, -range, -range, range, range)
1535 root 1.98 {
1536     /* For most of the detections, we only detect objects above the
1537     * floor. But this is not true for show invisible.
1538     * Basically, we just go and find the top object and work
1539     * down - that is easier than working up.
1540     */
1541    
1542 root 1.126 for (last = 0, tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above)
1543 root 1.98 last = tmp;
1544    
1545     /* Shouldn't happen, but if there are no objects on a space, this
1546     * would happen.
1547     */
1548     if (!last)
1549     continue;
1550    
1551     done_one = 0;
1552     floor = 0;
1553 root 1.126 detect = 0;
1554 root 1.98 for (tmp = last; tmp; tmp = tmp->below)
1555     {
1556     /* show invisible */
1557 root 1.124 if (spell->flag [FLAG_MAKE_INVIS]
1558 root 1.98 /* Might there be other objects that we can make visible? */
1559 root 1.124 && (tmp->invisible && (tmp->flag [FLAG_MONSTER]
1560     || (tmp->type == PLAYER && !tmp->flag [FLAG_WIZ])
1561 elmex 1.121 || tmp->type == T_HANDLE
1562     || tmp->type == TRAPDOOR
1563     || tmp->type == EXIT
1564     || tmp->type == HOLE
1565     || tmp->type == BUTTON
1566     || tmp->type == TELEPORTER
1567     || tmp->type == GATE
1568     || tmp->type == LOCKED_DOOR
1569     || tmp->type == WEAPON
1570     || tmp->type == ALTAR
1571 root 1.127 || (tmp->type == SIGN && tmp->face != magicmouth_face)
1572 elmex 1.121 || tmp->type == TRIGGER_PEDESTAL
1573     || tmp->type == SPECIAL_KEY
1574     || tmp->type == TREASURE
1575     || tmp->type == BOOK
1576     || tmp->type == HOLY_ALTAR
1577     || tmp->type == CONTAINER)))
1578 root 1.98 {
1579 root 1.127 printf ("show inv %s\n", tmp->debug_desc());//D
1580 root 1.98 if (random_roll (0, skill->level - 1, op, PREFER_HIGH) > level / 4)
1581     {
1582     tmp->invisible = 0;
1583     done_one = 1;
1584     }
1585     }
1586    
1587 root 1.124 if (tmp->flag [FLAG_IS_FLOOR])
1588 root 1.98 floor = 1;
1589    
1590     /* All detections below this point don't descend beneath the floor,
1591     * so just continue on. We could be clever and look at the type of
1592     * detection to completely break out if we don't care about objects beneath
1593     * the floor, but once we get to the floor, not likely a very big issue anyways.
1594     */
1595     if (floor)
1596     continue;
1597    
1598     /* I had thought about making detect magic and detect curse
1599     * show the flash the magic item like it does for detect monster.
1600     * however, if the object is within sight, this would then make it
1601     * difficult to see what object is magical/cursed, so the
1602     * effect wouldn't be as apparent.
1603     */
1604    
1605     /* detect magic */
1606 root 1.130 if (spell->flag [FLAG_KNOWN_MAGICAL]
1607     && !tmp->flag [FLAG_KNOWN_MAGICAL]
1608     && !tmp->flag [FLAG_IDENTIFIED]
1609     && tmp->need_identify ()
1610     && is_magical (tmp))
1611 root 1.98 {
1612 root 1.124 tmp->set_flag (FLAG_KNOWN_MAGICAL);
1613 elmex 1.121 /* make runes more visible */
1614 root 1.98 if (tmp->type == RUNE && tmp->attacktype & AT_MAGIC)
1615     tmp->stats.Cha /= 4;
1616    
1617     done_one = 1;
1618     }
1619    
1620     /* detect monster */
1621 root 1.124 if (spell->flag [FLAG_MONSTER] && (tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER))
1622 root 1.98 {
1623     done_one = 2;
1624    
1625     if (!detect)
1626     detect = tmp;
1627     }
1628    
1629     /* Basically, if race is set in the spell, then the creatures race must
1630     * match that. if the spell race is set to GOD, then the gods opposing
1631     * race must match.
1632     */
1633 root 1.124 if (spell->race && tmp->flag [FLAG_MONSTER] && tmp->race &&
1634 root 1.98 ((spell->race == shstr_GOD && god && god->slaying.contains (tmp->race)) ||
1635     spell->race.contains (tmp->race)))
1636     {
1637     done_one = 2;
1638    
1639     if (!detect)
1640     detect = tmp;
1641     }
1642 root 1.21
1643 root 1.130 if (spell->flag [FLAG_KNOWN_CURSED]
1644     && !tmp->flag [FLAG_KNOWN_CURSED]
1645     && tmp->need_identify ()
1646     && (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]))
1647 root 1.98 {
1648 root 1.124 tmp->set_flag (FLAG_KNOWN_CURSED);
1649 root 1.98 done_one = 1;
1650     }
1651 elmex 1.121
1652     // Do mining detection spell:
1653     if (spell->last_sp == 1) // 1 - detect any vein
1654     {
1655     if (tmp->type == VEIN)
1656     {
1657     if (tmp->other_arch)
1658     {
1659     if (!detect)
1660     detect = tmp->other_arch;
1661     done_one = 2;
1662     }
1663     else
1664     done_one = 1;
1665     }
1666     }
1667 root 1.98 } /* for stack of objects on this space */
1668 elmex 1.1
1669 root 1.98 /* Code here puts an effect of the spell on the space, so you can see
1670     * where the magic is.
1671     */
1672     if (done_one)
1673     {
1674 root 1.116 object *detect_ob = spell->other_arch->instance ();
1675 root 1.8
1676 root 1.98 /* if this is set, we want to copy the face */
1677     if (done_one == 2 && detect)
1678     {
1679     detect_ob->face = detect->face;
1680     detect_ob->animation_id = detect->animation_id;
1681     detect_ob->anim_speed = detect->anim_speed;
1682     detect_ob->last_anim = 0;
1683     /* by default, the detect_ob is already animated */
1684 root 1.124 if (!detect->flag [FLAG_ANIMATE])
1685     detect_ob->clr_flag (FLAG_ANIMATE);
1686 root 1.98 }
1687 root 1.27
1688 elmex 1.121 m->insert (detect_ob, nx, ny, op, INS_ON_TOP);
1689 root 1.98 }
1690     } /* for processing the surrounding spaces */
1691 root 1.5
1692    
1693 root 1.8 /* Now process objects in the players inventory if detect curse or magic */
1694 root 1.124 if (spell->flag [FLAG_KNOWN_CURSED] || spell->flag [FLAG_KNOWN_MAGICAL])
1695 root 1.8 {
1696     done_one = 0;
1697 root 1.80
1698 root 1.8 for (tmp = op->inv; tmp; tmp = tmp->below)
1699     {
1700 root 1.124 if (!tmp->invisible && !tmp->flag [FLAG_IDENTIFIED])
1701 root 1.8 {
1702 root 1.124 if (spell->flag [FLAG_KNOWN_MAGICAL] && is_magical (tmp) && !tmp->flag [FLAG_KNOWN_MAGICAL])
1703 root 1.8 {
1704 root 1.124 tmp->set_flag (FLAG_KNOWN_MAGICAL);
1705 root 1.80
1706     if (object *pl = tmp->visible_to ())
1707     esrv_update_item (UPD_FLAGS, pl, tmp);
1708 root 1.5 }
1709 root 1.80
1710 root 1.124 if (spell->flag [FLAG_KNOWN_CURSED] && !tmp->flag [FLAG_KNOWN_CURSED] &&
1711     (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]))
1712 root 1.8 {
1713 root 1.124 tmp->set_flag (FLAG_KNOWN_CURSED);
1714 root 1.80
1715     if (object *pl = tmp->visible_to ())
1716     esrv_update_item (UPD_FLAGS, pl, tmp);
1717 root 1.5 }
1718 root 1.8 } /* if item is not identified */
1719     } /* for the players inventory */
1720     } /* if detect magic/curse and object is a player */
1721 root 1.80
1722 root 1.8 return 1;
1723 elmex 1.1 }
1724    
1725    
1726     /**
1727     * Checks if victim has overcharged mana. caster_level is the caster's (skill)
1728     * level whos spell did cause the overcharge.
1729     */
1730 root 1.8 static void
1731     charge_mana_effect (object *victim, int caster_level)
1732 elmex 1.1 {
1733    
1734 root 1.8 /* Prevent explosions for objects without mana. Without this check, doors
1735     * will explode, too.
1736     */
1737     if (victim->stats.maxsp <= 0)
1738     return;
1739 elmex 1.1
1740 root 1.8 new_draw_info (NDI_UNIQUE, 0, victim, "You feel energy course through you.");
1741 elmex 1.1
1742 root 1.8 if (victim->stats.sp >= victim->stats.maxsp * 2)
1743     {
1744     new_draw_info (NDI_UNIQUE, 0, victim, "Your head explodes!");
1745     victim->stats.sp = 2 * victim->stats.maxsp;
1746 elmex 1.99 create_exploding_ball_at (victim, caster_level);
1747 elmex 1.1 }
1748 root 1.8 else if (victim->stats.sp >= victim->stats.maxsp * 1.88)
1749 root 1.86 new_draw_info (NDI_UNIQUE | NDI_ORANGE, 0, victim, "You feel like your head is going to explode.");
1750 root 1.8 else if (victim->stats.sp >= victim->stats.maxsp * 1.66)
1751 root 1.27 new_draw_info (NDI_UNIQUE, 0, victim, "You get a splitting headache!");
1752 root 1.8 else if (victim->stats.sp >= victim->stats.maxsp * 1.5)
1753     {
1754     new_draw_info (NDI_UNIQUE, 0, victim, "Chaos fills your world.");
1755     confuse_player (victim, victim, 99);
1756 elmex 1.1 }
1757 root 1.8 else if (victim->stats.sp >= victim->stats.maxsp * 1.25)
1758 root 1.27 new_draw_info (NDI_UNIQUE, 0, victim, "You start hearing voices.");
1759 elmex 1.1 }
1760    
1761     /* cast_transfer
1762     * This spell transfers sp from the player to another person.
1763     * We let the target go above their normal maximum SP.
1764     */
1765    
1766 root 1.8 int
1767     cast_transfer (object *op, object *caster, object *spell, int dir)
1768     {
1769     object *plyr = NULL;
1770     sint16 x, y;
1771 root 1.13 maptile *m;
1772 root 1.8 int mflags;
1773    
1774     m = op->map;
1775     x = op->x + freearr_x[dir];
1776     y = op->y + freearr_y[dir];
1777    
1778     mflags = get_map_flags (m, &m, x, y, &x, &y);
1779    
1780     if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
1781     {
1782 root 1.22 for (plyr = GET_MAP_OB (m, x, y); plyr != NULL; plyr = plyr->above)
1783 root 1.124 if (plyr != op && plyr->flag [FLAG_ALIVE])
1784 root 1.8 break;
1785 elmex 1.1 }
1786    
1787    
1788 root 1.8 /* If we did not find a player in the specified direction, transfer
1789     * to anyone on top of us. This is used for the rune of transference mostly.
1790     */
1791     if (plyr == NULL)
1792 root 1.22 for (plyr = GET_MAP_OB (op->map, op->x, op->y); plyr != NULL; plyr = plyr->above)
1793 root 1.124 if (plyr != op && plyr->flag [FLAG_ALIVE])
1794 root 1.8 break;
1795 elmex 1.1
1796 root 1.8 if (!plyr)
1797     {
1798 root 1.125 op->failmsg ("There is no one there.");
1799 root 1.8 return 0;
1800 elmex 1.1 }
1801 root 1.8 /* give sp */
1802     if (spell->stats.dam > 0)
1803     {
1804     plyr->stats.sp += spell->stats.dam + SP_level_dam_adjust (caster, spell);
1805 root 1.89 charge_mana_effect (plyr, casting_level (caster, spell));
1806 root 1.8 return 1;
1807 elmex 1.1 }
1808 root 1.8 /* suck sp away. Can't suck sp from yourself */
1809     else if (op != plyr)
1810     {
1811     /* old dragin magic used floats. easier to just use ints and divide by 100 */
1812    
1813     int rate = -spell->stats.dam + SP_level_dam_adjust (caster, spell), sucked;
1814    
1815     if (rate > 95)
1816     rate = 95;
1817    
1818     sucked = (plyr->stats.sp * rate) / 100;
1819     plyr->stats.sp -= sucked;
1820 root 1.124 if (op->flag [FLAG_ALIVE])
1821 root 1.8 {
1822     /* Player doesn't get full credit */
1823     sucked = (sucked * rate) / 100;
1824     op->stats.sp += sucked;
1825     if (sucked > 0)
1826     {
1827 root 1.89 charge_mana_effect (op, casting_level (caster, spell));
1828 root 1.5 }
1829     }
1830 root 1.8 return 1;
1831 elmex 1.1 }
1832 root 1.8 return 0;
1833 elmex 1.1 }
1834    
1835    
1836     /* counterspell: nullifies spell effects.
1837     * op is the counterspell object, dir is the direction
1838     * it was cast in.
1839     * Basically, if the object has a magic attacktype,
1840     * this may nullify it.
1841     */
1842 root 1.8 void
1843     counterspell (object *op, int dir)
1844 elmex 1.1 {
1845 root 1.8 object *tmp, *head, *next;
1846     int mflags;
1847 root 1.13 maptile *m;
1848 root 1.8 sint16 sx, sy;
1849    
1850     sx = op->x + freearr_x[dir];
1851     sy = op->y + freearr_y[dir];
1852     m = op->map;
1853     mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
1854     if (mflags & P_OUT_OF_MAP)
1855     return;
1856 elmex 1.1
1857 root 1.22 for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = next)
1858 root 1.8 {
1859     next = tmp->above;
1860 elmex 1.1
1861 root 1.8 /* Need to look at the head object - otherwise, if tmp
1862     * points to a monster, we don't have all the necessary
1863     * info for it.
1864     */
1865     if (tmp->head)
1866     head = tmp->head;
1867     else
1868     head = tmp;
1869    
1870     /* don't attack our own spells */
1871     if (tmp->owner && tmp->owner == op->owner)
1872     continue;
1873    
1874     /* Basically, if the object is magical and not counterspell,
1875     * we will more or less remove the object. Don't counterspell
1876     * monsters either.
1877     */
1878 elmex 1.1
1879 elmex 1.44 if (head->attacktype & AT_MAGIC
1880     && !(head->attacktype & AT_COUNTERSPELL)
1881 root 1.124 && !head->flag [FLAG_MONSTER]
1882 elmex 1.44 && (op->level > head->level))
1883 root 1.91 head->destroy ();
1884 root 1.8 else
1885     switch (head->type)
1886     {
1887     case SPELL_EFFECT:
1888 elmex 1.44 // XXX: Don't affect floor spelleffects. See also XXX comment
1889     // about sanctuary in spell_util.C
1890 root 1.124 if (tmp->flag [FLAG_IS_FLOOR])
1891 elmex 1.44 continue;
1892    
1893 root 1.8 if (op->level > head->level)
1894 root 1.91 head->destroy ();
1895 root 1.17
1896 root 1.5 break;
1897    
1898 root 1.8 /* I really don't get this rune code that much - that
1899     * random chance seems really low.
1900     */
1901     case RUNE:
1902     if (rndm (0, 149) == 0)
1903     {
1904     head->stats.hp--; /* weaken the rune */
1905     if (!head->stats.hp)
1906 root 1.91 head->destroy ();
1907 root 1.8 }
1908 root 1.5 break;
1909 root 1.8 }
1910 elmex 1.1 }
1911     }
1912    
1913     /* cast_consecrate() - a spell to make an altar your god's */
1914 root 1.8 int
1915     cast_consecrate (object *op, object *caster, object *spell)
1916     {
1917     char buf[MAX_BUF];
1918 elmex 1.1
1919 root 1.8 object *tmp, *god = find_god (determine_god (op));
1920 elmex 1.1
1921 root 1.8 if (!god)
1922     {
1923 root 1.125 op->failmsg ("You can't consecrate anything if you don't worship a god!");
1924 root 1.8 return 0;
1925 elmex 1.1 }
1926 root 1.8
1927     for (tmp = op->below; tmp; tmp = tmp->below)
1928     {
1929 root 1.124 if (tmp->flag [FLAG_IS_FLOOR])
1930 root 1.8 break;
1931     if (tmp->type == HOLY_ALTAR)
1932     {
1933    
1934 root 1.89 if (tmp->level > casting_level (caster, spell))
1935 root 1.8 {
1936 root 1.125 op->failmsgf ("You are not powerful enough to reconsecrate the %s", &tmp->name);
1937 root 1.8 return 0;
1938     }
1939     else
1940     {
1941     /* If we got here, we are consecrating an altar */
1942     sprintf (buf, "Altar of %s", &god->name);
1943     tmp->name = buf;
1944 root 1.89 tmp->level = casting_level (caster, spell);
1945 root 1.8 tmp->other_arch = god->arch;
1946 root 1.80
1947 root 1.8 if (op->type == PLAYER)
1948     esrv_update_item (UPD_NAME, op, tmp);
1949 root 1.80
1950 root 1.8 new_draw_info_format (NDI_UNIQUE, 0, op, "You consecrated the altar to %s!", &god->name);
1951     return 1;
1952 root 1.5 }
1953     }
1954 elmex 1.1 }
1955 root 1.125
1956     op->failmsg ("You are not standing over an altar!");
1957 root 1.8 return 0;
1958 elmex 1.1 }
1959    
1960     /* animate_weapon -
1961     * Generalization of staff_to_snake. Makes a golem out of the caster's weapon.
1962     * The golem is based on the archetype specified, modified by the caster's level
1963     * and the attributes of the weapon. The weapon is inserted in the golem's
1964     * inventory so that it falls to the ground when the golem dies.
1965     * This code was very odd - code early on would only let players use the spell,
1966     * yet the code wass full of player checks. I've presumed that the code
1967     * that only let players use it was correct, and removed all the other
1968     * player checks. MSW 2003-01-06
1969     */
1970 root 1.8 int
1971     animate_weapon (object *op, object *caster, object *spell, int dir)
1972     {
1973     char buf[MAX_BUF];
1974     int a, i;
1975     sint16 x, y;
1976 root 1.13 maptile *m;
1977 root 1.8
1978     if (!spell->other_arch)
1979     {
1980     new_draw_info (NDI_UNIQUE, 0, op, "Oops, program error!");
1981     LOG (llevError, "animate_weapon failed: spell %s missing other_arch!\n", &spell->name);
1982     return 0;
1983 elmex 1.1 }
1984 root 1.8 /* exit if it's not a player using this spell. */
1985     if (op->type != PLAYER)
1986     return 0;
1987 elmex 1.1
1988 root 1.8 /* if player already has a golem, abort */
1989 root 1.49 if (object *golem = op->contr->golem)
1990 root 1.8 {
1991 root 1.46 control_golem (golem, dir);
1992 root 1.8 return 0;
1993 elmex 1.1 }
1994    
1995 root 1.8 /* if no direction specified, pick one */
1996     if (!dir)
1997 root 1.84 dir = find_free_spot (spell->other_arch, op->map, op->x, op->y, 1, 9);
1998 root 1.8
1999     m = op->map;
2000     x = op->x + freearr_x[dir];
2001     y = op->y + freearr_y[dir];
2002    
2003     /* if there's no place to put the golem, abort */
2004 root 1.84 if (dir < 0 || (get_map_flags (m, &m, x, y, &x, &y) & P_OUT_OF_MAP)
2005     || ((spell->other_arch->move_type & GET_MAP_MOVE_BLOCK (m, x, y)) == spell->other_arch->move_type))
2006 root 1.8 {
2007 root 1.125 op->failmsg ("There is something in the way.");
2008 root 1.8 return 0;
2009 elmex 1.1 }
2010    
2011 root 1.8 /* Use the weapon marked by the player. */
2012 root 1.128 object *weapon = op->mark ();
2013 elmex 1.1
2014 root 1.8 if (!weapon)
2015     {
2016 root 1.125 op->failmsg ("You must mark a weapon to use with this spell!");
2017 root 1.8 return 0;
2018     }
2019 root 1.93
2020     if (spell->race && weapon->arch->archname != spell->race)
2021 root 1.8 {
2022 root 1.125 op->failmsg ("The spell fails to transform your weapon.");
2023 root 1.8 return 0;
2024     }
2025 root 1.93
2026 root 1.8 if (weapon->type != WEAPON)
2027     {
2028 root 1.125 op->failmsg ("You need to wield a weapon to animate it.");
2029 root 1.8 return 0;
2030 elmex 1.1 }
2031 root 1.93
2032 root 1.124 if (weapon->flag [FLAG_APPLIED])
2033 root 1.8 {
2034 root 1.125 op->failmsgf ("You need to unequip %s before using it in this spell", query_name (weapon));
2035 root 1.8 return 0;
2036 elmex 1.1 }
2037 root 1.8
2038 root 1.80 weapon = weapon->split ();
2039 root 1.8
2040     /* create the golem object */
2041 root 1.128 object *tmp = spell->other_arch->instance ();
2042 root 1.8
2043     /* if animated by a player, give the player control of the golem */
2044 root 1.124 tmp->clr_flag (FLAG_MONSTER);
2045 root 1.8 tmp->stats.exp = 0;
2046     add_friendly_object (tmp);
2047     tmp->type = GOLEM;
2048 root 1.19 tmp->set_owner (op);
2049 root 1.49 op->contr->golem = tmp;
2050 root 1.46 set_spell_skill (op, caster, spell, tmp);
2051 root 1.8
2052     /* Give the weapon to the golem now. A bit of a hack to check the
2053 root 1.79 * removed flag - it should only be set if weapon->split was
2054 root 1.8 * used above.
2055     */
2056 root 1.124 if (!weapon->flag [FLAG_REMOVED])
2057 root 1.16 weapon->remove ();
2058 root 1.46
2059 root 1.80 tmp->insert (weapon);
2060    
2061 root 1.8 /* To do everything necessary to let a golem use the weapon is a pain,
2062     * so instead, just set it as equipped (otherwise, we need to update
2063     * body_info, skills, etc)
2064     */
2065 root 1.124 tmp->set_flag (FLAG_USE_WEAPON);
2066     weapon->set_flag (FLAG_APPLIED);
2067 root 1.24 tmp->update_stats ();
2068 root 1.8
2069     /* There used to be 'odd' code that basically seemed to take the absolute
2070     * value of the weapon->magic an use that. IMO, that doesn't make sense -
2071     * if you're using a crappy weapon, it shouldn't be as good.
2072     */
2073    
2074     /* modify weapon's animated wc */
2075     tmp->stats.wc = tmp->stats.wc - SP_level_range_adjust (caster, spell) - 5 * weapon->stats.Dex - 2 * weapon->stats.Str - weapon->magic;
2076     if (tmp->stats.wc < -127)
2077     tmp->stats.wc = -127;
2078    
2079     /* Modify hit points for weapon */
2080     tmp->stats.maxhp = tmp->stats.maxhp + spell->duration +
2081     SP_level_duration_adjust (caster, spell) + +8 * weapon->magic + 12 * weapon->stats.Con;
2082     if (tmp->stats.maxhp < 0)
2083     tmp->stats.maxhp = 10;
2084     tmp->stats.hp = tmp->stats.maxhp;
2085    
2086     /* Modify weapon's damage */
2087     tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell) + weapon->stats.dam + weapon->magic + 5 * weapon->stats.Str;
2088     if (tmp->stats.dam < 0)
2089     tmp->stats.dam = 127;
2090    
2091    
2092     /* attacktype */
2093     if (!tmp->attacktype)
2094     tmp->attacktype = AT_PHYSICAL;
2095    
2096 root 1.114 for (i = 0; i < NROFATTACKS; i++)
2097     tmp->resist[i] = 50 - (op->material->save[i] * 5);
2098    
2099     a = op->material->save[0];
2100 root 1.63
2101 root 1.8 /* Set weapon's immunity */
2102     tmp->resist[ATNR_CONFUSION] = 100;
2103     tmp->resist[ATNR_POISON] = 100;
2104     tmp->resist[ATNR_SLOW] = 100;
2105     tmp->resist[ATNR_PARALYZE] = 100;
2106     tmp->resist[ATNR_TURN_UNDEAD] = 100;
2107     tmp->resist[ATNR_FEAR] = 100;
2108     tmp->resist[ATNR_DEPLETE] = 100;
2109     tmp->resist[ATNR_DEATH] = 100;
2110     tmp->resist[ATNR_BLIND] = 100;
2111    
2112     /* Improve weapon's armour value according to best save vs. physical of its material */
2113    
2114     if (a > 14)
2115     a = 14;
2116 root 1.63
2117 root 1.139 tmp->resist[ATNR_PHYSICAL] = 100 - (int) ((100.f - (float) tmp->resist[ATNR_PHYSICAL]) / (30.f - 2.f * a));
2118 root 1.8
2119     /* Determine golem's speed */
2120 root 1.139 tmp->set_speed (min (3.33f, 0.4f + 0.1f * SP_level_range_adjust (caster, spell)));
2121 root 1.8
2122     if (!spell->race)
2123     {
2124     sprintf (buf, "animated %s", &weapon->name);
2125     tmp->name = buf;
2126    
2127     tmp->face = weapon->face;
2128     tmp->animation_id = weapon->animation_id;
2129     tmp->anim_speed = weapon->anim_speed;
2130     tmp->last_anim = weapon->last_anim;
2131     tmp->state = weapon->state;
2132 root 1.26 tmp->flag [FLAG_ANIMATE] = weapon->flag [FLAG_ANIMATE];
2133 elmex 1.1 }
2134    
2135 root 1.8 /* make experience increase in proportion to the strength of the summoned creature. */
2136 root 1.113 tmp->stats.exp *= 1 + (max (spell->stats.maxgrace, spell->stats.sp) / casting_level (caster, spell));
2137 root 1.8
2138     tmp->speed_left = -1;
2139     tmp->direction = dir;
2140 root 1.27
2141     m->insert (tmp, x, y, op);
2142 root 1.8 return 1;
2143 elmex 1.1 }
2144    
2145     /* cast_daylight() - changes the map darkness level *lower* */
2146    
2147     /* cast_change_map_lightlevel: Was cast_daylight/nightfall.
2148     * This changes the light level for the entire map.
2149     */
2150 root 1.8 int
2151     cast_change_map_lightlevel (object *op, object *caster, object *spell)
2152     {
2153     int success;
2154 elmex 1.1
2155 root 1.8 if (!op->map)
2156     return 0; /* shouldnt happen */
2157 elmex 1.1
2158 root 1.28 success = op->map->change_map_light (spell->stats.dam);
2159    
2160 root 1.8 if (!success)
2161     {
2162     if (spell->stats.dam < 0)
2163 root 1.125 op->failmsg ("It can be no brighter here.");
2164 root 1.8 else
2165 root 1.125 op->failmsg ("It can be no darker here.");
2166 elmex 1.1 }
2167 root 1.92
2168 root 1.8 return success;
2169 elmex 1.1 }
2170    
2171     /* create an aura spell object and put it in the player's inventory.
2172     * as usual, op is player, caster is the object casting the spell,
2173     * spell is the spell object itself.
2174     */
2175 root 1.8 int
2176     create_aura (object *op, object *caster, object *spell)
2177 elmex 1.1 {
2178 root 1.8 int refresh = 0;
2179     object *new_aura;
2180 elmex 1.1
2181 root 1.8 new_aura = present_arch_in_ob (spell->other_arch, op);
2182     if (new_aura)
2183     refresh = 1;
2184     else
2185 root 1.116 new_aura = spell->other_arch->instance ();
2186 root 1.8
2187     new_aura->duration = spell->duration + 10 * SP_level_duration_adjust (caster, spell);
2188    
2189     new_aura->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
2190    
2191     set_spell_skill (op, caster, spell, new_aura);
2192     new_aura->attacktype = spell->attacktype;
2193    
2194 root 1.89 new_aura->level = casting_level (caster, spell);
2195 root 1.71
2196 root 1.8 if (refresh)
2197     new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect.");
2198     else
2199     new_draw_info (NDI_UNIQUE, 0, op, "You create an aura of magical force.");
2200 root 1.71
2201 root 1.8 insert_ob_in_ob (new_aura, op);
2202 root 1.71 new_aura->set_owner (op);
2203    
2204 root 1.8 return 1;
2205 elmex 1.1 }
2206    
2207     /* move aura function. An aura is a part of someone's inventory,
2208     * which he carries with him, but which acts on the map immediately
2209     * around him.
2210     * Aura parameters:
2211     * duration: duration counter.
2212     * attacktype: aura's attacktype
2213     * other_arch: archetype to drop where we attack
2214     */
2215 root 1.8 void
2216     move_aura (object *aura)
2217     {
2218     /* auras belong in inventories */
2219 root 1.72 object *env = aura->env;
2220     object *owner = aura->owner;
2221 root 1.8
2222     /* no matter what we've gotta remove the aura...
2223     * we'll put it back if its time isn't up.
2224     */
2225 root 1.16 aura->remove ();
2226 root 1.8
2227     /* exit if we're out of gas */
2228     if (aura->duration-- < 0)
2229     {
2230 root 1.91 aura->destroy ();
2231 root 1.8 return;
2232     }
2233    
2234     /* auras only exist in inventories */
2235 root 1.72 if (!env || !env->map)
2236 root 1.8 {
2237 root 1.91 aura->destroy ();
2238 root 1.8 return;
2239     }
2240 root 1.17
2241 root 1.8 /* we need to jump out of the inventory for a bit
2242     * in order to hit the map conveniently.
2243     */
2244 root 1.27 aura->insert_at (env, aura);
2245 root 1.8
2246 root 1.72 for (int i = 1; i < 9; i++)
2247 root 1.8 {
2248 root 1.72 mapxy pos (env);
2249     pos.move (i);
2250 root 1.8
2251 root 1.72 /* Consider the movement type of the person with the aura as
2252     * movement type of the aura. Eg, if the player is flying, the aura
2253 root 1.8 * is flying also, if player is walking, it is on the ground, etc.
2254     */
2255 root 1.72 if (pos.normalise () && !(OB_TYPE_MOVE_BLOCK (env, pos->move_block)))
2256 elmex 1.6 {
2257 root 1.8 hit_map (aura, i, aura->attacktype, 0);
2258 root 1.5
2259 root 1.8 if (aura->other_arch)
2260 root 1.116 pos.insert (aura->other_arch->instance (), aura);
2261 root 1.5 }
2262 elmex 1.1 }
2263 root 1.27
2264 root 1.8 /* put the aura back in the player's inventory */
2265 root 1.72 env->insert (aura);
2266     aura->set_owner (owner);
2267 elmex 1.1 }
2268    
2269     /* moves the peacemaker spell.
2270     * op is the piece object.
2271 root 1.8 */
2272     void
2273     move_peacemaker (object *op)
2274     {
2275 root 1.93 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
2276 root 1.8 {
2277     int atk_lev, def_lev;
2278 root 1.81 object *victim = tmp->head_ ();
2279 elmex 1.1
2280 root 1.124 if (!victim->flag [FLAG_MONSTER])
2281 root 1.8 continue;
2282 root 1.81
2283 root 1.124 if (victim->flag [FLAG_UNAGGRESSIVE])
2284 root 1.8 continue;
2285 root 1.81
2286 root 1.8 if (victim->stats.exp == 0)
2287     continue;
2288 elmex 1.1
2289 root 1.113 def_lev = max (1, victim->level);
2290     atk_lev = max (1, op->level);
2291 elmex 1.1
2292 root 1.8 if (rndm (0, atk_lev - 1) > def_lev)
2293     {
2294     /* make this sucker peaceful. */
2295 elmex 1.1
2296 root 1.81 INVOKE_OBJECT (KILL, victim, ARG_OBJECT (op));
2297 root 1.19 change_exp (op->owner, victim->stats.exp, op->skill, 0);
2298 root 1.8 victim->stats.exp = 0;
2299 elmex 1.1 #if 0
2300 root 1.8 /* No idea why these were all set to zero - if something
2301     * makes this creature agressive, he should still do damage.
2302     */
2303     victim->stats.dam = 0;
2304     victim->stats.sp = 0;
2305     victim->stats.grace = 0;
2306     victim->stats.Pow = 0;
2307 elmex 1.1 #endif
2308 root 1.8 victim->attack_movement = RANDO2;
2309 root 1.124 victim->set_flag (FLAG_UNAGGRESSIVE);
2310     victim->set_flag (FLAG_RUN_AWAY);
2311     victim->set_flag (FLAG_RANDOM_MOVE);
2312     victim->clr_flag (FLAG_MONSTER);
2313 root 1.81
2314 root 1.8 if (victim->name)
2315 root 1.81 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s no longer feels like fighting.", &victim->name);
2316 root 1.5 }
2317 elmex 1.1 }
2318 root 1.8 }
2319    
2320 elmex 1.1 /* This writes a rune that contains the appropriate message.
2321     * There really isn't any adjustments we make.
2322     */
2323 root 1.8 int
2324     write_mark (object *op, object *spell, const char *msg)
2325     {
2326     if (!msg || msg[0] == 0)
2327     {
2328 root 1.125 op->failmsg ("Write what?");
2329 root 1.8 return 0;
2330 elmex 1.1 }
2331    
2332 sf-marcmagus 1.109 if (!msg_is_safe (msg))
2333 root 1.8 {
2334 root 1.125 op->failmsg ("Trying to cheat are we? H<@-signs are not allowed in marking runes.>");
2335 sf-marcmagus 1.109 LOG (llevInfo, "write_mark: player %s tried to write bogus rune %s\n", &op->name, msg);
2336 root 1.8 return 0;
2337 elmex 1.1 }
2338 root 1.97
2339 root 1.8 if (!spell->other_arch)
2340     return 0;
2341 root 1.9
2342 root 1.116 object *tmp = spell->other_arch->instance ();
2343 root 1.9
2344 root 1.8 tmp->race = op->name; /*Save the owner of the rune */
2345 root 1.97 tmp->msg = msg;
2346 root 1.27
2347     tmp->insert_at (op, op, INS_BELOW_ORIGINATOR);
2348 root 1.97
2349 root 1.8 return 1;
2350 elmex 1.1 }
2351 root 1.97