| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <assert.h> |
| 22 |
#include <ctype.h> |
| 23 |
#include <errno.h> |
| 24 |
#include <stdlib.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "living.h" |
| 28 |
#include "object.h" |
| 29 |
#include "sounds.h" |
| 30 |
#include "spells.h" |
| 31 |
#include "sproto.h" |
| 32 |
|
| 33 |
extern const char *const spell_mapping[]; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
object *find_random_spell_in_ob(object *ob, const char *skill) { |
| 49 |
int k = 0, s; |
| 50 |
|
| 51 |
FOR_INV_PREPARE(ob, tmp) |
| 52 |
if (tmp->type == SPELL && (!skill || tmp->skill == skill)) |
| 53 |
k++; |
| 54 |
FOR_INV_FINISH(); |
| 55 |
|
| 56 |
|
| 57 |
if (!k) |
| 58 |
return NULL; |
| 59 |
|
| 60 |
s = RANDOM()%k; |
| 61 |
FOR_INV_PREPARE(ob, tmp) |
| 62 |
if (tmp->type == SPELL && (!skill || tmp->skill == skill)) { |
| 63 |
if (!s) |
| 64 |
return tmp; |
| 65 |
else |
| 66 |
s--; |
| 67 |
} |
| 68 |
FOR_INV_FINISH(); |
| 69 |
|
| 70 |
|
| 71 |
return NULL; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
void set_spell_skill(object *op, object *caster, object *spob, object *dest) { |
| 95 |
if (dest->skill) |
| 96 |
FREE_AND_CLEAR_STR(dest->skill); |
| 97 |
if (caster == op && spob->skill) |
| 98 |
dest->skill = add_refcount(spob->skill); |
| 99 |
else if (caster->skill) |
| 100 |
dest->skill = add_refcount(caster->skill); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
void check_spells(void) { |
| 110 |
#ifdef SPELL_DEBUG |
| 111 |
int i; |
| 112 |
archetype *at; |
| 113 |
|
| 114 |
LOG(llevDebug, "Checking spells...\n"); |
| 115 |
|
| 116 |
for (at = first_archetype; at; at = at->next) { |
| 117 |
if (at->clone.type == SPELL) { |
| 118 |
if (at->clone.skill) { |
| 119 |
for (i = 0; i < MAX_SKILLS && skill_names[i]; i++) |
| 120 |
if (!strcmp(skill_names[i], at->clone.skill)) |
| 121 |
break; |
| 122 |
if (i == MAX_SKILLS || !skill_names[i]) { |
| 123 |
LOG(llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
i = 0; |
| 131 |
while (spell_mapping[i]) { |
| 132 |
if (!find_archetype(spell_mapping[i])) { |
| 133 |
LOG(llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i); |
| 134 |
} |
| 135 |
i++; |
| 136 |
} |
| 137 |
LOG(llevDebug, "Checking spells completed.\n"); |
| 138 |
#endif |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
void dump_spells(void) { |
| 147 |
archetype *at; |
| 148 |
int banner = 0; |
| 149 |
|
| 150 |
for (at = first_archetype; at; at = at->next) { |
| 151 |
if (at->clone.type == SPELL) { |
| 152 |
fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null", |
| 153 |
at->name, at->clone.other_arch ? at->clone.other_arch->name : "null", |
| 154 |
at->clone.skill ? at->clone.skill : "null", at->clone.level); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
for (at = first_archetype; at; at = at->next) { |
| 159 |
if (at->clone.type == SPELL && at->clone.path_attuned == 0) { |
| 160 |
if (banner == 0) { |
| 161 |
banner = 1; |
| 162 |
fprintf(stderr, "Spells with no path set:\n"); |
| 163 |
} |
| 164 |
|
| 165 |
fprintf(stderr, "- %s\n", at->clone.name ? at->clone.name : "null"); |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) { |
| 184 |
if (spob->other_arch != NULL) { |
| 185 |
object *effect = arch_to_object(spob->other_arch); |
| 186 |
object_insert_in_map_at(effect, map, originator, 0, x, y); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
int min_casting_level(const object *caster, const object *spell) { |
| 204 |
int new_level; |
| 205 |
|
| 206 |
if (caster->path_denied&spell->path_attuned) { |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
return 1; |
| 211 |
} |
| 212 |
new_level = spell->level |
| 213 |
+((caster->path_repelled&spell->path_attuned) ? +2 : 0) |
| 214 |
+((caster->path_attuned&spell->path_attuned) ? -2 : 0); |
| 215 |
return MAX(new_level, 1); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
int caster_level(const object *caster, const object *spell) { |
| 234 |
int level = caster->level; |
| 235 |
|
| 236 |
|
| 237 |
if (caster->type == PLAYER && spell->skill) { |
| 238 |
object* skill = find_applied_skill_by_name(caster, spell->skill); |
| 239 |
if (skill != NULL) { |
| 240 |
level = skill->level; |
| 241 |
} else { |
| 242 |
level = 0; |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0) |
| 247 |
+((caster->path_attuned&spell->path_attuned) ? 2 : 0); |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
if (level < 1) |
| 253 |
level = 1; |
| 254 |
return level; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags) { |
| 276 |
int sp, grace, level = caster_level(caster, spell); |
| 277 |
|
| 278 |
if (settings.spellpoint_level_depend == TRUE) { |
| 279 |
if (spell->stats.sp && spell->stats.maxsp) { |
| 280 |
sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp))); |
| 281 |
} else |
| 282 |
sp = spell->stats.sp; |
| 283 |
|
| 284 |
sp *= PATH_SP_MULT(caster, spell); |
| 285 |
if (!sp && spell->stats.sp) |
| 286 |
sp = 1; |
| 287 |
|
| 288 |
if (spell->stats.grace && spell->stats.maxgrace) { |
| 289 |
grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace))); |
| 290 |
} else |
| 291 |
grace = spell->stats.grace; |
| 292 |
|
| 293 |
grace *= PATH_SP_MULT(caster, spell); |
| 294 |
if (spell->stats.grace && !grace) |
| 295 |
grace = 1; |
| 296 |
} else { |
| 297 |
sp = spell->stats.sp*PATH_SP_MULT(caster, spell); |
| 298 |
if (spell->stats.sp && !sp) |
| 299 |
sp = 1; |
| 300 |
grace = spell->stats.grace*PATH_SP_MULT(caster, spell); |
| 301 |
if (spell->stats.grace && !grace) |
| 302 |
grace = 1; |
| 303 |
} |
| 304 |
if (flags == SPELL_HIGHEST) |
| 305 |
return MAX(sp, grace); |
| 306 |
else if (flags == SPELL_GRACE) |
| 307 |
return grace; |
| 308 |
else if (flags == SPELL_MANA) |
| 309 |
return sp; |
| 310 |
else { |
| 311 |
LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags); |
| 312 |
return 0; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
int SP_level_dam_adjust(const object *caster, const object *spob) { |
| 327 |
int level = caster_level(caster, spob); |
| 328 |
int adj = level-min_casting_level(caster, spob); |
| 329 |
|
| 330 |
if (adj < 0) |
| 331 |
adj = 0; |
| 332 |
if (spob->dam_modifier) |
| 333 |
adj /= spob->dam_modifier; |
| 334 |
else |
| 335 |
adj = 0; |
| 336 |
return adj; |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
int SP_level_duration_adjust(const object *caster, const object *spob) { |
| 352 |
int level = caster_level(caster, spob); |
| 353 |
int adj = level-min_casting_level(caster, spob); |
| 354 |
|
| 355 |
if (adj < 0) |
| 356 |
adj = 0; |
| 357 |
if (spob->duration_modifier) |
| 358 |
adj /= spob->duration_modifier; |
| 359 |
else |
| 360 |
adj = 0; |
| 361 |
|
| 362 |
return adj; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
int SP_level_range_adjust(const object *caster, const object *spob) { |
| 378 |
int level = caster_level(caster, spob); |
| 379 |
int adj = level-min_casting_level(caster, spob); |
| 380 |
|
| 381 |
if (adj < 0) |
| 382 |
adj = 0; |
| 383 |
if (spob->range_modifier) |
| 384 |
adj /= spob->range_modifier; |
| 385 |
else |
| 386 |
adj = 0; |
| 387 |
|
| 388 |
return adj; |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
int SP_level_wc_adjust(const object *caster, const object *spob) { |
| 402 |
int level = caster_level(caster, spob); |
| 403 |
int adj = level - min_casting_level(caster, spob), irate; |
| 404 |
sstring rate; |
| 405 |
|
| 406 |
rate = object_get_value(spob, "wc_increase_rate"); |
| 407 |
|
| 408 |
if (rate == NULL) |
| 409 |
return 0; |
| 410 |
|
| 411 |
if (adj < 0) |
| 412 |
adj = 0; |
| 413 |
|
| 414 |
irate = atoi(rate); |
| 415 |
if (irate > 0) |
| 416 |
adj /= irate; |
| 417 |
else |
| 418 |
adj = 0; |
| 419 |
return adj; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
object *check_spell_known(object *op, const char *name) { |
| 434 |
return object_find_by_type_and_name(op, SPELL, name); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
object *lookup_spell_by_name(object *op, const char *spname) { |
| 450 |
object *spob1 = NULL, *spob2 = NULL; |
| 451 |
int nummatch = 0; |
| 452 |
|
| 453 |
if (spname == NULL) |
| 454 |
return NULL; |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
FOR_INV_PREPARE(op, spob) { |
| 461 |
if (spob->type == SPELL) { |
| 462 |
if (!strncmp(spob->name, spname, strlen(spname))) { |
| 463 |
if (strlen(spname) == strlen(spob->name)) |
| 464 |
|
| 465 |
return spob; |
| 466 |
nummatch++; |
| 467 |
spob1 = spob; |
| 468 |
} else if (!strncmp(spob->name, spname, strlen(spob->name))) { |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
if (spob2) |
| 475 |
LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name); |
| 476 |
spob2 = spob; |
| 477 |
} |
| 478 |
} |
| 479 |
} FOR_INV_FINISH(); |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
if (spob2) |
| 484 |
return spob2; |
| 485 |
if (spob1 && nummatch == 1) |
| 486 |
return spob1; |
| 487 |
return NULL; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
int reflwall(mapstruct *m, int x, int y, object *sp_op) { |
| 510 |
if (OUT_OF_REAL_MAP(m, x, y)) |
| 511 |
return 0; |
| 512 |
FOR_MAP_PREPARE(m, x, y, op) |
| 513 |
if (QUERY_FLAG(op, FLAG_REFL_SPELL) |
| 514 |
&& (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10))) |
| 515 |
return 1; |
| 516 |
FOR_MAP_FINISH(); |
| 517 |
return 0; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
int cast_create_obj(object *op, object *new_op, int dir) { |
| 534 |
mapstruct *m; |
| 535 |
int16_t sx, sy; |
| 536 |
|
| 537 |
if (dir |
| 538 |
&& ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP) |
| 539 |
|| OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) { |
| 540 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, |
| 541 |
"Something is in the way. You cast it at your feet."); |
| 542 |
dir = 0; |
| 543 |
} |
| 544 |
if (dir == 0) |
| 545 |
object_insert_in_map_at(new_op, op->map, op, INS_BELOW_ORIGINATOR, op->x+freearr_x[dir], op->y+freearr_y[dir]); |
| 546 |
else |
| 547 |
object_insert_in_map_at(new_op, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]); |
| 548 |
return dir; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop) { |
| 570 |
int mflags; |
| 571 |
mapstruct *mp; |
| 572 |
|
| 573 |
mp = m; |
| 574 |
mflags = get_map_flags(m, &mp, x, y, &x, &y); |
| 575 |
|
| 576 |
if (mflags&P_OUT_OF_MAP) |
| 577 |
return 0; |
| 578 |
|
| 579 |
if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(mp, x, y))) |
| 580 |
return 0; |
| 581 |
|
| 582 |
FOR_MAP_PREPARE(mp, x, y, tmp) { |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
if ((tmp->attacktype&AT_COUNTERSPELL) |
| 593 |
&& (tmp->type != PLAYER) |
| 594 |
&& !QUERY_FLAG(tmp, FLAG_MONSTER) |
| 595 |
&& (tmp->type != WEAPON) |
| 596 |
&& (tmp->type != BOW) |
| 597 |
&& (tmp->type != ARROW) |
| 598 |
&& (tmp->type != GOLEM) |
| 599 |
&& (immune_stop&AT_MAGIC)) |
| 600 |
return 0; |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
if (tmp->type == op->type |
| 613 |
&& tmp->subtype == op->subtype |
| 614 |
&& tmp->stats.maxhp |
| 615 |
&& op->stats.maxhp) { |
| 616 |
if ((tmp->stats.maxhp == op->stats.maxhp) |
| 617 |
|| (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp)) |
| 618 |
|| (op->spell_tags && OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp))) { |
| 619 |
statistics.spell_suppressions++; |
| 620 |
return 0; |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
if (op->spell_tags && tmp->spell_tags) { |
| 628 |
int i; |
| 629 |
|
| 630 |
for (i = 0; i < SPELL_TAG_SIZE; i++) { |
| 631 |
if (op->spell_tags[i] && |
| 632 |
op->spell_tags[i] == tmp->spell_tags[i]) { |
| 633 |
statistics.spell_suppressions++; |
| 634 |
return 0; |
| 635 |
} |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
} FOR_MAP_FINISH(); |
| 643 |
|
| 644 |
return 1; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell) { |
| 669 |
object *tmp; |
| 670 |
int mflags; |
| 671 |
mapstruct *m; |
| 672 |
|
| 673 |
if (dir < 0 || dir > 8) { |
| 674 |
LOG(llevError, "Invalid direction %d in fire_arch_from_position for %s\n", dir, spell->name); |
| 675 |
dir = RANDOM() % 8 + 1; |
| 676 |
} |
| 677 |
|
| 678 |
if (spell->other_arch == NULL) |
| 679 |
return 0; |
| 680 |
|
| 681 |
if (spell->type != SPELL) |
| 682 |
LOG(llevError, "Unexpected object type %d in fire_arch_from_position for %s\n", spell->type, spell->name); |
| 683 |
|
| 684 |
m = op->map; |
| 685 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 686 |
if (mflags&P_OUT_OF_MAP) { |
| 687 |
return 0; |
| 688 |
} |
| 689 |
|
| 690 |
tmp = arch_to_object(spell->other_arch); |
| 691 |
if (tmp == NULL) |
| 692 |
return 0; |
| 693 |
|
| 694 |
mflags = get_map_flags(m, &tmp->map, x, y, &tmp->x, &tmp->y); |
| 695 |
if (mflags&P_OUT_OF_MAP) { |
| 696 |
object_free_drop_inventory(tmp); |
| 697 |
return 0; |
| 698 |
} |
| 699 |
|
| 700 |
if (spell->subtype == SP_BULLET) { |
| 701 |
|
| 702 |
tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 703 |
tmp->attacktype = spell->attacktype; |
| 704 |
if (spell->slaying) |
| 705 |
tmp->slaying = add_refcount(spell->slaying); |
| 706 |
|
| 707 |
tmp->range = 50; |
| 708 |
|
| 709 |
|
| 710 |
tmp->stats.hp = spell->duration+SP_level_duration_adjust(caster, spell); |
| 711 |
tmp->stats.maxhp = spell->range+SP_level_range_adjust(caster, spell); |
| 712 |
tmp->dam_modifier = spell->stats.food+SP_level_dam_adjust(caster, spell); |
| 713 |
|
| 714 |
tmp->direction = dir; |
| 715 |
object_update_turn_face(tmp); |
| 716 |
|
| 717 |
object_set_owner(tmp, op); |
| 718 |
} else { |
| 719 |
if (spell->subtype != SP_MAGIC_MISSILE && spell->subtype != SP_MOVING_BALL) |
| 720 |
LOG(llevError, "Unexpected object subtype %d in fire_arch_from_position for %s\n", spell->subtype, spell->name); |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
if (caster->type == PLAYER && OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) { |
| 728 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 729 |
"You can't cast the spell on top of a wall!"); |
| 730 |
object_free_drop_inventory(tmp); |
| 731 |
return 0; |
| 732 |
} |
| 733 |
|
| 734 |
tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 735 |
tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell); |
| 736 |
|
| 737 |
tmp->stats.food = tmp->duration; |
| 738 |
tmp->range = spell->range+SP_level_range_adjust(caster, spell); |
| 739 |
tmp->attacktype = spell->attacktype; |
| 740 |
if (object_get_owner(op) != NULL) |
| 741 |
object_copy_owner(tmp, op); |
| 742 |
else |
| 743 |
object_set_owner(tmp, op); |
| 744 |
tmp->level = caster_level(caster, spell); |
| 745 |
} |
| 746 |
|
| 747 |
tmp->direction = dir; |
| 748 |
set_spell_skill(op, caster, spell, tmp); |
| 749 |
|
| 750 |
if (spell->subtype == SP_BULLET) { |
| 751 |
if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) { |
| 752 |
if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) { |
| 753 |
object_free_drop_inventory(tmp); |
| 754 |
return 0; |
| 755 |
} |
| 756 |
tmp->direction = absdir(tmp->direction+4); |
| 757 |
x += DIRX(tmp); |
| 758 |
y += DIRY(tmp); |
| 759 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 760 |
if (mflags&P_OUT_OF_MAP) { |
| 761 |
object_free_drop_inventory(tmp); |
| 762 |
return 0; |
| 763 |
} |
| 764 |
tmp->x = x; |
| 765 |
tmp->y = y; |
| 766 |
tmp->map = m; |
| 767 |
} |
| 768 |
|
| 769 |
tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y); |
| 770 |
if (tmp != NULL) |
| 771 |
check_bullet(tmp); |
| 772 |
} else { |
| 773 |
|
| 774 |
if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) { |
| 775 |
if (!tailor_god_spell(tmp, op)) |
| 776 |
return 0; |
| 777 |
} |
| 778 |
object_update_turn_face(tmp); |
| 779 |
|
| 780 |
tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y); |
| 781 |
if (tmp != NULL) |
| 782 |
ob_process(tmp); |
| 783 |
} |
| 784 |
|
| 785 |
return 1; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
void regenerate_rod(object *rod) { |
| 801 |
if (rod->stats.hp < rod->stats.maxhp) { |
| 802 |
rod->stats.hp += 1+rod->stats.maxhp/10; |
| 803 |
|
| 804 |
if (rod->stats.hp > rod->stats.maxhp) |
| 805 |
rod->stats.hp = rod->stats.maxhp; |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
void drain_rod_charge(object *rod) { |
| 816 |
rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
void drain_wand_charge(object *wand) { |
| 826 |
assert(wand->type == WAND); |
| 827 |
|
| 828 |
if (!(--wand->stats.food)) { |
| 829 |
object *tmp; |
| 830 |
if (wand->arch) { |
| 831 |
CLEAR_FLAG(wand, FLAG_ANIMATE); |
| 832 |
wand->face = wand->arch->clone.face; |
| 833 |
wand->speed = 0; |
| 834 |
object_update_speed(wand); |
| 835 |
} |
| 836 |
tmp = object_get_player_container(wand); |
| 837 |
if (tmp) |
| 838 |
esrv_update_item(UPD_ANIM, tmp, wand); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
object *find_target_for_friendly_spell(object *op, int dir) { |
| 853 |
object *tmp; |
| 854 |
mapstruct *m; |
| 855 |
int16_t x, y; |
| 856 |
int mflags; |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
if (op->type != PLAYER && op->type != RUNE) { |
| 863 |
tmp = object_get_owner(op); |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER)) |
| 868 |
tmp = op; |
| 869 |
} else { |
| 870 |
m = op->map; |
| 871 |
x = op->x+freearr_x[dir]; |
| 872 |
y = op->y+freearr_y[dir]; |
| 873 |
|
| 874 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 875 |
|
| 876 |
if (mflags&P_OUT_OF_MAP) |
| 877 |
tmp = NULL; |
| 878 |
else { |
| 879 |
for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) { |
| 880 |
if (tmp->type == PLAYER) |
| 881 |
break; |
| 882 |
} |
| 883 |
} |
| 884 |
} |
| 885 |
|
| 886 |
if (tmp == NULL) |
| 887 |
FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) { |
| 888 |
if (tmp->type == PLAYER) |
| 889 |
return tmp; |
| 890 |
|
| 891 |
if (tmp->type == TRANSPORT) { |
| 892 |
object *inv; |
| 893 |
|
| 894 |
for (inv = tmp->inv; inv; inv = inv->below) { |
| 895 |
if ((inv->type == PLAYER) && (op == inv)) |
| 896 |
return inv; |
| 897 |
} |
| 898 |
} |
| 899 |
} FOR_MAP_FINISH(); |
| 900 |
return tmp; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
int spell_find_dir(mapstruct *m, int x, int y, object *exclude) { |
| 926 |
int i; |
| 927 |
int16_t nx, ny; |
| 928 |
int owner_type = 0, mflags; |
| 929 |
object *tmp; |
| 930 |
mapstruct *mp; |
| 931 |
int dirs[SIZEOFFREE]; |
| 932 |
|
| 933 |
if (exclude != NULL) { |
| 934 |
exclude = HEAD(exclude); |
| 935 |
owner_type = exclude->type; |
| 936 |
} |
| 937 |
|
| 938 |
get_search_arr(dirs); |
| 939 |
for (i = 1; i < SIZEOFFREE; i++) { |
| 940 |
nx = x+freearr_x[dirs[i]]; |
| 941 |
ny = y+freearr_y[dirs[i]]; |
| 942 |
mp = m; |
| 943 |
mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny); |
| 944 |
if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW)) |
| 945 |
continue; |
| 946 |
|
| 947 |
for (tmp = GET_MAP_OB(mp, nx, ny); tmp != NULL; tmp = tmp->above) { |
| 948 |
object *head; |
| 949 |
|
| 950 |
head = HEAD(tmp); |
| 951 |
if ((owner_type != PLAYER || QUERY_FLAG(head, FLAG_MONSTER) || QUERY_FLAG(head, FLAG_GENERATOR) || (head->type == PLAYER && op_on_battleground(head, NULL, NULL, NULL))) |
| 952 |
&& (owner_type == PLAYER || head->type == PLAYER) |
| 953 |
&& head != exclude |
| 954 |
&& can_see_monsterP(m, x, y, dirs[i])) { |
| 955 |
return freedir[dirs[i]]; |
| 956 |
} |
| 957 |
} |
| 958 |
} |
| 959 |
return -1; |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
static int put_a_monster(object *op, const char *monstername) { |
| 978 |
object *tmp, *head = NULL, *prev = NULL; |
| 979 |
archetype *at; |
| 980 |
int dir; |
| 981 |
|
| 982 |
|
| 983 |
at = find_archetype(monstername); |
| 984 |
if (at == NULL) |
| 985 |
return 0; |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
dir = object_find_first_free_spot(&at->clone, op->map, op->x, op->y); |
| 992 |
if (dir != -1) { |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
while (at != NULL) { |
| 997 |
tmp = arch_to_object(at); |
| 998 |
tmp->x = op->x+freearr_x[dir]+at->clone.x; |
| 999 |
tmp->y = op->y+freearr_y[dir]+at->clone.y; |
| 1000 |
tmp->map = op->map; |
| 1001 |
if (head) { |
| 1002 |
tmp->head = head; |
| 1003 |
prev->more = tmp; |
| 1004 |
} |
| 1005 |
if (!head) |
| 1006 |
head = tmp; |
| 1007 |
prev = tmp; |
| 1008 |
at = at->more; |
| 1009 |
} |
| 1010 |
|
| 1011 |
if (head->randomitems) |
| 1012 |
create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
| 1013 |
|
| 1014 |
object_insert_in_map_at(head, op->map, op, 0, op->x, op->y); |
| 1015 |
|
| 1016 |
|
| 1017 |
tmp = create_archetype("burnout"); |
| 1018 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]); |
| 1019 |
return 1; |
| 1020 |
} else { |
| 1021 |
return 0; |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
int summon_hostile_monsters(object *op, int n, const char *monstername) { |
| 1044 |
int i, put = 0; |
| 1045 |
|
| 1046 |
for (i = 0; i < n; i++) |
| 1047 |
put += put_a_monster(op, monstername); |
| 1048 |
|
| 1049 |
return put; |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
void shuffle_attack(object *op, int change_face) { |
| 1078 |
int i; |
| 1079 |
|
| 1080 |
i = rndm(0, 21); |
| 1081 |
op->attacktype = ATTACKS[i].attacktype|AT_MAGIC; |
| 1082 |
if (change_face) { |
| 1083 |
SET_ANIMATION(op, ATTACKS[i].face); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
static void prayer_failure(object *op, int failure, int power) { |
| 1099 |
const char *godname; |
| 1100 |
object *tmp; |
| 1101 |
|
| 1102 |
godname = determine_god(op); |
| 1103 |
if (!strcmp(godname, "none")) |
| 1104 |
godname = "Your spirit"; |
| 1105 |
|
| 1106 |
if (failure <= -20 && failure > -40) { |
| 1107 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1108 |
"%s gives a sign to renew your faith.", |
| 1109 |
godname); |
| 1110 |
tmp = create_archetype(SPELL_WONDER); |
| 1111 |
cast_cone(op, op, 0, tmp); |
| 1112 |
object_free_drop_inventory(tmp); |
| 1113 |
} else if (failure <= -40 && failure > -60) { |
| 1114 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1115 |
"Your diety touches your mind!"); |
| 1116 |
confuse_living(op, op, 99); |
| 1117 |
} else if (failure <= -60 && failure > -150) { |
| 1118 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1119 |
"%s requires you to pray NOW. You comply, ignoring all else.", |
| 1120 |
godname); |
| 1121 |
|
| 1122 |
paralyze_living(op, 99); |
| 1123 |
} else if (failure <= -150) { |
| 1124 |
tmp = create_archetype(GOD_POWER); |
| 1125 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1126 |
"%s smites you!", |
| 1127 |
godname); |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
cast_magic_storm(op, tmp, power > 50 ? 50 : power); |
| 1134 |
} |
| 1135 |
} |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
void spell_failure(object *op, int failure, int power, object *skill) { |
| 1150 |
object *tmp; |
| 1151 |
|
| 1152 |
if (settings.spell_failure_effects == FALSE) |
| 1153 |
return; |
| 1154 |
|
| 1155 |
if (failure <= -20 && failure > -40) { |
| 1156 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1157 |
"Your spell causes an unexpected effect."); |
| 1158 |
tmp = create_archetype(SPELL_WONDER); |
| 1159 |
cast_cone(op, op, 0, tmp); |
| 1160 |
object_free_drop_inventory(tmp); |
| 1161 |
} else if (failure <= -40 && failure > -60) { |
| 1162 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1163 |
"Your magic recoils on you, making you confused!"); |
| 1164 |
confuse_living(op, op, 99); |
| 1165 |
} else if (failure <= -60 && failure > -80) { |
| 1166 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1167 |
"Your magic stuns you!"); |
| 1168 |
paralyze_living(op, 99); |
| 1169 |
} else if (failure <= -80) { |
| 1170 |
object *tmp; |
| 1171 |
|
| 1172 |
|
| 1173 |
if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) { |
| 1174 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1175 |
"The magic warps and you are turned inside out!"); |
| 1176 |
hit_player(op, 9998, op, AT_INTERNAL, 1); |
| 1177 |
} else { |
| 1178 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1179 |
"You lose control of the mana! The uncontrolled magic blasts you!"); |
| 1180 |
tmp = create_archetype(LOOSE_MANA); |
| 1181 |
tmp->level = skill->level; |
| 1182 |
|
| 1183 |
|
| 1184 |
tmp->range += isqrt(power); |
| 1185 |
|
| 1186 |
if (power > 25) |
| 1187 |
tmp->stats.dam = 25+isqrt(power); |
| 1188 |
else |
| 1189 |
tmp->stats.dam = power; |
| 1190 |
|
| 1191 |
tmp->stats.maxhp = tmp->count; |
| 1192 |
if (tmp->stats.maxhp == 0) |
| 1193 |
tmp->stats.maxhp = 1; |
| 1194 |
object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
static int can_be_transmuted_to_flower(object *op) { |
| 1208 |
if (op->invisible) |
| 1209 |
return 0; |
| 1210 |
|
| 1211 |
if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON) |
| 1212 |
return 1; |
| 1213 |
|
| 1214 |
return 0; |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
static void transmute_item_to_flower(object *op) { |
| 1230 |
object *force; |
| 1231 |
object *item; |
| 1232 |
object *flower; |
| 1233 |
object *first = NULL; |
| 1234 |
int count = 0; |
| 1235 |
char name[HUGE_BUF]; |
| 1236 |
|
| 1237 |
FOR_INV_PREPARE(op, item) |
| 1238 |
if (can_be_transmuted_to_flower(item)) { |
| 1239 |
if (!first) |
| 1240 |
first = item; |
| 1241 |
count++; |
| 1242 |
} |
| 1243 |
FOR_INV_FINISH(); |
| 1244 |
|
| 1245 |
if (count == 0) |
| 1246 |
return; |
| 1247 |
|
| 1248 |
count = rndm(0, count-1); |
| 1249 |
for (item = first; item; item = item->below) { |
| 1250 |
if (can_be_transmuted_to_flower(item)) { |
| 1251 |
count--; |
| 1252 |
if (count < 0) |
| 1253 |
break; |
| 1254 |
} |
| 1255 |
} |
| 1256 |
|
| 1257 |
if (!item) |
| 1258 |
return; |
| 1259 |
|
| 1260 |
force = create_archetype(FORCE_NAME); |
| 1261 |
force->duration = 100+rndm(0, 10)*100; |
| 1262 |
force->subtype = FORCE_TRANSFORMED_ITEM; |
| 1263 |
force->speed = 1; |
| 1264 |
object_update_speed(force); |
| 1265 |
|
| 1266 |
flower = create_archetype("flowers_permanent"); |
| 1267 |
|
| 1268 |
if (QUERY_FLAG(item, FLAG_APPLIED)) |
| 1269 |
apply_manual(op, item, AP_NOPRINT|AP_IGNORE_CURSE|AP_UNAPPLY); |
| 1270 |
object_remove(item); |
| 1271 |
flower->weight = item->nrof ? ((int32_t)item->nrof)*item->weight : item->weight; |
| 1272 |
item->weight = 0; |
| 1273 |
esrv_del_item(op->contr, item); |
| 1274 |
object_insert_in_ob(item, force); |
| 1275 |
|
| 1276 |
query_short_name(item, name, HUGE_BUF); |
| 1277 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1278 |
MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 1279 |
"Your %s turns to a flower!", |
| 1280 |
name); |
| 1281 |
|
| 1282 |
object_insert_in_ob(force, flower); |
| 1283 |
flower = object_insert_in_ob(flower, op); |
| 1284 |
esrv_send_item(op, flower); |
| 1285 |
} |
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
static void swap_random_stats(object *op) { |
| 1298 |
object *force; |
| 1299 |
int first, second; |
| 1300 |
|
| 1301 |
first = RANDOM()%NUM_STATS; |
| 1302 |
second = RANDOM()%(NUM_STATS-1); |
| 1303 |
if (second >= first) |
| 1304 |
second++; |
| 1305 |
|
| 1306 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1307 |
MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SPELL, |
| 1308 |
"You suddenly feel really weird!"); |
| 1309 |
|
| 1310 |
force = create_archetype(FORCE_NAME); |
| 1311 |
force->duration = 100+rndm(0, 10)*100; |
| 1312 |
force->speed = 1; |
| 1313 |
SET_FLAG(force, FLAG_APPLIED); |
| 1314 |
set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second)); |
| 1315 |
set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first)); |
| 1316 |
object_update_speed(force); |
| 1317 |
object_insert_in_ob(force, op); |
| 1318 |
change_abil(op, force); |
| 1319 |
fix_object(op); |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
static void handle_spell_confusion(object *op) { |
| 1333 |
switch (RANDOM()%2) { |
| 1334 |
case 0: |
| 1335 |
transmute_item_to_flower(op); |
| 1336 |
break; |
| 1337 |
|
| 1338 |
case 1: |
| 1339 |
swap_random_stats(op); |
| 1340 |
break; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
static int spell_consume_items(object *op, const object *spell_ob) { |
| 1352 |
sstring requirements; |
| 1353 |
char *copy; |
| 1354 |
char *ingredients[10]; |
| 1355 |
object *found[10]; |
| 1356 |
int count, i; |
| 1357 |
uint32_t nrof[10]; |
| 1358 |
char name_ob[MAX_BUF]; |
| 1359 |
const char *name2; |
| 1360 |
|
| 1361 |
if (op->type != PLAYER) |
| 1362 |
return 1; |
| 1363 |
|
| 1364 |
requirements = object_get_value(spell_ob, "casting_requirements"); |
| 1365 |
if (!requirements) |
| 1366 |
|
| 1367 |
return 1; |
| 1368 |
|
| 1369 |
|
| 1370 |
copy = strdup_local(requirements); |
| 1371 |
count = split_string(copy, ingredients, 10, ','); |
| 1372 |
|
| 1373 |
|
| 1374 |
for (i = 0; i < count; i++) { |
| 1375 |
nrof[i] = 0; |
| 1376 |
found[i] = NULL; |
| 1377 |
while (isdigit(*ingredients[i])) { |
| 1378 |
nrof[i] = 10*nrof[i]+(*(ingredients[i])-'0'); |
| 1379 |
ingredients[i]++; |
| 1380 |
} |
| 1381 |
if (nrof[i] == 0) |
| 1382 |
nrof[i] = 1; |
| 1383 |
while (*ingredients[i] == ' ') |
| 1384 |
ingredients[i]++; |
| 1385 |
|
| 1386 |
|
| 1387 |
FOR_INV_PREPARE(op, check) { |
| 1388 |
|
| 1389 |
if (check->title == NULL) |
| 1390 |
name2 = check->name; |
| 1391 |
else { |
| 1392 |
snprintf(name_ob, sizeof(name_ob), "%s %s", check->name, check->title); |
| 1393 |
name2 = name_ob; |
| 1394 |
} |
| 1395 |
|
| 1396 |
if (strcmp(name2, ingredients[i]) == 0) { |
| 1397 |
found[i] = check; |
| 1398 |
break; |
| 1399 |
} |
| 1400 |
} FOR_INV_FINISH(); |
| 1401 |
|
| 1402 |
if (found[i] == NULL) { |
| 1403 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1404 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1405 |
"Casting this spell requires %s, but you don't have any.", |
| 1406 |
ingredients[i]); |
| 1407 |
free(copy); |
| 1408 |
return 0; |
| 1409 |
} |
| 1410 |
|
| 1411 |
if (found[i]->nrof < nrof[i]) { |
| 1412 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1413 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1414 |
"Casting this spell requires %d %s, but you only have %d.", |
| 1415 |
nrof[i], found[i]->name_pl, found[i]->nrof); |
| 1416 |
free(copy); |
| 1417 |
return 0; |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
free(copy); |
| 1422 |
|
| 1423 |
|
| 1424 |
for (i = 0; i < count; i++) { |
| 1425 |
object_decrease_nrof(found[i], nrof[i]); |
| 1426 |
} |
| 1427 |
|
| 1428 |
|
| 1429 |
return 1; |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) { |
| 1468 |
const char *godname; |
| 1469 |
int success = 0, mflags, cast_level = 0; |
| 1470 |
rangetype old_shoottype; |
| 1471 |
object *skill = NULL; |
| 1472 |
int confusion_effect = 0; |
| 1473 |
float cost_multiplier = 1.0f; |
| 1474 |
|
| 1475 |
old_shoottype = op->contr ? op->contr->shoottype : range_none; |
| 1476 |
|
| 1477 |
if (!spell_ob) { |
| 1478 |
LOG(llevError, "cast_spell: null spell object passed\n"); |
| 1479 |
return 0; |
| 1480 |
} |
| 1481 |
godname = determine_god(op); |
| 1482 |
if (!strcmp(godname, "none")) |
| 1483 |
godname = "A random spirit"; |
| 1484 |
|
| 1485 |
|
| 1486 |
if (!caster) { |
| 1487 |
LOG(llevError, "cast_spell: null caster object passed\n"); |
| 1488 |
return 0; |
| 1489 |
} |
| 1490 |
if (spell_ob->anim_suffix) |
| 1491 |
apply_anim_suffix(caster, spell_ob->anim_suffix); |
| 1492 |
|
| 1493 |
|
| 1494 |
if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) { |
| 1495 |
if (rndm(0, 5) < 4) { |
| 1496 |
spell_ob = find_random_spell_in_ob(op, NULL); |
| 1497 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1498 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1499 |
"In your confused state, you're not sure of what you cast!"); |
| 1500 |
} else |
| 1501 |
|
| 1502 |
confusion_effect = 1; |
| 1503 |
} |
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) { |
| 1509 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1510 |
"That spell path is denied to you."); |
| 1511 |
return 0; |
| 1512 |
} |
| 1513 |
|
| 1514 |
|
| 1515 |
mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL); |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
if (spell_ob->type == SPELL |
| 1523 |
&& caster->type != POTION |
| 1524 |
&& !QUERY_FLAG(op, FLAG_WIZCAST) |
| 1525 |
&& (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE)) |
| 1526 |
&& !QUERY_FLAG(op, FLAG_MONSTER) |
| 1527 |
&& (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) { |
| 1528 |
if (op->type != PLAYER) |
| 1529 |
return 0; |
| 1530 |
|
| 1531 |
cast_create_obj(op, create_archetype(ARCH_SPELL_BLOCKED), 0); |
| 1532 |
|
| 1533 |
if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace) |
| 1534 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1535 |
"This ground is unholy! %s ignores you.", |
| 1536 |
godname); |
| 1537 |
else |
| 1538 |
switch (op->contr->shoottype) { |
| 1539 |
case range_magic: |
| 1540 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1541 |
"Something blocks your spellcasting."); |
| 1542 |
break; |
| 1543 |
|
| 1544 |
case range_misc: |
| 1545 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1546 |
"Something blocks the magic of your item."); |
| 1547 |
break; |
| 1548 |
case range_golem: |
| 1549 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1550 |
"Something blocks the magic of your scroll."); |
| 1551 |
break; |
| 1552 |
|
| 1553 |
default: |
| 1554 |
break; |
| 1555 |
} |
| 1556 |
return 0; |
| 1557 |
} |
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
if (op->type == PLAYER && op == caster) { |
| 1569 |
cast_level = caster_level(caster, spell_ob); |
| 1570 |
if (spell_ob->skill) { |
| 1571 |
skill = find_skill_by_name(op, spell_ob->skill); |
| 1572 |
if (!skill) { |
| 1573 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1574 |
MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING, |
| 1575 |
"You need the skill %s to cast %s.", |
| 1576 |
spell_ob->skill, spell_ob->name); |
| 1577 |
return 0; |
| 1578 |
} |
| 1579 |
if (min_casting_level(op, spell_ob) > cast_level && !QUERY_FLAG(op, FLAG_WIZ)) { |
| 1580 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1581 |
"You lack enough skill to cast that spell."); |
| 1582 |
return 0; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
if (!QUERY_FLAG(op, FLAG_WIZ)) { |
| 1589 |
if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) |
| 1590 |
&& SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) > op->stats.sp) { |
| 1591 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1592 |
"You don't have enough mana."); |
| 1593 |
return 0; |
| 1594 |
} |
| 1595 |
if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) |
| 1596 |
&& SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) > op->stats.grace) { |
| 1597 |
if (random_roll(0, op->stats.Wis-1, op, PREFER_HIGH)+op->stats.grace-10*SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)/op->stats.maxgrace > 0) { |
| 1598 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1599 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, |
| 1600 |
"%s grants your prayer, though you are unworthy.", |
| 1601 |
godname); |
| 1602 |
} else { |
| 1603 |
prayer_failure(op, op->stats.grace, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)-op->stats.grace); |
| 1604 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1605 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1606 |
"%s ignores your prayer.", |
| 1607 |
godname); |
| 1608 |
return 0; |
| 1609 |
} |
| 1610 |
} |
| 1611 |
|
| 1612 |
|
| 1613 |
if (spell_ob->stats.grace |
| 1614 |
&& random_roll(0, 99, op, PREFER_HIGH) < (get_cleric_chance(op->stats.Wis) * spell_ob->level/MAX(1, op->level))) { |
| 1615 |
play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell_ob, 0, "fumble"); |
| 1616 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1617 |
"You fumble the spell."); |
| 1618 |
if (settings.casting_time == TRUE) { |
| 1619 |
op->casting_time = -1; |
| 1620 |
} |
| 1621 |
op->stats.grace -= random_roll(1, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
| 1622 |
object *bungle = create_archetype(ARCH_SPELL_BUNGLE); |
| 1623 |
if (bungle->arch != NULL) { |
| 1624 |
cast_create_obj(op, bungle, 0); |
| 1625 |
} else { |
| 1626 |
LOG(llevError, "cast_spell: Could not create spell_bungle arch\n"); |
| 1627 |
} |
| 1628 |
return 0; |
| 1629 |
} else if (spell_ob->stats.sp) { |
| 1630 |
int failure = random_roll(0, 199, op, PREFER_HIGH)-op->contr->encumbrance+op->level-spell_ob->level+35; |
| 1631 |
|
| 1632 |
if (failure < 0) { |
| 1633 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1634 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1635 |
"You bungle the spell because you have too much heavy equipment in use."); |
| 1636 |
if (settings.spell_failure_effects == TRUE) |
| 1637 |
spell_failure(op, failure, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), skill); |
| 1638 |
op->contr->shoottype = old_shoottype; |
| 1639 |
op->stats.sp -= random_roll(0, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), op, PREFER_LOW); |
| 1640 |
object *bungle = create_archetype(ARCH_SPELL_BUNGLE); |
| 1641 |
if (bungle->arch != NULL) { |
| 1642 |
cast_create_obj(op, bungle, 0); |
| 1643 |
} else { |
| 1644 |
LOG(llevError, "cast_spell: Could not create spell_bungle arch\n"); |
| 1645 |
} |
| 1646 |
return 0; |
| 1647 |
} |
| 1648 |
} |
| 1649 |
|
| 1650 |
|
| 1651 |
if (!spell_consume_items(op, spell_ob)) |
| 1652 |
|
| 1653 |
return 0; |
| 1654 |
} |
| 1655 |
} |
| 1656 |
|
| 1657 |
if (caster == op && caster->type ==PLAYER && settings.casting_time == TRUE && spell_ob->type == SPELL) { |
| 1658 |
if (op->casting_time == -1) { |
| 1659 |
op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob); |
| 1660 |
op->spell = spell_ob; |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
if (stringarg) { |
| 1666 |
op->spellarg = strdup_local(stringarg); |
| 1667 |
} else |
| 1668 |
op->spellarg = NULL; |
| 1669 |
return 0; |
| 1670 |
} else if (op->casting_time != 0) { |
| 1671 |
if (op->type == PLAYER) |
| 1672 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, |
| 1673 |
"You are casting!"); |
| 1674 |
return 0; |
| 1675 |
} else { |
| 1676 |
op->casting_time = -1; |
| 1677 |
spell_ob = op->spell; |
| 1678 |
stringarg = op->spellarg; |
| 1679 |
} |
| 1680 |
} else { |
| 1681 |
if (!QUERY_FLAG(caster, FLAG_WIZ)) { |
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
if (caster == op && caster->type != FIREWALL) { |
| 1691 |
op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed); |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
if ((spell_ob->casting_time > 0) |
| 1696 |
&& op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed)) |
| 1697 |
op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed); |
| 1698 |
} else if (caster->type == WAND |
| 1699 |
|| caster->type == ROD |
| 1700 |
|| caster->type == POTION |
| 1701 |
|| caster->type == SCROLL) { |
| 1702 |
op->speed_left -= 2*FABS(op->speed); |
| 1703 |
} |
| 1704 |
} |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
if (op != caster && !skill && caster->skill && !QUERY_FLAG(op, FLAG_MONSTER)) { |
| 1712 |
skill = find_skill_by_name(op, caster->skill); |
| 1713 |
if (!skill) { |
| 1714 |
char name[MAX_BUF]; |
| 1715 |
|
| 1716 |
query_name(caster, name, MAX_BUF); |
| 1717 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1718 |
MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING, |
| 1719 |
"You lack the skill %s to use the %s", |
| 1720 |
caster->skill, name); |
| 1721 |
return 0; |
| 1722 |
} |
| 1723 |
change_skill(op, skill, 0); |
| 1724 |
} |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
if (caster->type == RUNE) { |
| 1731 |
object *owner = object_get_owner(caster); |
| 1732 |
|
| 1733 |
if (owner) |
| 1734 |
skill = find_skill_by_name(owner, caster->skill); |
| 1735 |
} |
| 1736 |
|
| 1737 |
if (confusion_effect) { |
| 1738 |
|
| 1739 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1740 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1741 |
"In your confused state, you can't control the magic!"); |
| 1742 |
handle_spell_confusion(op); |
| 1743 |
|
| 1744 |
|
| 1745 |
if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) { |
| 1746 |
op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE); |
| 1747 |
op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA); |
| 1748 |
} |
| 1749 |
|
| 1750 |
return 0; |
| 1751 |
} |
| 1752 |
|
| 1753 |
play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name); |
| 1754 |
|
| 1755 |
switch (spell_ob->subtype) { |
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
case SP_RAISE_DEAD: |
| 1760 |
success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg); |
| 1761 |
break; |
| 1762 |
|
| 1763 |
case SP_RUNE: |
| 1764 |
success = write_rune(op, caster, spell_ob, dir, stringarg); |
| 1765 |
break; |
| 1766 |
|
| 1767 |
case SP_MAKE_MARK: |
| 1768 |
success = write_mark(op, spell_ob, stringarg); |
| 1769 |
break; |
| 1770 |
|
| 1771 |
case SP_BOLT: |
| 1772 |
success = fire_bolt(op, caster, dir, spell_ob); |
| 1773 |
break; |
| 1774 |
|
| 1775 |
case SP_BULLET: |
| 1776 |
success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob); |
| 1777 |
break; |
| 1778 |
|
| 1779 |
case SP_CONE: |
| 1780 |
success = cast_cone(op, caster, dir, spell_ob); |
| 1781 |
break; |
| 1782 |
|
| 1783 |
case SP_BOMB: |
| 1784 |
success = create_bomb(op, caster, dir, spell_ob); |
| 1785 |
break; |
| 1786 |
|
| 1787 |
case SP_WONDER: |
| 1788 |
success = cast_wonder(op, caster, dir, spell_ob); |
| 1789 |
break; |
| 1790 |
|
| 1791 |
case SP_SMITE: |
| 1792 |
success = cast_smite_spell(op, caster, dir, spell_ob); |
| 1793 |
break; |
| 1794 |
|
| 1795 |
case SP_MAGIC_MISSILE: |
| 1796 |
success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob); |
| 1797 |
break; |
| 1798 |
|
| 1799 |
case SP_SUMMON_GOLEM: |
| 1800 |
success = pets_summon_golem(op, caster, dir, spell_ob); |
| 1801 |
if (success || op->contr == NULL) |
| 1802 |
old_shoottype = range_golem; |
| 1803 |
else |
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
old_shoottype = op->contr->shoottype; |
| 1809 |
break; |
| 1810 |
|
| 1811 |
case SP_DIMENSION_DOOR: |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
success = dimension_door(op, caster, spell_ob, dir); |
| 1816 |
break; |
| 1817 |
|
| 1818 |
case SP_MAGIC_MAPPING: |
| 1819 |
if (op->type == PLAYER) { |
| 1820 |
spell_effect(spell_ob, op->x, op->y, op->map, op); |
| 1821 |
draw_magic_map(op); |
| 1822 |
success = 1; |
| 1823 |
} else |
| 1824 |
success = 0; |
| 1825 |
break; |
| 1826 |
|
| 1827 |
case SP_MAGIC_WALL: |
| 1828 |
success = magic_wall(op, caster, dir, spell_ob); |
| 1829 |
break; |
| 1830 |
|
| 1831 |
case SP_DESTRUCTION: |
| 1832 |
success = cast_destruction(op, caster, spell_ob); |
| 1833 |
break; |
| 1834 |
|
| 1835 |
case SP_PERCEIVE_SELF: |
| 1836 |
success = perceive_self(op); |
| 1837 |
break; |
| 1838 |
|
| 1839 |
case SP_WORD_OF_RECALL: |
| 1840 |
success = cast_word_of_recall(op, caster, spell_ob); |
| 1841 |
break; |
| 1842 |
|
| 1843 |
case SP_INVISIBLE: |
| 1844 |
success = cast_invisible(op, caster, spell_ob); |
| 1845 |
break; |
| 1846 |
|
| 1847 |
case SP_PROBE: |
| 1848 |
if (op != caster) |
| 1849 |
cast_level = caster->level; |
| 1850 |
else |
| 1851 |
cast_level = skill != NULL ? skill->level : op->level; |
| 1852 |
success = probe(op, caster, spell_ob, dir, cast_level); |
| 1853 |
break; |
| 1854 |
|
| 1855 |
case SP_HEALING: |
| 1856 |
success = cast_heal(op, caster, spell_ob, dir); |
| 1857 |
break; |
| 1858 |
|
| 1859 |
case SP_CREATE_FOOD: |
| 1860 |
success = cast_create_food(op, caster, spell_ob, dir, stringarg); |
| 1861 |
break; |
| 1862 |
|
| 1863 |
case SP_EARTH_TO_DUST: |
| 1864 |
success = cast_earth_to_dust(op, caster, spell_ob); |
| 1865 |
break; |
| 1866 |
|
| 1867 |
case SP_CHANGE_ABILITY: |
| 1868 |
success = cast_change_ability(op, caster, spell_ob, dir, 0); |
| 1869 |
break; |
| 1870 |
|
| 1871 |
case SP_BLESS: |
| 1872 |
success = cast_bless(op, caster, spell_ob, dir); |
| 1873 |
break; |
| 1874 |
|
| 1875 |
case SP_CURSE: |
| 1876 |
success = cast_curse(op, caster, spell_ob, dir); |
| 1877 |
break; |
| 1878 |
|
| 1879 |
case SP_SUMMON_MONSTER: |
| 1880 |
success = pets_summon_object(op, caster, spell_ob, dir, stringarg); |
| 1881 |
if (!success) { |
| 1882 |
cost_multiplier = 0.0f; |
| 1883 |
} |
| 1884 |
break; |
| 1885 |
|
| 1886 |
case SP_CHARGING: |
| 1887 |
success = recharge(op, caster, spell_ob); |
| 1888 |
break; |
| 1889 |
|
| 1890 |
case SP_POLYMORPH: |
| 1891 |
#if 0 |
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1897 |
"The spell fizzles"); |
| 1898 |
success = 0; |
| 1899 |
#else |
| 1900 |
success = cast_polymorph(op, caster, spell_ob, dir); |
| 1901 |
#endif |
| 1902 |
break; |
| 1903 |
|
| 1904 |
case SP_ALCHEMY: |
| 1905 |
success = alchemy(op, caster, spell_ob); |
| 1906 |
break; |
| 1907 |
|
| 1908 |
case SP_REMOVE_CURSE: |
| 1909 |
success = remove_curse(op, caster, spell_ob); |
| 1910 |
break; |
| 1911 |
|
| 1912 |
case SP_IDENTIFY: |
| 1913 |
success = cast_identify(op, caster, spell_ob); |
| 1914 |
break; |
| 1915 |
|
| 1916 |
case SP_DETECTION: |
| 1917 |
success = cast_detection(op, caster, spell_ob); |
| 1918 |
break; |
| 1919 |
|
| 1920 |
case SP_MOOD_CHANGE: |
| 1921 |
success = mood_change(op, caster, spell_ob); |
| 1922 |
break; |
| 1923 |
|
| 1924 |
case SP_MOVING_BALL: |
| 1925 |
if (spell_ob->path_repelled |
| 1926 |
&& (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) { |
| 1927 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1928 |
"You lack the proper attunement to cast %s", |
| 1929 |
spell_ob->name); |
| 1930 |
success = 0; |
| 1931 |
} else |
| 1932 |
success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob); |
| 1933 |
break; |
| 1934 |
|
| 1935 |
case SP_SWARM: |
| 1936 |
success = fire_swarm(op, caster, spell_ob, dir); |
| 1937 |
break; |
| 1938 |
|
| 1939 |
case SP_CHANGE_MANA: |
| 1940 |
success = cast_transfer(op, caster, spell_ob, dir); |
| 1941 |
break; |
| 1942 |
|
| 1943 |
case SP_DISPEL_RUNE: |
| 1944 |
|
| 1945 |
success = dispel_rune(op, caster, spell_ob, skill, dir); |
| 1946 |
break; |
| 1947 |
|
| 1948 |
case SP_CREATE_MISSILE: |
| 1949 |
success = cast_create_missile(op, caster, spell_ob, dir, stringarg); |
| 1950 |
break; |
| 1951 |
|
| 1952 |
case SP_CONSECRATE: |
| 1953 |
success = cast_consecrate(op, caster, spell_ob); |
| 1954 |
break; |
| 1955 |
|
| 1956 |
case SP_ANIMATE_WEAPON: |
| 1957 |
success = animate_weapon(op, caster, spell_ob, dir); |
| 1958 |
old_shoottype = range_golem; |
| 1959 |
break; |
| 1960 |
|
| 1961 |
case SP_LIGHT: |
| 1962 |
success = cast_light(op, caster, spell_ob, dir); |
| 1963 |
break; |
| 1964 |
|
| 1965 |
case SP_CHANGE_MAP_LIGHT: |
| 1966 |
success = cast_change_map_lightlevel(op, caster, spell_ob); |
| 1967 |
break; |
| 1968 |
|
| 1969 |
case SP_FAERY_FIRE: |
| 1970 |
success = cast_destruction(op, caster, spell_ob); |
| 1971 |
break; |
| 1972 |
|
| 1973 |
case SP_CAUSE_DISEASE: |
| 1974 |
success = cast_cause_disease(op, caster, spell_ob, dir); |
| 1975 |
break; |
| 1976 |
|
| 1977 |
case SP_AURA: |
| 1978 |
success = create_aura(op, caster, spell_ob); |
| 1979 |
break; |
| 1980 |
|
| 1981 |
case SP_TOWN_PORTAL: |
| 1982 |
success = cast_create_town_portal(op, caster, spell_ob, dir); |
| 1983 |
break; |
| 1984 |
|
| 1985 |
case SP_ITEM_CURSE_BLESS: |
| 1986 |
success = cast_item_curse_or_curse(op, caster, spell_ob); |
| 1987 |
break; |
| 1988 |
|
| 1989 |
case SP_ELEM_SHIELD: |
| 1990 |
success = create_aura(op, caster, spell_ob); |
| 1991 |
break; |
| 1992 |
|
| 1993 |
default: |
| 1994 |
LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); |
| 1995 |
} |
| 1996 |
|
| 1997 |
|
| 1998 |
if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) { |
| 1999 |
op->stats.grace -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)); |
| 2000 |
op->stats.sp -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA)); |
| 2001 |
} |
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
if (settings.casting_time == TRUE) { |
| 2006 |
free(stringarg); |
| 2007 |
stringarg = NULL; |
| 2008 |
} |
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
if (op->contr) |
| 2014 |
op->contr->shoottype = old_shoottype; |
| 2015 |
|
| 2016 |
return success; |
| 2017 |
} |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
void store_spell_expiry(object *spell) { |
| 2026 |
|
| 2027 |
char dur[10]; |
| 2028 |
int i = spell->duration/5; |
| 2029 |
|
| 2030 |
if (!i) |
| 2031 |
i = 1; |
| 2032 |
snprintf(dur, sizeof(dur), "%d", i); |
| 2033 |
object_set_value(spell, "spell_expiry_warn_1", dur, 1); |
| 2034 |
i = i/5; |
| 2035 |
if (i > 0) { |
| 2036 |
snprintf(dur, sizeof(dur), "%d", i); |
| 2037 |
object_set_value(spell, "spell_expiry_warn_2", dur, 1); |
| 2038 |
} |
| 2039 |
} |
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
void check_spell_expiry(object *spell) { |
| 2051 |
const char *key; |
| 2052 |
|
| 2053 |
if (!spell->env || !IS_PLAYER(spell->env)) |
| 2054 |
return; |
| 2055 |
|
| 2056 |
key = object_get_value(spell, "spell_expiry_warn_1"); |
| 2057 |
if (key != NULL) { |
| 2058 |
if (spell->duration == atoi(key)) { |
| 2059 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, spell->env, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, |
| 2060 |
"The effects of your %s are draining out.", spell->name); |
| 2061 |
return; |
| 2062 |
} |
| 2063 |
} |
| 2064 |
key = object_get_value(spell, "spell_expiry_warn_2"); |
| 2065 |
if (key != NULL) { |
| 2066 |
if (spell->duration == atoi(key)) { |
| 2067 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, spell->env, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, |
| 2068 |
"The effects of your %s are about to expire.", spell->name); |
| 2069 |
return; |
| 2070 |
} |
| 2071 |
} |
| 2072 |
} |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
void rod_adjust(object *rod) { |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
rod->value = rod->value*rod->inv->value*(rod->level+50)/(rod->inv->level+50); |
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
rod->stats.maxhp = MAX(rod->stats.maxhp, 2)*SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST); |
| 2096 |
rod->stats.hp = rod->stats.maxhp; |
| 2097 |
} |