| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#define _GNU_SOURCE |
| 20 |
|
| 21 |
#include "global.h" |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
#include <ctype.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include "living.h" |
| 29 |
#include "object.h" |
| 30 |
#include "shop.h" |
| 31 |
#include "sounds.h" |
| 32 |
#include "spells.h" |
| 33 |
#include "sproto.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
void cast_magic_storm(object *op, object *tmp, int lvl) { |
| 46 |
if (!tmp) |
| 47 |
return; |
| 48 |
tmp->level = op->level; |
| 49 |
tmp->range += lvl/5; |
| 50 |
tmp->duration += lvl/5; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
if (tmp->duration >= 40) |
| 58 |
tmp->duration = 40; |
| 59 |
tmp->stats.dam = lvl; |
| 60 |
tmp->stats.maxhp = tmp->count; |
| 61 |
if (tmp->stats.maxhp == 0) |
| 62 |
tmp->stats.maxhp = 1; |
| 63 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
int recharge(object *op, object *caster, object *spell_ob) { |
| 81 |
object *wand, *tmp; |
| 82 |
int ncharges; |
| 83 |
char name[MAX_BUF]; |
| 84 |
|
| 85 |
wand = find_marked_object(op); |
| 86 |
if (wand == NULL || wand->type != WAND) { |
| 87 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 88 |
"You need to mark the wand you want to recharge."); |
| 89 |
return 0; |
| 90 |
} |
| 91 |
if (!(random_roll(0, 3, op, PREFER_HIGH))) { |
| 92 |
query_name(wand, name, MAX_BUF); |
| 93 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 94 |
"The %s vibrates violently, then explodes!", |
| 95 |
name); |
| 96 |
play_sound_map(SOUND_TYPE_ITEM, wand, 0, "explode"); |
| 97 |
object_remove(wand); |
| 98 |
object_free(wand, 0); |
| 99 |
tmp = create_archetype("fireball"); |
| 100 |
tmp->stats.dam = (spell_ob->stats.dam+SP_level_dam_adjust(caster, spell_ob))/10; |
| 101 |
if (!tmp->stats.dam) |
| 102 |
tmp->stats.dam = 1; |
| 103 |
tmp->stats.hp = tmp->stats.dam/2; |
| 104 |
if (tmp->stats.hp < 2) |
| 105 |
tmp->stats.hp = 2; |
| 106 |
object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y); |
| 107 |
return 1; |
| 108 |
} |
| 109 |
|
| 110 |
ncharges = (spell_ob->stats.dam+SP_level_dam_adjust(caster, spell_ob)); |
| 111 |
if (wand->inv && wand->inv->level) |
| 112 |
ncharges /= wand->inv->level; |
| 113 |
else { |
| 114 |
query_name(wand, name, MAX_BUF); |
| 115 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 116 |
"Your %s is broken.", |
| 117 |
name); |
| 118 |
return 0; |
| 119 |
} |
| 120 |
if (!ncharges) |
| 121 |
ncharges = 1; |
| 122 |
|
| 123 |
wand->stats.food += ncharges; |
| 124 |
query_name(wand, name, MAX_BUF); |
| 125 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 126 |
"The %s glows with power.", |
| 127 |
name); |
| 128 |
|
| 129 |
if (wand->arch && QUERY_FLAG(&wand->arch->clone, FLAG_ANIMATE)) { |
| 130 |
SET_FLAG(wand, FLAG_ANIMATE); |
| 131 |
wand->speed = wand->arch->clone.speed; |
| 132 |
object_update_speed(wand); |
| 133 |
} |
| 134 |
return 1; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static void polymorph_living(object *op, int level) { |
| 159 |
archetype *at; |
| 160 |
int x = op->x, y = op->y, numat = 0, choice, friendly; |
| 161 |
mapstruct *map = op->map; |
| 162 |
object *owner; |
| 163 |
|
| 164 |
op = HEAD(op); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
if (op->level >= level*2 |
| 170 |
|| did_make_save(op, op->level, op->resist[ATNR_MAGIC]/10) |
| 171 |
|| (op->resist[ATNR_MAGIC] == 100)) |
| 172 |
return; |
| 173 |
|
| 174 |
object_remove(op); |
| 175 |
|
| 176 |
|
| 177 |
for (at = first_archetype; at != NULL; at = at->next) |
| 178 |
if ((QUERY_FLAG((&at->clone), FLAG_MONSTER) == QUERY_FLAG(op, FLAG_MONSTER)) |
| 179 |
&& (object_find_free_spot(&at->clone, map, x, y, 0, SIZEOFFREE) != -1)) { |
| 180 |
numat++; |
| 181 |
} |
| 182 |
if (!numat) { |
| 183 |
object_insert_in_map_at(op, map, NULL, 0, x, y); |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
choice = rndm(0, numat-1); |
| 189 |
for (at = first_archetype; at != NULL; at = at->next) |
| 190 |
if ((QUERY_FLAG((&at->clone), FLAG_MONSTER) == QUERY_FLAG(op, FLAG_MONSTER)) && (object_find_free_spot(&at->clone, map, x, y, 0, SIZEOFFREE) != -1)) { |
| 191 |
if (!choice) |
| 192 |
break; |
| 193 |
else |
| 194 |
choice--; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
FOR_INV_PREPARE(op, tmp) { |
| 202 |
if (QUERY_FLAG(tmp, FLAG_APPLIED)) |
| 203 |
apply_manual(op, tmp, 0); |
| 204 |
if (tmp->type == SPELL) { |
| 205 |
object_remove(tmp); |
| 206 |
object_free(tmp, 0); |
| 207 |
} |
| 208 |
} FOR_INV_FINISH(); |
| 209 |
|
| 210 |
|
| 211 |
owner = object_get_owner(op); |
| 212 |
friendly = QUERY_FLAG(op, FLAG_FRIENDLY); |
| 213 |
if (friendly) |
| 214 |
remove_friendly_object(op); |
| 215 |
|
| 216 |
object_copy(&(at->clone), op); |
| 217 |
if (owner != NULL) |
| 218 |
object_set_owner(op, owner); |
| 219 |
if (friendly) { |
| 220 |
SET_FLAG(op, FLAG_FRIENDLY); |
| 221 |
op->attack_movement = PETMOVE; |
| 222 |
add_friendly_object(op); |
| 223 |
} else |
| 224 |
CLEAR_FLAG(op, FLAG_FRIENDLY); |
| 225 |
|
| 226 |
|
| 227 |
if ((op = object_insert_in_map_at(op, map, owner, 0, x, y)) == NULL) |
| 228 |
return; |
| 229 |
|
| 230 |
if (HAS_RANDOM_ITEMS(op)) |
| 231 |
create_treasure(op->randomitems, op, GT_INVISIBLE, map->difficulty, 0); |
| 232 |
|
| 233 |
|
| 234 |
monster_check_apply_all(op); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
static void polymorph_melt(object *who, object *op) { |
| 250 |
|
| 251 |
char name[MAX_BUF]; |
| 252 |
|
| 253 |
query_name(op, name, MAX_BUF); |
| 254 |
if (op->nrof > 1) |
| 255 |
draw_ext_info_format(NDI_GREY, 0, who, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 256 |
"The %s glow red, melt and evaporate!", |
| 257 |
name); |
| 258 |
else |
| 259 |
draw_ext_info_format(NDI_GREY, 0, who, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 260 |
"The %s glows red, melts and evaporates!", |
| 261 |
name); |
| 262 |
play_sound_map(SOUND_TYPE_ITEM, op, 0, "evaporate"); |
| 263 |
object_remove(op); |
| 264 |
object_free(op, 0); |
| 265 |
return; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
static void polymorph_item(object *who, object *op, int level) { |
| 278 |
archetype *at; |
| 279 |
int max_value, difficulty, tries = 0, choice, charges = op->stats.food, numat = 0; |
| 280 |
object *new_ob; |
| 281 |
mapstruct *m; |
| 282 |
int16_t x, y; |
| 283 |
|
| 284 |
|
| 285 |
max_value = op->value*2; |
| 286 |
if (max_value > 2000*(level/10)) |
| 287 |
max_value = 2000*(level/10)+(max_value-2000*(level/10))/3; |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 294 |
if (at->clone.type == op->type |
| 295 |
&& !at->clone.invisible |
| 296 |
&& at->clone.value > 0 |
| 297 |
&& at->clone.value < max_value |
| 298 |
&& !QUERY_FLAG(&at->clone, FLAG_NO_DROP) |
| 299 |
&& !QUERY_FLAG(&at->clone, FLAG_STARTEQUIP)) |
| 300 |
numat++; |
| 301 |
} |
| 302 |
|
| 303 |
if (!numat) |
| 304 |
return; |
| 305 |
|
| 306 |
difficulty = op->magic*5; |
| 307 |
if (difficulty < 0) |
| 308 |
difficulty = 0; |
| 309 |
new_ob = object_new(); |
| 310 |
do { |
| 311 |
choice = rndm(0, numat-1); |
| 312 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 313 |
if (at->clone.type == op->type |
| 314 |
&& !at->clone.invisible |
| 315 |
&& at->clone.value > 0 |
| 316 |
&& at->clone.value < max_value |
| 317 |
&& !QUERY_FLAG(&at->clone, FLAG_NO_DROP) |
| 318 |
&& !QUERY_FLAG(&at->clone, FLAG_STARTEQUIP)) { |
| 319 |
if (!choice) |
| 320 |
break; |
| 321 |
else |
| 322 |
choice--; |
| 323 |
} |
| 324 |
} |
| 325 |
object_copy(&(at->clone), new_ob); |
| 326 |
fix_generated_item(new_ob, op, difficulty, FABS(op->magic), GT_ENVIRONMENT); |
| 327 |
++tries; |
| 328 |
} while (new_ob->value > max_value && tries < 10); |
| 329 |
if (new_ob->invisible) { |
| 330 |
LOG(llevError, "polymorph_item: fix_generated_object made %s invisible?!\n", new_ob->name); |
| 331 |
object_free(new_ob, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
if (tries == 10) { |
| 337 |
polymorph_melt(who, op); |
| 338 |
object_free(new_ob, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 339 |
return; |
| 340 |
} |
| 341 |
|
| 342 |
if (op->nrof && new_ob->nrof) { |
| 343 |
new_ob->nrof = op->nrof; |
| 344 |
|
| 345 |
if (new_ob->nrof > 2) |
| 346 |
new_ob->nrof -= rndm(0, op->nrof/2-1); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
if (charges && op->type != RING && op->type != FOOD) |
| 353 |
op->stats.food = charges; |
| 354 |
|
| 355 |
x = op->x; |
| 356 |
y = op->y; |
| 357 |
m = op->map; |
| 358 |
object_remove(op); |
| 359 |
object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
object_insert_in_map_at(new_ob, m, new_ob, INS_NO_MERGE|INS_NO_WALK_ON, x, y); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
void polymorph(object *op, object *who, int level) { |
| 378 |
int tmp; |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
if (op->type == PLAYER || QUERY_FLAG(op, FLAG_GENERATOR)) |
| 383 |
return; |
| 384 |
|
| 385 |
if (QUERY_FLAG(op, FLAG_MONSTER)) { |
| 386 |
polymorph_living(op, level); |
| 387 |
return; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
if (QUERY_FLAG(op, FLAG_ALIVE)) |
| 393 |
return; |
| 394 |
|
| 395 |
|
| 396 |
if (FABS(op->speed) > 0.001 && !QUERY_FLAG(op, FLAG_ANIMATE)) |
| 397 |
return; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
if (op->type == 0 |
| 404 |
|| op->arch == NULL |
| 405 |
|| QUERY_FLAG(op, FLAG_NO_PICK) |
| 406 |
|| op->move_block |
| 407 |
|| op->type == TREASURE) |
| 408 |
return; |
| 409 |
|
| 410 |
tmp = rndm(0, 7); |
| 411 |
if (tmp) |
| 412 |
polymorph_item(who, op, level); |
| 413 |
else |
| 414 |
polymorph_melt(who, op); |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir) { |
| 432 |
object *tmp; |
| 433 |
int range, mflags, maxrange, level; |
| 434 |
mapstruct *m; |
| 435 |
|
| 436 |
if (dir == 0) |
| 437 |
return 0; |
| 438 |
|
| 439 |
maxrange = spell_ob->range+SP_level_range_adjust(caster, spell_ob); |
| 440 |
level = caster_level(caster, spell_ob); |
| 441 |
for (range = 1; range < maxrange; range++) { |
| 442 |
int16_t x = op->x+freearr_x[dir]*range, y = op->y+freearr_y[dir]*range; |
| 443 |
object *image; |
| 444 |
|
| 445 |
m = op->map; |
| 446 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 447 |
|
| 448 |
if (mflags&(P_NO_MAGIC|P_OUT_OF_MAP)) |
| 449 |
break; |
| 450 |
|
| 451 |
if (GET_MAP_MOVE_BLOCK(m, x, y)&MOVE_FLY_LOW) |
| 452 |
break; |
| 453 |
|
| 454 |
|
| 455 |
for (tmp = GET_MAP_OB(m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above) |
| 456 |
; |
| 457 |
|
| 458 |
|
| 459 |
FOR_OB_AND_BELOW_PREPARE(tmp) { |
| 460 |
|
| 461 |
if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
| 462 |
break; |
| 463 |
polymorph(tmp, op, level); |
| 464 |
} FOR_OB_AND_BELOW_FINISH(); |
| 465 |
image = arch_to_object(spell_ob->other_arch); |
| 466 |
image->stats.food = 5; |
| 467 |
image->speed_left = 0.1; |
| 468 |
object_insert_in_map_at(image, m, op, 0, x, y); |
| 469 |
} |
| 470 |
return 1; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg) { |
| 500 |
int missile_plus = 0, bonus_plus = 0; |
| 501 |
const char *missile_name; |
| 502 |
object *tmp, *missile; |
| 503 |
tag_t tag; |
| 504 |
|
| 505 |
tmp = object_find_by_type_applied(op, BOW); |
| 506 |
missile_name = tmp != NULL ? tmp->race : "arrow"; |
| 507 |
|
| 508 |
missile_plus = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 509 |
|
| 510 |
if (!strcmp(missile_name, "arrows")) |
| 511 |
missile_name = "arrow"; |
| 512 |
else if (!strcmp(missile_name, "crossbow bolts")) |
| 513 |
missile_name = "bolt"; |
| 514 |
|
| 515 |
|
| 516 |
if ( stringarg && strncmp(stringarg,"of ",3)==0 ) stringarg +=3; |
| 517 |
if ( stringarg && strncmp(stringarg,"bolt",4)==0 ) { |
| 518 |
missile_name = "bolt"; |
| 519 |
stringarg += 4; |
| 520 |
while ( isalpha(*stringarg) ) ++stringarg; |
| 521 |
while ( *stringarg==' ' ) ++stringarg; |
| 522 |
} |
| 523 |
if ( stringarg && strncmp(stringarg,"arrow",5)==0 ) { |
| 524 |
missile_name = "arrow"; |
| 525 |
stringarg += 5; |
| 526 |
while ( isalpha(*stringarg) ) ++stringarg; |
| 527 |
while ( *stringarg==' ' ) ++stringarg; |
| 528 |
} |
| 529 |
|
| 530 |
if (find_archetype(missile_name) == NULL) { |
| 531 |
LOG(llevDebug, "Cast create_missile: could not find archetype %s\n", missile_name); |
| 532 |
return 0; |
| 533 |
} |
| 534 |
missile = create_archetype(missile_name); |
| 535 |
|
| 536 |
if ( stringarg && strncmp(stringarg,"of ",3)==0 ) stringarg +=3; |
| 537 |
if (stringarg) { |
| 538 |
|
| 539 |
if (isalpha(*stringarg)) { |
| 540 |
artifact *al = find_artifactlist(missile->type)->items; |
| 541 |
|
| 542 |
for (; al != NULL; al = al->next) |
| 543 |
if (!strcasecmp(al->item->name, stringarg)) |
| 544 |
break; |
| 545 |
|
| 546 |
if (!al) { |
| 547 |
object_free(missile, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 548 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 549 |
"No such object %ss of %s", |
| 550 |
missile_name, stringarg); |
| 551 |
return 0; |
| 552 |
} |
| 553 |
if (al->item->slaying) { |
| 554 |
object_free(missile, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 555 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 556 |
"You are not allowed to create %ss of %s", |
| 557 |
missile_name, stringarg); |
| 558 |
return 0; |
| 559 |
} |
| 560 |
give_artifact_abilities(missile, al->item); |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
bonus_plus = 1+(al->item->value/5); |
| 566 |
missile_plus = 0; |
| 567 |
} else if (atoi(stringarg) < missile_plus) |
| 568 |
missile_plus = atoi(stringarg); |
| 569 |
} |
| 570 |
if (missile_plus > 4) |
| 571 |
missile_plus = 4; |
| 572 |
else if (missile_plus < -4) |
| 573 |
missile_plus = -4; |
| 574 |
|
| 575 |
missile->nrof = spell->duration+SP_level_duration_adjust(caster, spell); |
| 576 |
if (missile->nrof <= (uint32_t)3 * (missile_plus + bonus_plus)) { |
| 577 |
object_free(missile, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 578 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 579 |
"This item is too powerful for you to create!"); |
| 580 |
return 0; |
| 581 |
} |
| 582 |
missile->nrof -= 3*(missile_plus+bonus_plus); |
| 583 |
if (missile->nrof < 1) |
| 584 |
missile->nrof = 1; |
| 585 |
|
| 586 |
missile->magic = missile_plus; |
| 587 |
|
| 588 |
missile->value = 0; |
| 589 |
|
| 590 |
SET_FLAG(missile, FLAG_IDENTIFIED); |
| 591 |
tag = missile->count; |
| 592 |
|
| 593 |
if (!cast_create_obj(op, missile, dir) |
| 594 |
&& op->type == PLAYER |
| 595 |
&& !object_was_destroyed(missile, tag)) { |
| 596 |
pick_up(op, missile); |
| 597 |
} |
| 598 |
return 1; |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg) { |
| 623 |
int food_value; |
| 624 |
archetype *at = NULL; |
| 625 |
object *new_op; |
| 626 |
|
| 627 |
food_value = spell_ob->stats.food+50*SP_level_duration_adjust(caster, spell_ob); |
| 628 |
|
| 629 |
if (stringarg) { |
| 630 |
at = find_archetype_by_object_type_name(FOOD, stringarg); |
| 631 |
if (at == NULL) |
| 632 |
at = find_archetype_by_object_type_name(DRINK, stringarg); |
| 633 |
if (at == NULL || at->clone.stats.food > food_value) |
| 634 |
stringarg = NULL; |
| 635 |
} |
| 636 |
|
| 637 |
if (!stringarg) { |
| 638 |
archetype *at_tmp; |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
for (at_tmp = first_archetype; at_tmp != NULL; at_tmp = at_tmp->next) { |
| 649 |
if (at_tmp->clone.type == FOOD || at_tmp->clone.type == DRINK) { |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
if (at_tmp->clone.stats.food <= food_value |
| 655 |
&& (!at || at_tmp->clone.stats.food > at->clone.stats.food)) |
| 656 |
at = at_tmp; |
| 657 |
} |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
if (!at) { |
| 664 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 665 |
"You don't have enough experience to create any food."); |
| 666 |
return 0; |
| 667 |
} |
| 668 |
|
| 669 |
food_value /= at->clone.stats.food; |
| 670 |
new_op = object_new(); |
| 671 |
object_copy(&at->clone, new_op); |
| 672 |
new_op->nrof = food_value; |
| 673 |
|
| 674 |
new_op->value = 0; |
| 675 |
if (new_op->nrof < 1) |
| 676 |
new_op->nrof = 1; |
| 677 |
|
| 678 |
cast_create_obj(op, new_op, dir); |
| 679 |
return 1; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
int probe(object *op, object *caster, object *spell_ob, int dir, int level) { |
| 701 |
int r, mflags, maxrange; |
| 702 |
mapstruct *m; |
| 703 |
|
| 704 |
if (!dir) { |
| 705 |
examine_monster(op, op, level); |
| 706 |
return 1; |
| 707 |
} |
| 708 |
maxrange = spell_ob->range+SP_level_range_adjust(caster, spell_ob); |
| 709 |
for (r = 1; r < maxrange; r++) { |
| 710 |
int16_t x = op->x+r*freearr_x[dir], y = op->y+r*freearr_y[dir]; |
| 711 |
|
| 712 |
m = op->map; |
| 713 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 714 |
|
| 715 |
if (mflags&P_OUT_OF_MAP) |
| 716 |
break; |
| 717 |
|
| 718 |
if (!QUERY_FLAG(op, FLAG_WIZCAST) && (mflags&P_NO_MAGIC)) { |
| 719 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 720 |
"Something blocks your magic."); |
| 721 |
return 0; |
| 722 |
} |
| 723 |
if (mflags&P_IS_ALIVE) { |
| 724 |
FOR_MAP_PREPARE(m, x, y, tmp) |
| 725 |
if (CAN_PROBE(tmp)) { |
| 726 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 727 |
"You detect something."); |
| 728 |
examine_monster(op, HEAD(tmp), level); |
| 729 |
return 1; |
| 730 |
} |
| 731 |
FOR_MAP_FINISH(); |
| 732 |
} |
| 733 |
} |
| 734 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 735 |
"You detect nothing."); |
| 736 |
return 1; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
int makes_invisible_to(object *pl, object *mon) { |
| 758 |
if (!pl->invisible) |
| 759 |
return 0; |
| 760 |
if (pl->type == PLAYER) { |
| 761 |
|
| 762 |
if (!pl->contr->invis_race) { |
| 763 |
if (QUERY_FLAG(mon, FLAG_UNDEAD)) |
| 764 |
return 0; |
| 765 |
return 1; |
| 766 |
} |
| 767 |
|
| 768 |
if (!strcmp(pl->contr->invis_race, "undead") && is_true_undead(mon)) |
| 769 |
return 1; |
| 770 |
|
| 771 |
if (!mon->race) |
| 772 |
return 0; |
| 773 |
if (strstr(mon->race, pl->contr->invis_race)) |
| 774 |
return 1; |
| 775 |
|
| 776 |
return 0; |
| 777 |
} else { |
| 778 |
|
| 779 |
return 1; |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
int cast_invisible(object *op, object *caster, object *spell_ob) { |
| 805 |
object *tmp; |
| 806 |
|
| 807 |
if (op->invisible > 1000) { |
| 808 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 809 |
"You can not extend the duration of your invisibility any further"); |
| 810 |
return 0; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
op->invisible += spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 817 |
|
| 818 |
if (op->invisible > 1000) |
| 819 |
op->invisible = 1000; |
| 820 |
|
| 821 |
if (op->type == PLAYER) { |
| 822 |
if (op->contr->invis_race) |
| 823 |
FREE_AND_CLEAR_STR(op->contr->invis_race); |
| 824 |
if (spell_ob->race) |
| 825 |
op->contr->invis_race = add_refcount(spell_ob->race); |
| 826 |
if (QUERY_FLAG(spell_ob, FLAG_MAKE_INVIS)) |
| 827 |
op->contr->tmp_invis = 0; |
| 828 |
else |
| 829 |
op->contr->tmp_invis = 1; |
| 830 |
|
| 831 |
op->contr->hidden = 0; |
| 832 |
} |
| 833 |
if (makes_invisible_to(op, op)) |
| 834 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 835 |
"You can't see your hands!"); |
| 836 |
else |
| 837 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 838 |
"You feel more transparent!"); |
| 839 |
|
| 840 |
object_update(op, UP_OBJ_FACE); |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
for (tmp = active_objects; tmp != NULL; tmp = tmp->active_next) |
| 846 |
if (tmp->enemy == op) |
| 847 |
object_set_enemy(tmp, NULL); |
| 848 |
return 1; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
int cast_earth_to_dust(object *op, object *caster, object *spell_ob) { |
| 866 |
int range, i, j, mflags; |
| 867 |
int16_t sx, sy; |
| 868 |
mapstruct *m; |
| 869 |
|
| 870 |
if (op->type != PLAYER) |
| 871 |
return 0; |
| 872 |
|
| 873 |
range = spell_ob->range+SP_level_range_adjust(caster, spell_ob); |
| 874 |
|
| 875 |
for (i = -range; i < range; i++) |
| 876 |
for (j = -range; j < range; j++) { |
| 877 |
sx = op->x+i; |
| 878 |
sy = op->y+j; |
| 879 |
m = op->map; |
| 880 |
mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
| 881 |
|
| 882 |
if (mflags&P_OUT_OF_MAP) |
| 883 |
continue; |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
if (GET_MAP_MOVE_BLOCK(m, sx, sy)) { |
| 891 |
FOR_MAP_PREPARE(m, sx, sy, tmp) |
| 892 |
if (tmp && QUERY_FLAG(tmp, FLAG_TEAR_DOWN)) |
| 893 |
hit_player(tmp, 9998, op, AT_PHYSICAL, 0); |
| 894 |
FOR_MAP_FINISH(); |
| 895 |
} |
| 896 |
} |
| 897 |
return 1; |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
int cast_word_of_recall(object *op, object *caster, object *spell_ob) { |
| 917 |
object *dummy; |
| 918 |
int time; |
| 919 |
|
| 920 |
if (op->type != PLAYER) |
| 921 |
return 0; |
| 922 |
|
| 923 |
if (object_find_by_type_subtype(op, SPELL_EFFECT, SP_WORD_OF_RECALL)) { |
| 924 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 925 |
"You feel a force starting to build up inside you."); |
| 926 |
return 1; |
| 927 |
} |
| 928 |
|
| 929 |
dummy = create_archetype(FORCE_NAME); |
| 930 |
if (dummy == NULL) { |
| 931 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 932 |
"Oops, program error!"); |
| 933 |
LOG(llevError, "cast_word_of_recall: create_archetype(force) failed!\n"); |
| 934 |
return 0; |
| 935 |
} |
| 936 |
time = spell_ob->duration-SP_level_duration_adjust(caster, spell_ob); |
| 937 |
if (time < 1) |
| 938 |
time = 1; |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
dummy->speed = 0.002; |
| 945 |
object_update_speed(dummy); |
| 946 |
dummy->speed_left = -dummy->speed*time; |
| 947 |
dummy->type = SPELL_EFFECT; |
| 948 |
dummy->subtype = SP_WORD_OF_RECALL; |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
EXIT_PATH(dummy) = add_string(op->contr->savebed_map); |
| 954 |
EXIT_X(dummy) = op->contr->bed_x; |
| 955 |
EXIT_Y(dummy) = op->contr->bed_y; |
| 956 |
|
| 957 |
(void)object_insert_in_ob(dummy, op); |
| 958 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 959 |
"You feel a force starting to build up inside you."); |
| 960 |
return 1; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
int cast_wonder(object *op, object *caster, int dir, object *spell_ob) { |
| 979 |
object *newspell; |
| 980 |
|
| 981 |
if (!rndm(0, 3)) |
| 982 |
return cast_cone(op, caster, dir, spell_ob); |
| 983 |
|
| 984 |
if (spell_ob->randomitems) { |
| 985 |
newspell = generate_treasure(spell_ob->randomitems, caster->level); |
| 986 |
if (!newspell) { |
| 987 |
LOG(llevError, "cast_wonder: Unable to get a spell!\n"); |
| 988 |
return 0; |
| 989 |
} |
| 990 |
if (newspell->type != SPELL) { |
| 991 |
LOG(llevError, "cast_wonder: spell returned is not a spell (%d, %s)!\n", newspell->type, newspell->name); |
| 992 |
return 0; |
| 993 |
} |
| 994 |
|
| 995 |
if (newspell->subtype == SP_WONDER) { |
| 996 |
LOG(llevError, "cast_wonder: spell returned is another wonder spell!\n"); |
| 997 |
return 0; |
| 998 |
} |
| 999 |
return cast_spell(op, caster, dir, newspell, NULL); |
| 1000 |
} |
| 1001 |
return 1; |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
int perceive_self(object *op) { |
| 1013 |
char *cp, buf[MAX_BUF]; |
| 1014 |
archetype *at = find_archetype(ARCH_DEPLETION); |
| 1015 |
if (at == NULL) { |
| 1016 |
return 1; |
| 1017 |
} |
| 1018 |
object *tmp; |
| 1019 |
const object *god; |
| 1020 |
int i; |
| 1021 |
StringBuffer *immunity; |
| 1022 |
|
| 1023 |
god = find_god(determine_god(op)); |
| 1024 |
if (god) |
| 1025 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1026 |
"You worship %s", |
| 1027 |
god->name); |
| 1028 |
else |
| 1029 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1030 |
"You worship no god"); |
| 1031 |
|
| 1032 |
tmp = arch_present_in_ob(at, op); |
| 1033 |
|
| 1034 |
cp = stringbuffer_finish(describe_item(op, op, 0, NULL)); |
| 1035 |
|
| 1036 |
if (*cp == '\0' && tmp == NULL) |
| 1037 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1038 |
"You feel very mundane"); |
| 1039 |
else { |
| 1040 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1041 |
"You have:"); |
| 1042 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1043 |
cp); |
| 1044 |
if (tmp != NULL) { |
| 1045 |
for (i = 0; i < NUM_STATS; i++) { |
| 1046 |
if (get_attr_value(&tmp->stats, i) < 0) { |
| 1047 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1048 |
"Your %s is depleted by %d", |
| 1049 |
statname[i], -(get_attr_value(&tmp->stats, i))); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} |
| 1053 |
} |
| 1054 |
free(cp); |
| 1055 |
|
| 1056 |
if (op->glow_radius > 0) |
| 1057 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1058 |
"You glow in the dark."); |
| 1059 |
|
| 1060 |
immunity = NULL; |
| 1061 |
for (tmp = op->inv; tmp; tmp = tmp->below) { |
| 1062 |
if (tmp->type == SIGN) { |
| 1063 |
if (immunity == NULL) { |
| 1064 |
immunity = stringbuffer_new(); |
| 1065 |
stringbuffer_append_string(immunity, "You have been exposed to: "); |
| 1066 |
} else { |
| 1067 |
stringbuffer_append_string(immunity, ", "); |
| 1068 |
} |
| 1069 |
stringbuffer_append_string(immunity, tmp->name); |
| 1070 |
if (tmp->level > 100) |
| 1071 |
stringbuffer_append_string(immunity, " (full immunity)"); |
| 1072 |
else if (tmp->level > 70) |
| 1073 |
stringbuffer_append_string(immunity, " (high immunity)"); |
| 1074 |
else if (tmp->level > 20) |
| 1075 |
stringbuffer_append_string(immunity, " (partial immunity)"); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
if (immunity != NULL) { |
| 1080 |
cp = stringbuffer_finish(immunity); |
| 1081 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, cp); |
| 1082 |
free(cp); |
| 1083 |
} |
| 1084 |
|
| 1085 |
if (is_dragon_pl(op)) { |
| 1086 |
|
| 1087 |
tmp = object_find_by_type_and_arch_name(op, FORCE, "dragon_ability_force"); |
| 1088 |
if (tmp != NULL) { |
| 1089 |
StringBuffer *levels = NULL; |
| 1090 |
int i; |
| 1091 |
|
| 1092 |
if (tmp->stats.exp == 0) { |
| 1093 |
snprintf(buf, sizeof(buf), "Your metabolism isn't focused on anything."); |
| 1094 |
} else { |
| 1095 |
snprintf(buf, sizeof(buf), "Your metabolism is focused on %s.", change_resist_msg[tmp->stats.exp]); |
| 1096 |
} |
| 1097 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, |
| 1098 |
buf); |
| 1099 |
|
| 1100 |
for (i = 0; i < NROFATTACKS; i++) { |
| 1101 |
if (atnr_is_dragon_enabled(i) && tmp->resist[i] > 0) { |
| 1102 |
if (levels == NULL) { |
| 1103 |
levels = stringbuffer_new(); |
| 1104 |
stringbuffer_append_string(levels, "Ability levels:\n"); |
| 1105 |
} |
| 1106 |
stringbuffer_append_printf(levels, "- %s: %d\n", change_resist_msg[i], tmp->resist[i]); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
|
| 1110 |
if (levels != NULL) { |
| 1111 |
cp = stringbuffer_finish(levels); |
| 1112 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_PERCEIVE_SELF, cp); |
| 1113 |
free(cp); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
} |
| 1117 |
return 1; |
| 1118 |
} |
| 1119 |
|
| 1120 |
static object* town_portal_find_force(object* op, object* spell) { |
| 1121 |
object *dummy, *force; |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
dummy = arch_to_object(spell->other_arch); |
| 1127 |
if (dummy == NULL) { |
| 1128 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1129 |
"Oops, program error!"); |
| 1130 |
LOG(llevError, "object_new failed (force in cast_create_town_portal for %s!\n", op->name); |
| 1131 |
return NULL; |
| 1132 |
} |
| 1133 |
|
| 1134 |
force = check_inv_recursive(op, dummy); |
| 1135 |
if (force == NULL) { |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
free_string(dummy->name); |
| 1142 |
dummy->name = add_string(op->map->path); |
| 1143 |
EXIT_X(dummy) = op->x; |
| 1144 |
EXIT_Y(dummy) = op->y; |
| 1145 |
dummy->weapontype = op->map->last_reset_time; |
| 1146 |
object_insert_in_ob(dummy, op); |
| 1147 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 1148 |
"You fix this place in your mind and feel that you " |
| 1149 |
"can come here from anywhere."); |
| 1150 |
} else { |
| 1151 |
object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1152 |
} |
| 1153 |
return force; |
| 1154 |
} |
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
static int town_portal_destroy_existing(object* op, object* spell) { |
| 1160 |
object* dummy = create_archetype(spell->race); |
| 1161 |
object* old_force; |
| 1162 |
if (dummy == NULL) { |
| 1163 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1164 |
"Oops, program error!"); |
| 1165 |
LOG(llevError, "object_new failed (force) in cast_create_town_portal for %s!\n", op->name); |
| 1166 |
return 0; |
| 1167 |
} |
| 1168 |
archetype *perm_portal; |
| 1169 |
perm_portal = find_archetype(spell->slaying); |
| 1170 |
if (perm_portal == NULL) { |
| 1171 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1172 |
"Oops, program error!"); |
| 1173 |
return 0; |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
while ((old_force = check_inv_recursive(op, dummy))) { |
| 1184 |
int16_t exitx = EXIT_X(old_force); |
| 1185 |
int16_t exity = EXIT_Y(old_force); |
| 1186 |
LOG(llevDebug, "Trying to kill a portal in %s (%d,%d)\n", old_force->race, exitx, exity); |
| 1187 |
|
| 1188 |
mapstruct *exitmap; |
| 1189 |
if (!strncmp(old_force->race, settings.localdir, strlen(settings.localdir))) |
| 1190 |
exitmap = ready_map_name(old_force->race, MAP_PLAYER_UNIQUE); |
| 1191 |
else |
| 1192 |
exitmap = ready_map_name(old_force->race, 0); |
| 1193 |
|
| 1194 |
if (exitmap) { |
| 1195 |
object* tmp = map_find_by_archetype(exitmap, exitx, exity, perm_portal); |
| 1196 |
FOR_OB_AND_ABOVE_PREPARE(tmp) |
| 1197 |
if (tmp->name == old_force->name) { |
| 1198 |
object_remove(tmp); |
| 1199 |
object_free(tmp, 0); |
| 1200 |
break; |
| 1201 |
} |
| 1202 |
FOR_OB_AND_ABOVE_FINISH(); |
| 1203 |
|
| 1204 |
|
| 1205 |
archetype *arch = find_archetype("town_portal_open"); |
| 1206 |
if (arch != NULL) { |
| 1207 |
tmp = map_find_by_archetype(exitmap, exitx, exity, arch); |
| 1208 |
FOR_OB_AND_ABOVE_PREPARE(tmp) |
| 1209 |
if (tmp->name == old_force->name) { |
| 1210 |
object_remove(tmp); |
| 1211 |
object_free(tmp, FREE_OBJ_FREE_INVENTORY); |
| 1212 |
break; |
| 1213 |
} |
| 1214 |
FOR_OB_AND_ABOVE_FINISH(); |
| 1215 |
} |
| 1216 |
} |
| 1217 |
object_remove(old_force); |
| 1218 |
object_free(old_force, 0); |
| 1219 |
} |
| 1220 |
object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1221 |
return 0; |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
int cast_create_town_portal(object *op, object *caster, object *spell, int dir) { |
| 1254 |
object *dummy, *force, *tmp; |
| 1255 |
char portal_name [1024], portal_message [1024]; |
| 1256 |
mapstruct *exitmap; |
| 1257 |
int op_level, x, y; |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
if (!settings.create_home_portals) { |
| 1264 |
if (!strncmp(op->map->path, settings.localdir, strlen(settings.localdir))) { |
| 1265 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1266 |
"You can't cast that here."); |
| 1267 |
return 0; |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
if (op->contr && op->contr->transport) { |
| 1273 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1274 |
"You need to exit the transport to cast that."); |
| 1275 |
return 0; |
| 1276 |
} |
| 1277 |
|
| 1278 |
force = town_portal_find_force(op, spell); |
| 1279 |
if (force == NULL) { |
| 1280 |
return 1; |
| 1281 |
} |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
if (town_portal_destroy_existing(op, spell) != 0) { |
| 1299 |
return 1; |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
if (!strncmp(force->name, settings.localdir, strlen(settings.localdir))) |
| 1314 |
exitmap = ready_map_name(force->name, MAP_PLAYER_UNIQUE); |
| 1315 |
else |
| 1316 |
exitmap = ready_map_name(force->name, 0); |
| 1317 |
|
| 1318 |
|
| 1319 |
if (exitmap == NULL) { |
| 1320 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1321 |
"Something strange happens. You can't remember where to go!?"); |
| 1322 |
object_remove(force); |
| 1323 |
object_free(force, 0); |
| 1324 |
cast_create_obj(op, create_archetype(ARCH_PORTAL_FAILED), 0); |
| 1325 |
return 1; |
| 1326 |
} else if (exitmap->last_reset_time != force->weapontype) { |
| 1327 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1328 |
"The spell effect has expired."); |
| 1329 |
object_remove(force); |
| 1330 |
object_free(force, 0); |
| 1331 |
cast_create_obj(op, create_archetype(ARCH_PORTAL_FAILED), 0); |
| 1332 |
return 1; |
| 1333 |
} |
| 1334 |
|
| 1335 |
op_level = caster_level(caster, spell); |
| 1336 |
if (op_level < 15) |
| 1337 |
snprintf(portal_message, 1024, "The air moves around you and a huge smell of ammonia surrounds you as you pass through %s's tiny portal. Pouah!", op->name); |
| 1338 |
else if (op_level < 30) |
| 1339 |
snprintf(portal_message, 1024, "%s's portal smells of ozone. You do a lot of movements and finally pass through the small hole in the air.", op->name); |
| 1340 |
else if (op_level < 60) |
| 1341 |
snprintf(portal_message, 1024, "A shining door opens in the air in front of you, showing you the path to another place."); |
| 1342 |
else |
| 1343 |
snprintf(portal_message, 1024, "As you walk through %s's portal, flowers come out from the ground around you. You feel awed.", op->name); |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
snprintf(portal_name, 1024, "%s's portal to %s", op->name, force->name); |
| 1351 |
dummy = create_archetype(spell->slaying); |
| 1352 |
if (dummy == NULL) { |
| 1353 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1354 |
"Oops, program error!"); |
| 1355 |
LOG(llevError, "object_new failed (perm_magic_portal) in cast_create_town_portal for %s!\n", op->name); |
| 1356 |
return 0; |
| 1357 |
} |
| 1358 |
EXIT_PATH(dummy) = add_string(force->name); |
| 1359 |
EXIT_X(dummy) = EXIT_X(force); |
| 1360 |
EXIT_Y(dummy) = EXIT_Y(force); |
| 1361 |
FREE_AND_COPY(dummy->name, portal_name); |
| 1362 |
FREE_AND_COPY(dummy->name_pl, portal_name); |
| 1363 |
object_set_msg(dummy, portal_message); |
| 1364 |
dummy->race = add_string(op->name); |
| 1365 |
|
| 1366 |
|
| 1367 |
tmp = create_archetype("town_portal_open"); |
| 1368 |
FREE_AND_COPY(tmp->name, portal_name); |
| 1369 |
FREE_AND_COPY(tmp->name_pl, portal_name); |
| 1370 |
object_insert_in_ob(dummy, tmp); |
| 1371 |
|
| 1372 |
cast_create_obj(op, tmp, 0); |
| 1373 |
x = tmp->x; |
| 1374 |
y = tmp->y; |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
tmp = create_archetype(spell->race); |
| 1381 |
if (tmp == NULL) { |
| 1382 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1383 |
"Oops, program error!"); |
| 1384 |
LOG(llevError, "object_new failed (force) in cast_create_town_portal for %s!\n", op->name); |
| 1385 |
return 0; |
| 1386 |
} |
| 1387 |
tmp->race = add_string(op->map->path); |
| 1388 |
FREE_AND_COPY(tmp->name, portal_name); |
| 1389 |
EXIT_X(tmp) = x; |
| 1390 |
EXIT_Y(tmp) = y; |
| 1391 |
object_insert_in_ob(tmp, op); |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
snprintf(portal_name, 1024, "%s's portal to %s", op->name, op->map->path); |
| 1400 |
dummy = create_archetype(spell->slaying); |
| 1401 |
if (dummy == NULL) { |
| 1402 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1403 |
"Oops, program error!"); |
| 1404 |
LOG(llevError, "object_new failed (perm_magic_portal) in cast_create_town_portal for %s!\n", op->name); |
| 1405 |
return 0; |
| 1406 |
} |
| 1407 |
EXIT_PATH(dummy) = add_string(op->map->path); |
| 1408 |
EXIT_X(dummy) = op->x; |
| 1409 |
EXIT_Y(dummy) = op->y; |
| 1410 |
FREE_AND_COPY(dummy->name, portal_name); |
| 1411 |
FREE_AND_COPY(dummy->name_pl, portal_name); |
| 1412 |
object_set_msg(dummy, portal_message); |
| 1413 |
dummy->race = add_string(op->name); |
| 1414 |
|
| 1415 |
|
| 1416 |
tmp = create_archetype("town_portal_open"); |
| 1417 |
FREE_AND_COPY(tmp->name, portal_name); |
| 1418 |
FREE_AND_COPY(tmp->name_pl, portal_name); |
| 1419 |
object_insert_in_ob(dummy, tmp); |
| 1420 |
|
| 1421 |
object_insert_in_map_at(tmp, exitmap, op, 0, EXIT_X(force), EXIT_Y(force)); |
| 1422 |
x = tmp->x; |
| 1423 |
y = tmp->y; |
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
tmp = create_archetype(spell->race); |
| 1429 |
if (tmp == NULL) { |
| 1430 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1431 |
"Oops, program error!"); |
| 1432 |
LOG(llevError, "object_new failed (force) in cast_create_town_portal for %s!\n", op->name); |
| 1433 |
return 0; |
| 1434 |
} |
| 1435 |
tmp->race = add_string(force->name); |
| 1436 |
FREE_AND_COPY(tmp->name, portal_name); |
| 1437 |
EXIT_X(tmp) = x; |
| 1438 |
EXIT_Y(tmp) = y; |
| 1439 |
object_insert_in_ob(tmp, op); |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 1444 |
"You see air moving and showing you the way home."); |
| 1445 |
object_remove(force); |
| 1446 |
object_free(force, 0); |
| 1447 |
return 1; |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
int magic_wall(object *op, object *caster, int dir, object *spell_ob) { |
| 1469 |
object *tmp, *tmp2; |
| 1470 |
int i, posblocked, negblocked, maxrange; |
| 1471 |
int16_t x, y; |
| 1472 |
mapstruct *m; |
| 1473 |
const char *name; |
| 1474 |
archetype *at; |
| 1475 |
|
| 1476 |
if (!dir) { |
| 1477 |
dir = op->facing; |
| 1478 |
x = op->x; |
| 1479 |
y = op->y; |
| 1480 |
} else { |
| 1481 |
x = op->x+freearr_x[dir]; |
| 1482 |
y = op->y+freearr_y[dir]; |
| 1483 |
} |
| 1484 |
m = op->map; |
| 1485 |
|
| 1486 |
if ((spell_ob->move_block || x != op->x || y != op->y) |
| 1487 |
&& (get_map_flags(m, &m, x, y, &x, &y)&(P_OUT_OF_MAP|P_IS_ALIVE) |
| 1488 |
|| ((spell_ob->move_block&GET_MAP_MOVE_BLOCK(m, x, y)) == spell_ob->move_block))) { |
| 1489 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1490 |
"Something is in the way."); |
| 1491 |
return 0; |
| 1492 |
} |
| 1493 |
if (spell_ob->other_arch) { |
| 1494 |
tmp = arch_to_object(spell_ob->other_arch); |
| 1495 |
} else if (spell_ob->race) { |
| 1496 |
char buf1[MAX_BUF]; |
| 1497 |
|
| 1498 |
snprintf(buf1, sizeof(buf1), spell_ob->race, dir); |
| 1499 |
at = find_archetype(buf1); |
| 1500 |
if (!at) { |
| 1501 |
LOG(llevError, "summon_wall: Unable to find archetype %s\n", buf1); |
| 1502 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1503 |
"This spell is broken."); |
| 1504 |
return 0; |
| 1505 |
} |
| 1506 |
tmp = arch_to_object(at); |
| 1507 |
} else { |
| 1508 |
LOG(llevError, "magic_wall: spell %s lacks other_arch\n", spell_ob->name); |
| 1509 |
return 0; |
| 1510 |
} |
| 1511 |
|
| 1512 |
if (tmp->type == SPELL_EFFECT) { |
| 1513 |
tmp->attacktype = spell_ob->attacktype; |
| 1514 |
tmp->duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 1515 |
tmp->stats.dam = spell_ob->stats.dam+SP_level_dam_adjust(caster, spell_ob); |
| 1516 |
tmp->range = 0; |
| 1517 |
} else if (QUERY_FLAG(tmp, FLAG_ALIVE)) { |
| 1518 |
tmp->stats.hp = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 1519 |
tmp->stats.maxhp = tmp->stats.hp; |
| 1520 |
object_set_owner(tmp, op); |
| 1521 |
set_spell_skill(op, caster, spell_ob, tmp); |
| 1522 |
} |
| 1523 |
if (QUERY_FLAG(spell_ob, FLAG_IS_USED_UP) || QUERY_FLAG(tmp, FLAG_IS_USED_UP)) { |
| 1524 |
tmp->stats.food = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 1525 |
SET_FLAG(tmp, FLAG_IS_USED_UP); |
| 1526 |
} |
| 1527 |
if (QUERY_FLAG(spell_ob, FLAG_TEAR_DOWN)) { |
| 1528 |
tmp->stats.hp = spell_ob->stats.dam+SP_level_dam_adjust(caster, spell_ob); |
| 1529 |
tmp->stats.maxhp = tmp->stats.hp; |
| 1530 |
SET_FLAG(tmp, FLAG_TEAR_DOWN); |
| 1531 |
SET_FLAG(tmp, FLAG_ALIVE); |
| 1532 |
} |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
object_set_owner(tmp, op); |
| 1538 |
set_spell_skill(op, caster, spell_ob, tmp); |
| 1539 |
tmp->level = caster_level(caster, spell_ob)/2; |
| 1540 |
|
| 1541 |
name = tmp->name; |
| 1542 |
if ((tmp = object_insert_in_map_at(tmp, m, op, 0, x, y)) == NULL) { |
| 1543 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1544 |
"Something destroys your %s", |
| 1545 |
name); |
| 1546 |
return 0; |
| 1547 |
} |
| 1548 |
|
| 1549 |
if (tmp->other_arch && tmp->other_arch->clone.type == SPELL) |
| 1550 |
object_insert_in_ob(arch_to_object(tmp->other_arch), tmp); |
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
maxrange = spell_ob->range+SP_level_range_adjust(caster, spell_ob); |
| 1559 |
posblocked = 0; |
| 1560 |
negblocked = 0; |
| 1561 |
|
| 1562 |
for (i = 1; i <= maxrange; i++) { |
| 1563 |
int dir2; |
| 1564 |
|
| 1565 |
dir2 = (dir < 4) ? (dir+2) : dir-2; |
| 1566 |
|
| 1567 |
x = tmp->x+i*freearr_x[dir2]; |
| 1568 |
y = tmp->y+i*freearr_y[dir2]; |
| 1569 |
m = tmp->map; |
| 1570 |
|
| 1571 |
if (!(get_map_flags(m, &m, x, y, &x, &y)&(P_OUT_OF_MAP|P_IS_ALIVE)) |
| 1572 |
&& ((spell_ob->move_block&GET_MAP_MOVE_BLOCK(m, x, y)) != spell_ob->move_block) |
| 1573 |
&& !posblocked) { |
| 1574 |
tmp2 = object_new(); |
| 1575 |
object_copy(tmp, tmp2); |
| 1576 |
object_insert_in_map_at(tmp2, m, op, 0, x, y); |
| 1577 |
|
| 1578 |
if (tmp2->other_arch && tmp2->other_arch->clone.type == SPELL) |
| 1579 |
object_insert_in_ob(arch_to_object(tmp2->other_arch), tmp2); |
| 1580 |
} else |
| 1581 |
posblocked = 1; |
| 1582 |
|
| 1583 |
x = tmp->x-i*freearr_x[dir2]; |
| 1584 |
y = tmp->y-i*freearr_y[dir2]; |
| 1585 |
m = tmp->map; |
| 1586 |
|
| 1587 |
if (!(get_map_flags(m, &m, x, y, &x, &y)&(P_OUT_OF_MAP|P_IS_ALIVE)) |
| 1588 |
&& ((spell_ob->move_block&GET_MAP_MOVE_BLOCK(m, x, y)) != spell_ob->move_block) |
| 1589 |
&& !negblocked) { |
| 1590 |
tmp2 = object_new(); |
| 1591 |
object_copy(tmp, tmp2); |
| 1592 |
object_insert_in_map_at(tmp2, m, op, 0, x, y); |
| 1593 |
if (tmp2->other_arch && tmp2->other_arch->clone.type == SPELL) |
| 1594 |
object_insert_in_ob(arch_to_object(tmp2->other_arch), tmp2); |
| 1595 |
} else |
| 1596 |
negblocked = 1; |
| 1597 |
} |
| 1598 |
|
| 1599 |
if (QUERY_FLAG(tmp, FLAG_BLOCKSVIEW)) |
| 1600 |
update_all_los(op->map, op->x, op->y); |
| 1601 |
|
| 1602 |
return 1; |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
int dimension_door(object *op, object *caster, object *spob, int dir) { |
| 1622 |
uint32_t dist, maxdist; |
| 1623 |
int mflags; |
| 1624 |
mapstruct *m; |
| 1625 |
int16_t sx, sy; |
| 1626 |
|
| 1627 |
if (op->type != PLAYER) |
| 1628 |
return 0; |
| 1629 |
|
| 1630 |
if (!dir) { |
| 1631 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1632 |
"In what direction?"); |
| 1633 |
return 0; |
| 1634 |
} |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
maxdist = spob->range+SP_level_range_adjust(caster, spob); |
| 1640 |
|
| 1641 |
if (op->contr->count) { |
| 1642 |
if (op->contr->count > maxdist) { |
| 1643 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1644 |
"You can't dimension door that far!"); |
| 1645 |
return 0; |
| 1646 |
} |
| 1647 |
|
| 1648 |
for (dist = 0; dist < op->contr->count; dist++) { |
| 1649 |
mflags = get_map_flags(op->map, &m, |
| 1650 |
op->x+freearr_x[dir]*(dist+1), |
| 1651 |
op->y+freearr_y[dir]*(dist+1), |
| 1652 |
&sx, &sy); |
| 1653 |
|
| 1654 |
if (mflags&(P_NO_MAGIC|P_OUT_OF_MAP)) |
| 1655 |
break; |
| 1656 |
|
| 1657 |
if ((mflags&P_BLOCKSVIEW) |
| 1658 |
&& OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) |
| 1659 |
break; |
| 1660 |
} |
| 1661 |
|
| 1662 |
if (dist < op->contr->count) { |
| 1663 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1664 |
"Something blocks the magic of the spell."); |
| 1665 |
op->contr->count = 0; |
| 1666 |
return 0; |
| 1667 |
} |
| 1668 |
op->contr->count = 0; |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
mflags = get_map_flags(op->map, &m, op->x+freearr_x[dir]*dist, op->y+freearr_y[dir]*dist, |
| 1679 |
&sx, &sy); |
| 1680 |
if (mflags&P_IS_ALIVE || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) { |
| 1681 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1682 |
"You cast your spell, but nothing happens."); |
| 1683 |
return 1; |
| 1684 |
} |
| 1685 |
} else { |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
for (dist = 0; dist < maxdist; dist++) { |
| 1692 |
mflags = get_map_flags(op->map, &m, |
| 1693 |
op->x+freearr_x[dir]*(dist+1), |
| 1694 |
op->y+freearr_y[dir]*(dist+1), |
| 1695 |
&sx, &sy); |
| 1696 |
|
| 1697 |
if (mflags&(P_NO_MAGIC|P_OUT_OF_MAP)) |
| 1698 |
break; |
| 1699 |
|
| 1700 |
if ((mflags&P_BLOCKSVIEW) |
| 1701 |
&& OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) |
| 1702 |
break; |
| 1703 |
} |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
for (; dist > 0; dist--) { |
| 1709 |
if (get_map_flags(op->map, &m, op->x+freearr_x[dir]*dist, op->y+freearr_y[dir]*dist, &sx, &sy)&(P_OUT_OF_MAP|P_IS_ALIVE)) |
| 1710 |
continue; |
| 1711 |
|
| 1712 |
if (!OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) |
| 1713 |
break; |
| 1714 |
} |
| 1715 |
if (!dist) { |
| 1716 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1717 |
"Your spell failed!"); |
| 1718 |
return 0; |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
if (op->contr->transport && op->contr->transport->type == TRANSPORT) { |
| 1723 |
ob_apply(op->contr->transport, op, 0); |
| 1724 |
if (op->contr->transport) { |
| 1725 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1726 |
"Your spell failed!"); |
| 1727 |
return 0; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
|
| 1732 |
object_remove(op); |
| 1733 |
if ((op = object_insert_in_map_at(op, op->map, op, 0, op->x+freearr_x[dir]*dist, op->y+freearr_y[dir]*dist)) == NULL) |
| 1734 |
return 1; |
| 1735 |
|
| 1736 |
if (op->type == PLAYER) { |
| 1737 |
map_newmap_cmd(&op->contr->socket); |
| 1738 |
player_update_bg_music(op); |
| 1739 |
} |
| 1740 |
op->speed_left = -FABS(op->speed)*5; |
| 1741 |
return 1; |
| 1742 |
} |
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
int cast_heal(object *op, object *caster, object *spell, int dir) { |
| 1758 |
object *target; |
| 1759 |
archetype *at; |
| 1760 |
object *poison; |
| 1761 |
int heal = 0, success = 0; |
| 1762 |
|
| 1763 |
target = find_target_for_friendly_spell(op, dir); |
| 1764 |
|
| 1765 |
if (target == NULL) |
| 1766 |
return 0; |
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
heal = spell->stats.dam; |
| 1772 |
if (spell->stats.hp) |
| 1773 |
heal += random_roll(spell->stats.hp, 6, op, PREFER_HIGH)+spell->stats.hp; |
| 1774 |
|
| 1775 |
if (heal) { |
| 1776 |
if (target->stats.hp >= target->stats.maxhp) { |
| 1777 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1778 |
"You are already fully healed."); |
| 1779 |
} else { |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
if (heal > (target->stats.maxhp-target->stats.hp)) |
| 1785 |
heal = target->stats.maxhp-target->stats.hp; |
| 1786 |
target->stats.hp += heal; |
| 1787 |
|
| 1788 |
if (target->stats.hp >= target->stats.maxhp) { |
| 1789 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1790 |
"You feel just fine!"); |
| 1791 |
} else if (heal > 50) { |
| 1792 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1793 |
"Your wounds close!"); |
| 1794 |
} else if (heal > 25) { |
| 1795 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1796 |
"Your wounds mostly close."); |
| 1797 |
} else if (heal > 10) { |
| 1798 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1799 |
"Your wounds start to fade."); |
| 1800 |
} else { |
| 1801 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1802 |
"Your wounds start to close."); |
| 1803 |
} |
| 1804 |
success = 1; |
| 1805 |
} |
| 1806 |
} |
| 1807 |
if (spell->attacktype&AT_DISEASE) |
| 1808 |
if (cure_disease(target, op, caster && caster->type != PLAYER ? caster->skill : spell->skill)) |
| 1809 |
success = 1; |
| 1810 |
|
| 1811 |
if (spell->attacktype&AT_POISON) { |
| 1812 |
at = find_archetype("poisoning"); |
| 1813 |
if (at != NULL) { |
| 1814 |
poison = arch_present_in_ob(at, target); |
| 1815 |
if (poison) { |
| 1816 |
success = 1; |
| 1817 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1818 |
"Your body feels cleansed"); |
| 1819 |
poison->stats.food = 1; |
| 1820 |
} |
| 1821 |
} |
| 1822 |
} |
| 1823 |
if (spell->attacktype&AT_CONFUSION) { |
| 1824 |
poison = object_present_in_ob_by_name(FORCE, "confusion", target); |
| 1825 |
if (poison) { |
| 1826 |
success = 1; |
| 1827 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1828 |
"Your mind feels clearer"); |
| 1829 |
poison->duration = 1; |
| 1830 |
} |
| 1831 |
} |
| 1832 |
if (spell->attacktype&AT_BLIND) { |
| 1833 |
at = find_archetype("blindness"); |
| 1834 |
if (at != NULL) { |
| 1835 |
poison = arch_present_in_ob(at, target); |
| 1836 |
if (poison) { |
| 1837 |
success = 1; |
| 1838 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1839 |
"Your vision begins to return."); |
| 1840 |
poison->stats.food = 1; |
| 1841 |
} |
| 1842 |
} |
| 1843 |
} |
| 1844 |
if (spell->last_sp && target->stats.sp < target->stats.maxsp) { |
| 1845 |
target->stats.sp += spell->last_sp; |
| 1846 |
if (target->stats.sp > target->stats.maxsp) |
| 1847 |
target->stats.sp = target->stats.maxsp; |
| 1848 |
success = 1; |
| 1849 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1850 |
"Magical energies surge through your body!"); |
| 1851 |
} |
| 1852 |
if (spell->last_grace && target->stats.grace < target->stats.maxgrace) { |
| 1853 |
target->stats.grace += spell->last_grace; |
| 1854 |
if (target->stats.grace > target->stats.maxgrace) |
| 1855 |
target->stats.grace = target->stats.maxgrace; |
| 1856 |
success = 1; |
| 1857 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1858 |
"You feel redeemed with you god!"); |
| 1859 |
} |
| 1860 |
if (spell->stats.food && target->stats.food < MAX_FOOD) { |
| 1861 |
target->stats.food += spell->stats.food; |
| 1862 |
if (target->stats.food > MAX_FOOD) |
| 1863 |
target->stats.food = MAX_FOOD; |
| 1864 |
success = 1; |
| 1865 |
|
| 1866 |
draw_ext_info(NDI_UNIQUE, 0, target, MSG_TYPE_SPELL, MSG_TYPE_SPELL_HEAL, |
| 1867 |
"You feel your belly fill with food"); |
| 1868 |
} |
| 1869 |
|
| 1870 |
if (spell->other_arch != NULL && target->map != NULL) { |
| 1871 |
object_insert_in_map_at(arch_to_object(spell->other_arch), target->map, NULL, INS_ON_TOP, target->x, target->y); |
| 1872 |
} |
| 1873 |
|
| 1874 |
return success; |
| 1875 |
} |
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
static const char *const no_gain_msgs[NUM_STATS] = { |
| 1884 |
"You grow no stronger.", |
| 1885 |
"You grow no more agile.", |
| 1886 |
"You don't feel any healthier.", |
| 1887 |
"no wis", |
| 1888 |
"You are no easier to look at.", |
| 1889 |
"no int", |
| 1890 |
"no pow" |
| 1891 |
}; |
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent) { |
| 1913 |
object *tmp; |
| 1914 |
object *force = NULL; |
| 1915 |
int i; |
| 1916 |
|
| 1917 |
|
| 1918 |
if (dir != 0) { |
| 1919 |
tmp = find_target_for_friendly_spell(op, dir); |
| 1920 |
} else { |
| 1921 |
tmp = op; |
| 1922 |
} |
| 1923 |
|
| 1924 |
if (tmp == NULL) |
| 1925 |
return 0; |
| 1926 |
|
| 1927 |
|
| 1928 |
FOR_INV_PREPARE(tmp, tmp2) |
| 1929 |
if (tmp2->type == FORCE && tmp2->subtype == FORCE_CHANGE_ABILITY) { |
| 1930 |
if (tmp2->name == spell_ob->name) { |
| 1931 |
force = tmp2; |
| 1932 |
break; |
| 1933 |
} else if (spell_ob->race && spell_ob->race == tmp2->name) { |
| 1934 |
if (!silent) |
| 1935 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 1936 |
"You can not cast %s while %s is in effect", |
| 1937 |
spell_ob->name, tmp2->name_pl); |
| 1938 |
return 0; |
| 1939 |
} |
| 1940 |
} |
| 1941 |
FOR_INV_FINISH(); |
| 1942 |
if (force == NULL) { |
| 1943 |
force = create_archetype(FORCE_NAME); |
| 1944 |
force->subtype = FORCE_CHANGE_ABILITY; |
| 1945 |
free_string(force->name); |
| 1946 |
if (spell_ob->race) |
| 1947 |
force->name = add_refcount(spell_ob->race); |
| 1948 |
else |
| 1949 |
force->name = add_refcount(spell_ob->name); |
| 1950 |
free_string(force->name_pl); |
| 1951 |
force->name_pl = add_refcount(spell_ob->name); |
| 1952 |
} else { |
| 1953 |
int duration; |
| 1954 |
|
| 1955 |
duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 1956 |
if (duration > force->duration) { |
| 1957 |
force->duration = duration; |
| 1958 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 1959 |
"You recast the spell while in effect."); |
| 1960 |
|
| 1961 |
if (spell_ob->other_arch != NULL && tmp->map != NULL) { |
| 1962 |
object_insert_in_map_at(arch_to_object(spell_ob->other_arch), tmp->map, NULL, INS_ON_TOP, tmp->x, tmp->y); |
| 1963 |
} |
| 1964 |
|
| 1965 |
} else { |
| 1966 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 1967 |
"Recasting the spell had no effect."); |
| 1968 |
} |
| 1969 |
return 1; |
| 1970 |
} |
| 1971 |
force->duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 1972 |
if (op->type == PLAYER) |
| 1973 |
store_spell_expiry(force); |
| 1974 |
force->speed = 1.0; |
| 1975 |
force->speed_left = -1.0; |
| 1976 |
SET_FLAG(force, FLAG_APPLIED); |
| 1977 |
|
| 1978 |
|
| 1979 |
for (i = 0; i < NROFATTACKS; i++) { |
| 1980 |
if (spell_ob->resist[i]) { |
| 1981 |
force->resist[i] = spell_ob->resist[i]+SP_level_dam_adjust(caster, spell_ob); |
| 1982 |
if (force->resist[i] > 100) |
| 1983 |
force->resist[i] = 100; |
| 1984 |
} |
| 1985 |
} |
| 1986 |
if (spell_ob->stats.hp) |
| 1987 |
force->stats.hp = spell_ob->stats.hp+SP_level_dam_adjust(caster, spell_ob); |
| 1988 |
|
| 1989 |
if (tmp->type == PLAYER) { |
| 1990 |
|
| 1991 |
for (i = 0; i < NUM_STATS; i++) { |
| 1992 |
int8_t stat = get_attr_value(&spell_ob->stats, i), k, sm; |
| 1993 |
|
| 1994 |
if (stat) { |
| 1995 |
sm = 0; |
| 1996 |
for (k = 0; k < stat; k++) |
| 1997 |
sm += rndm(1, 3); |
| 1998 |
|
| 1999 |
if ((get_attr_value(&tmp->stats, i)+sm) > (15+5*stat)) { |
| 2000 |
sm = (15+5*stat)-get_attr_value(&tmp->stats, i); |
| 2001 |
if (sm < 0) |
| 2002 |
sm = 0; |
| 2003 |
} |
| 2004 |
set_attr_value(&force->stats, i, sm); |
| 2005 |
if (!sm) |
| 2006 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2007 |
no_gain_msgs[i]); |
| 2008 |
} |
| 2009 |
} |
| 2010 |
} |
| 2011 |
|
| 2012 |
force->move_type = spell_ob->move_type; |
| 2013 |
|
| 2014 |
if (QUERY_FLAG(spell_ob, FLAG_SEE_IN_DARK)) |
| 2015 |
SET_FLAG(force, FLAG_SEE_IN_DARK); |
| 2016 |
|
| 2017 |
if (QUERY_FLAG(spell_ob, FLAG_XRAYS)) |
| 2018 |
SET_FLAG(force, FLAG_XRAYS); |
| 2019 |
|
| 2020 |
|
| 2021 |
if (spell_ob->stats.exp) { |
| 2022 |
if (op->speed > 0.5) |
| 2023 |
force->stats.exp = (float)spell_ob->stats.exp/(op->speed+0.5); |
| 2024 |
else |
| 2025 |
force->stats.exp = spell_ob->stats.exp; |
| 2026 |
} |
| 2027 |
|
| 2028 |
force->stats.wc = spell_ob->stats.wc; |
| 2029 |
force->stats.ac = spell_ob->stats.ac; |
| 2030 |
force->attacktype = spell_ob->attacktype; |
| 2031 |
|
| 2032 |
SET_FLAG(tmp, FLAG_NO_FIX_PLAYER); |
| 2033 |
object_insert_in_ob(force, tmp); |
| 2034 |
CLEAR_FLAG(tmp, FLAG_NO_FIX_PLAYER); |
| 2035 |
change_abil(tmp, force); |
| 2036 |
|
| 2037 |
if (spell_ob->other_arch != NULL && tmp->map != NULL) { |
| 2038 |
object_insert_in_map_at(arch_to_object(spell_ob->other_arch), tmp->map, NULL, INS_ON_TOP, tmp->x, tmp->y); |
| 2039 |
} |
| 2040 |
|
| 2041 |
return 1; |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
int cast_bless(object *op, object *caster, object *spell_ob, int dir) { |
| 2061 |
int i; |
| 2062 |
const object *god = find_god(determine_god(op)); |
| 2063 |
object *force = NULL, *tmp; |
| 2064 |
|
| 2065 |
|
| 2066 |
if (dir != 0) { |
| 2067 |
tmp = find_target_for_friendly_spell(op, dir); |
| 2068 |
} else { |
| 2069 |
tmp = op; |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
FOR_INV_PREPARE(tmp, tmp2) |
| 2074 |
if (tmp2->type == FORCE && tmp2->subtype == FORCE_CHANGE_ABILITY) { |
| 2075 |
if (tmp2->name == spell_ob->name) { |
| 2076 |
force = tmp2; |
| 2077 |
break; |
| 2078 |
} else if (spell_ob->race && spell_ob->race == tmp2->name) { |
| 2079 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 2080 |
"You can not cast %s while %s is in effect", |
| 2081 |
spell_ob->name, tmp2->name_pl); |
| 2082 |
return 0; |
| 2083 |
} |
| 2084 |
} |
| 2085 |
FOR_INV_FINISH(); |
| 2086 |
if (force == NULL) { |
| 2087 |
force = create_archetype(FORCE_NAME); |
| 2088 |
force->subtype = FORCE_CHANGE_ABILITY; |
| 2089 |
free_string(force->name); |
| 2090 |
if (spell_ob->race) |
| 2091 |
force->name = add_refcount(spell_ob->race); |
| 2092 |
else |
| 2093 |
force->name = add_refcount(spell_ob->name); |
| 2094 |
free_string(force->name_pl); |
| 2095 |
force->name_pl = add_refcount(spell_ob->name); |
| 2096 |
} else { |
| 2097 |
int duration; |
| 2098 |
|
| 2099 |
duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 2100 |
if (duration > force->duration) { |
| 2101 |
force->duration = duration; |
| 2102 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 2103 |
"You recast the spell while in effect."); |
| 2104 |
} else { |
| 2105 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2106 |
"Recasting the spell had no effect."); |
| 2107 |
} |
| 2108 |
return 0; |
| 2109 |
} |
| 2110 |
force->duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 2111 |
force->speed = 1.0; |
| 2112 |
force->speed_left = -1.0; |
| 2113 |
|
| 2114 |
if (!god) { |
| 2115 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2116 |
"Your blessing seems empty."); |
| 2117 |
} else { |
| 2118 |
|
| 2119 |
const int16_t resist_max = spell_ob->resist[ATNR_GODPOWER]; |
| 2120 |
for (i = 0; i < NROFATTACKS; i++) { |
| 2121 |
if (god->resist[i] > 0) { |
| 2122 |
force->resist[i] = MIN(god->resist[i], resist_max); |
| 2123 |
} |
| 2124 |
} |
| 2125 |
|
| 2126 |
force->resist[ATNR_GODPOWER] = spell_ob->resist[ATNR_GODPOWER]; |
| 2127 |
|
| 2128 |
force->path_attuned |= god->path_attuned; |
| 2129 |
if (spell_ob->attacktype) { |
| 2130 |
force->attacktype |= god->attacktype|AT_PHYSICAL; |
| 2131 |
if (god->slaying) |
| 2132 |
force->slaying = add_string(god->slaying); |
| 2133 |
} |
| 2134 |
if (tmp != op) { |
| 2135 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 2136 |
"You bless %s.", |
| 2137 |
tmp->name); |
| 2138 |
draw_ext_info_format(NDI_UNIQUE, 0, tmp, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2139 |
"%s blessed you.", |
| 2140 |
op->name); |
| 2141 |
} else { |
| 2142 |
draw_ext_info_format(NDI_UNIQUE, 0, tmp, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2143 |
"You are blessed by %s!", |
| 2144 |
god->name); |
| 2145 |
} |
| 2146 |
} |
| 2147 |
force->stats.wc = spell_ob->stats.wc; |
| 2148 |
force->stats.ac = spell_ob->stats.ac; |
| 2149 |
|
| 2150 |
store_spell_expiry(force); |
| 2151 |
object_insert_in_ob(force, tmp); |
| 2152 |
SET_FLAG(force, FLAG_APPLIED); |
| 2153 |
change_abil(tmp, force); |
| 2154 |
|
| 2155 |
if (spell_ob->other_arch != NULL && tmp->map != NULL) { |
| 2156 |
object_insert_in_map_at(arch_to_object(spell_ob->other_arch), tmp->map, NULL, INS_ON_TOP, tmp->x, tmp->y); |
| 2157 |
} |
| 2158 |
return 1; |
| 2159 |
} |
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
#define SMALL_NUGGET "smallnugget" |
| 2186 |
#define LARGE_NUGGET "largenugget" |
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
static void alchemy_object(float value_adj, object *obj, int *small_nuggets, int *large_nuggets, int *weight) { |
| 2203 |
uint64_t value = price_base(obj); |
| 2204 |
uint64_t small_value, large_value; |
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
if (QUERY_FLAG(obj, FLAG_UNPAID)) |
| 2210 |
value = 0; |
| 2211 |
else |
| 2212 |
value *= value_adj; |
| 2213 |
|
| 2214 |
archetype *small_nugget_arch = find_archetype(SMALL_NUGGET); |
| 2215 |
if (small_nugget_arch == NULL) { |
| 2216 |
return; |
| 2217 |
} |
| 2218 |
small_value = price_base(&small_nugget_arch->clone); |
| 2219 |
archetype *large_nugget_arch = find_archetype(LARGE_NUGGET); |
| 2220 |
if (large_nugget_arch == NULL) { |
| 2221 |
return; |
| 2222 |
} |
| 2223 |
large_value = price_base(&large_nugget_arch->clone); |
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
if (value && (obj->type == MONEY || obj->type == GEM)) |
| 2230 |
value /= 2; |
| 2231 |
|
| 2232 |
if ((obj->value > 0) && rndm(0, 29)) { |
| 2233 |
int count; |
| 2234 |
|
| 2235 |
assert(large_value != 0 && small_value != 0); |
| 2236 |
count = value/large_value; |
| 2237 |
*large_nuggets += count; |
| 2238 |
value -= (uint64_t)count*large_value; |
| 2239 |
count = value/small_value; |
| 2240 |
*small_nuggets += count; |
| 2241 |
} |
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
if (*small_nuggets*small_value >= large_value) { |
| 2248 |
assert(small_value != 0); |
| 2249 |
(*large_nuggets)++; |
| 2250 |
*small_nuggets -= large_value/small_value; |
| 2251 |
if (*small_nuggets && large_value%small_value) |
| 2252 |
(*small_nuggets)--; |
| 2253 |
} |
| 2254 |
|
| 2255 |
if (weight != NULL) { |
| 2256 |
*weight += obj->weight; |
| 2257 |
} |
| 2258 |
|
| 2259 |
object_remove(obj); |
| 2260 |
object_free(obj, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 2261 |
} |
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
static void place_alchemy_objects(object *op, mapstruct *m, int small_nuggets, int large_nuggets, int x, int y) { |
| 2277 |
object *tmp; |
| 2278 |
int flag = 0; |
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
if (x == op->x && y == op->y && op->map == m) |
| 2284 |
flag = INS_BELOW_ORIGINATOR; |
| 2285 |
|
| 2286 |
if (small_nuggets) { |
| 2287 |
tmp = create_archetype(SMALL_NUGGET); |
| 2288 |
tmp-> nrof = small_nuggets; |
| 2289 |
object_insert_in_map_at(tmp, m, op, flag, x, y); |
| 2290 |
} |
| 2291 |
if (large_nuggets) { |
| 2292 |
tmp = create_archetype(LARGE_NUGGET); |
| 2293 |
tmp-> nrof = large_nuggets; |
| 2294 |
object_insert_in_map_at(tmp, m, op, flag, x, y); |
| 2295 |
} |
| 2296 |
} |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
int alchemy(object *op, object *caster, object *spell_ob) { |
| 2313 |
int x, y, weight = 0, weight_max, large_nuggets, small_nuggets, mflags; |
| 2314 |
int16_t nx, ny; |
| 2315 |
float value_adj; |
| 2316 |
mapstruct *mp; |
| 2317 |
|
| 2318 |
if (op->type != PLAYER) |
| 2319 |
return 0; |
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
weight_max = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 2326 |
weight_max *= 1000; |
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
value_adj = (SP_level_dam_adjust(caster, spell_ob)/100.00)+0.05; |
| 2333 |
|
| 2334 |
if (value_adj > 0.40) |
| 2335 |
value_adj = 0.40; |
| 2336 |
|
| 2337 |
for (y = op->y-1; y <= op->y+1; y++) { |
| 2338 |
for (x = op->x-1; x <= op->x+1; x++) { |
| 2339 |
nx = x; |
| 2340 |
ny = y; |
| 2341 |
|
| 2342 |
mp = op->map; |
| 2343 |
|
| 2344 |
mflags = get_map_flags(mp, &mp, nx, ny, &nx, &ny); |
| 2345 |
|
| 2346 |
if (mflags&(P_OUT_OF_MAP|P_NO_MAGIC)) |
| 2347 |
continue; |
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
if (GET_MAP_MOVE_BLOCK(mp, nx, ny)&MOVE_WALK) |
| 2354 |
continue; |
| 2355 |
|
| 2356 |
small_nuggets = 0; |
| 2357 |
large_nuggets = 0; |
| 2358 |
|
| 2359 |
FOR_MAP_PREPARE(mp, nx, ny, tmp) { |
| 2360 |
if (tmp->weight > 0 && !QUERY_FLAG(tmp, FLAG_NO_PICK) |
| 2361 |
&& !QUERY_FLAG(tmp, FLAG_ALIVE) |
| 2362 |
&& !QUERY_FLAG(tmp, FLAG_IS_CAULDRON)) { |
| 2363 |
if (tmp->inv) { |
| 2364 |
FOR_INV_PREPARE(tmp, tmp1) |
| 2365 |
if (tmp1->weight > 0 && !QUERY_FLAG(tmp1, FLAG_NO_PICK) |
| 2366 |
&& !QUERY_FLAG(tmp1, FLAG_ALIVE) |
| 2367 |
&& !QUERY_FLAG(tmp1, FLAG_IS_CAULDRON)) |
| 2368 |
alchemy_object(value_adj, tmp1, &small_nuggets, &large_nuggets, &weight); |
| 2369 |
FOR_INV_FINISH(); |
| 2370 |
} |
| 2371 |
alchemy_object(value_adj, tmp, &small_nuggets, &large_nuggets, &weight); |
| 2372 |
|
| 2373 |
if (weight > weight_max) { |
| 2374 |
place_alchemy_objects(op, mp, small_nuggets, large_nuggets, nx, ny); |
| 2375 |
return 1; |
| 2376 |
} |
| 2377 |
} |
| 2378 |
} FOR_MAP_FINISH(); |
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
place_alchemy_objects(op, mp, small_nuggets, large_nuggets, nx, ny); |
| 2385 |
} |
| 2386 |
} |
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
op->contr->socket.look_position = 0; |
| 2392 |
return 1; |
| 2393 |
} |
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
int remove_curse(object *op, object *caster, object *spell) { |
| 2411 |
int success = 0, was_one = 0; |
| 2412 |
|
| 2413 |
FOR_INV_PREPARE(op, tmp) |
| 2414 |
if (QUERY_FLAG(tmp, FLAG_APPLIED) |
| 2415 |
&& ((QUERY_FLAG(tmp, FLAG_CURSED) && QUERY_FLAG(spell, FLAG_CURSED)) |
| 2416 |
|| (QUERY_FLAG(tmp, FLAG_DAMNED) && QUERY_FLAG(spell, FLAG_DAMNED)))) { |
| 2417 |
was_one++; |
| 2418 |
if (tmp->level <= caster_level(caster, spell)) { |
| 2419 |
success++; |
| 2420 |
if (QUERY_FLAG(spell, FLAG_DAMNED)) |
| 2421 |
CLEAR_FLAG(tmp, FLAG_DAMNED); |
| 2422 |
|
| 2423 |
CLEAR_FLAG(tmp, FLAG_CURSED); |
| 2424 |
CLEAR_FLAG(tmp, FLAG_KNOWN_CURSED); |
| 2425 |
tmp->value = 0; |
| 2426 |
if (op->type == PLAYER) |
| 2427 |
esrv_update_item(UPD_FLAGS, op, tmp); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
FOR_INV_FINISH(); |
| 2431 |
|
| 2432 |
if (op->type == PLAYER) { |
| 2433 |
if (success) { |
| 2434 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 2435 |
"You feel like some of your items are looser now."); |
| 2436 |
} else { |
| 2437 |
if (was_one) |
| 2438 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2439 |
"You failed to remove the curse."); |
| 2440 |
else |
| 2441 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2442 |
"You are not using any cursed items."); |
| 2443 |
} |
| 2444 |
} |
| 2445 |
return success; |
| 2446 |
} |
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
int cast_item_curse_or_curse(object *op, object *caster, object *spell_ob) { |
| 2461 |
object *marked = find_marked_object(op); |
| 2462 |
char name[HUGE_BUF]; |
| 2463 |
|
| 2464 |
if (!marked) { |
| 2465 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2466 |
"You need to mark an item first!"); |
| 2467 |
return 0; |
| 2468 |
} |
| 2469 |
|
| 2470 |
if ((QUERY_FLAG(marked, FLAG_CURSED) && QUERY_FLAG(spell_ob, FLAG_CURSED)) |
| 2471 |
|| (QUERY_FLAG(marked, FLAG_BLESSED) && QUERY_FLAG(spell_ob, FLAG_BLESSED))) { |
| 2472 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2473 |
"The spell has no effect"); |
| 2474 |
return 0; |
| 2475 |
} |
| 2476 |
|
| 2477 |
query_short_name(marked, name, HUGE_BUF); |
| 2478 |
if (QUERY_FLAG(spell_ob, FLAG_CURSED)) { |
| 2479 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 2480 |
"Your %s emits a dark light for a few seconds.", name); |
| 2481 |
SET_FLAG(marked, FLAG_CURSED); |
| 2482 |
CLEAR_FLAG(marked, FLAG_KNOWN_CURSED); |
| 2483 |
CLEAR_FLAG(marked, FLAG_IDENTIFIED); |
| 2484 |
esrv_update_item(UPD_FLAGS, op, marked); |
| 2485 |
return 1; |
| 2486 |
} |
| 2487 |
|
| 2488 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 2489 |
"Your %s glows blue for a few seconds.", name); |
| 2490 |
SET_FLAG(marked, FLAG_BLESSED); |
| 2491 |
SET_FLAG(marked, FLAG_KNOWN_BLESSED); |
| 2492 |
SET_FLAG(marked, FLAG_STARTEQUIP); |
| 2493 |
esrv_update_item(UPD_FLAGS, op, marked); |
| 2494 |
return 1; |
| 2495 |
} |
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
int cast_identify(object *op, object *caster, object *spell) { |
| 2512 |
int success = 0, num_ident; |
| 2513 |
char desc[MAX_BUF]; |
| 2514 |
|
| 2515 |
num_ident = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 2516 |
|
| 2517 |
if (num_ident < 1) |
| 2518 |
num_ident = 1; |
| 2519 |
|
| 2520 |
FOR_INV_PREPARE(op, tmp) |
| 2521 |
if (!tmp->invisible && !is_identified(tmp)) { |
| 2522 |
tmp = identify(tmp); |
| 2523 |
if (op->type == PLAYER) { |
| 2524 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 2525 |
"You have %s.", |
| 2526 |
ob_describe(tmp, op, 1, desc, sizeof(desc))); |
| 2527 |
if (tmp->msg) { |
| 2528 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 2529 |
"The item has a story:\n%s", |
| 2530 |
tmp->msg); |
| 2531 |
} |
| 2532 |
} |
| 2533 |
num_ident--; |
| 2534 |
success = 1; |
| 2535 |
if (!num_ident) |
| 2536 |
break; |
| 2537 |
} |
| 2538 |
FOR_INV_FINISH(); |
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
if (num_ident) { |
| 2544 |
FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) |
| 2545 |
if (!tmp->invisible && !is_identified(tmp)) { |
| 2546 |
tmp = identify(tmp); |
| 2547 |
if (op->type == PLAYER) { |
| 2548 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 2549 |
"On the ground is %s.", |
| 2550 |
ob_describe(tmp, op, 1, desc, sizeof(desc))); |
| 2551 |
if (tmp->msg) { |
| 2552 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 2553 |
"The item has a story:\n%s", |
| 2554 |
tmp->msg); |
| 2555 |
} |
| 2556 |
esrv_update_item(UPD_FLAGS|UPD_NAME, op, tmp); |
| 2557 |
} |
| 2558 |
num_ident--; |
| 2559 |
success = 1; |
| 2560 |
if (!num_ident) |
| 2561 |
break; |
| 2562 |
} |
| 2563 |
FOR_MAP_FINISH(); |
| 2564 |
} |
| 2565 |
if (!success) |
| 2566 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2567 |
"You can't reach anything unidentified."); |
| 2568 |
else { |
| 2569 |
spell_effect(spell, op->x, op->y, op->map, op); |
| 2570 |
} |
| 2571 |
return success; |
| 2572 |
} |
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
int cast_detection(object *op, object *caster, object *spell) { |
| 2587 |
object *tmp, *last, *detect; |
| 2588 |
const object *god; |
| 2589 |
int done_one, range, mflags, floor, level; |
| 2590 |
int16_t x, y, nx, ny; |
| 2591 |
mapstruct *m; |
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
god = find_god(determine_god(op)); |
| 2597 |
level = caster_level(caster, spell); |
| 2598 |
range = spell->range+SP_level_range_adjust(caster, spell); |
| 2599 |
|
| 2600 |
for (x = op->x-range; x <= op->x+range; x++) |
| 2601 |
for (y = op->y-range; y <= op->y+range; y++) { |
| 2602 |
m = op->map; |
| 2603 |
mflags = get_map_flags(m, &m, x, y, &nx, &ny); |
| 2604 |
if (mflags&P_OUT_OF_MAP) |
| 2605 |
continue; |
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
last = NULL; |
| 2614 |
FOR_MAP_PREPARE(m, nx, ny, tmp) |
| 2615 |
last = tmp; |
| 2616 |
FOR_MAP_FINISH(); |
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
if (!last) |
| 2621 |
continue; |
| 2622 |
|
| 2623 |
done_one = 0; |
| 2624 |
floor = 0; |
| 2625 |
detect = NULL; |
| 2626 |
tmp = last; |
| 2627 |
FOR_OB_AND_BELOW_PREPARE(tmp) { |
| 2628 |
|
| 2629 |
if (QUERY_FLAG(spell, FLAG_MAKE_INVIS) |
| 2630 |
|
| 2631 |
&& (tmp->invisible && (QUERY_FLAG(tmp, FLAG_MONSTER) || |
| 2632 |
(tmp->type == PLAYER && !QUERY_FLAG(tmp, FLAG_WIZ)) || |
| 2633 |
tmp->type == CF_HANDLE || |
| 2634 |
tmp->type == TRAPDOOR || tmp->type == EXIT || tmp->type == HOLE || |
| 2635 |
tmp->type == BUTTON || tmp->type == TELEPORTER || |
| 2636 |
tmp->type == GATE || tmp->type == LOCKED_DOOR || |
| 2637 |
tmp->type == WEAPON || tmp->type == ALTAR || tmp->type == SIGN || |
| 2638 |
tmp->type == TRIGGER_PEDESTAL || tmp->type == SPECIAL_KEY || |
| 2639 |
tmp->type == TREASURE || tmp->type == BOOK || |
| 2640 |
tmp->type == HOLY_ALTAR))) { |
| 2641 |
if (random_roll(0, level-1, op, PREFER_HIGH) > tmp->level) { |
| 2642 |
tmp->invisible = 0; |
| 2643 |
done_one = 1; |
| 2644 |
} |
| 2645 |
} |
| 2646 |
if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
| 2647 |
floor = 1; |
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
if (floor) |
| 2655 |
continue; |
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
if (QUERY_FLAG(spell, FLAG_KNOWN_MAGICAL) |
| 2666 |
&& !QUERY_FLAG(tmp, FLAG_KNOWN_MAGICAL) |
| 2667 |
&& !QUERY_FLAG(tmp, FLAG_IDENTIFIED) |
| 2668 |
&& is_magical(tmp)) { |
| 2669 |
SET_FLAG(tmp, FLAG_KNOWN_MAGICAL); |
| 2670 |
|
| 2671 |
if (tmp->type == RUNE && tmp->attacktype&AT_MAGIC) |
| 2672 |
tmp->stats.Cha /= 4; |
| 2673 |
done_one = 1; |
| 2674 |
} |
| 2675 |
|
| 2676 |
if (QUERY_FLAG(spell, FLAG_MONSTER) |
| 2677 |
&& (QUERY_FLAG(tmp, FLAG_MONSTER) || (tmp->type == PLAYER && !QUERY_FLAG(tmp, FLAG_WIZ)))) { |
| 2678 |
done_one = 2; |
| 2679 |
if (!detect) |
| 2680 |
detect = tmp; |
| 2681 |
} |
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
if (spell->race |
| 2687 |
&& QUERY_FLAG(tmp, FLAG_MONSTER) |
| 2688 |
&& tmp->race |
| 2689 |
&& ((!strcmp(spell->race, "GOD") && god && god->slaying && strstr(god->slaying, tmp->race)) || (strstr(spell->race, tmp->race)))) { |
| 2690 |
done_one = 2; |
| 2691 |
if (!detect) |
| 2692 |
detect = tmp; |
| 2693 |
} |
| 2694 |
if (QUERY_FLAG(spell, FLAG_KNOWN_CURSED) |
| 2695 |
&& !QUERY_FLAG(tmp, FLAG_KNOWN_CURSED) |
| 2696 |
&& (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED))) { |
| 2697 |
SET_FLAG(tmp, FLAG_KNOWN_CURSED); |
| 2698 |
done_one = 1; |
| 2699 |
} |
| 2700 |
} FOR_OB_AND_BELOW_FINISH(); |
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
if (done_one) { |
| 2706 |
object *detect_ob; |
| 2707 |
int dx = nx, dy = ny; |
| 2708 |
|
| 2709 |
|
| 2710 |
if (done_one == 2 && detect) { |
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
object *part; |
| 2718 |
int flag; |
| 2719 |
|
| 2720 |
dx = HEAD(detect)->x; |
| 2721 |
dy = HEAD(detect)->y; |
| 2722 |
|
| 2723 |
detect_ob = object_create_arch(HEAD(detect)->arch); |
| 2724 |
for (part = detect_ob; part != NULL; part = part->more) { |
| 2725 |
if (part->arch->reference_count > 0) |
| 2726 |
part->arch->reference_count++; |
| 2727 |
part->last_anim = 0; |
| 2728 |
part->type = spell->other_arch->clone.type; |
| 2729 |
for (flag = 0; flag < 4; flag++) { |
| 2730 |
part->flags[flag] = spell->other_arch->clone.flags[flag]; |
| 2731 |
} |
| 2732 |
part->stats.food = spell->other_arch->clone.stats.food; |
| 2733 |
part->last_anim = 0; |
| 2734 |
part->speed = spell->other_arch->clone.speed; |
| 2735 |
part->speed_left = spell->other_arch->clone.speed_left; |
| 2736 |
part->move_allow = spell->other_arch->clone.move_allow; |
| 2737 |
part->move_block = spell->other_arch->clone.move_block; |
| 2738 |
part->move_type = spell->other_arch->clone.move_type; |
| 2739 |
part->glow_radius = spell->other_arch->clone.glow_radius; |
| 2740 |
part->invisible = spell->other_arch->clone.invisible; |
| 2741 |
part->weight = spell->other_arch->clone.weight; |
| 2742 |
part->map_layer = spell->other_arch->clone.map_layer; |
| 2743 |
FREE_AND_COPY(part->name, spell->other_arch->clone.name); |
| 2744 |
|
| 2745 |
|
| 2746 |
if (!QUERY_FLAG(detect, FLAG_ANIMATE)) |
| 2747 |
CLEAR_FLAG(part, FLAG_ANIMATE); |
| 2748 |
} |
| 2749 |
object_update_speed(detect_ob); |
| 2750 |
} else |
| 2751 |
detect_ob = arch_to_object(spell->other_arch); |
| 2752 |
|
| 2753 |
object_insert_in_map_at(detect_ob, m, op, 0, dx, dy); |
| 2754 |
} |
| 2755 |
} |
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
if (QUERY_FLAG(spell, FLAG_KNOWN_CURSED) || QUERY_FLAG(spell, FLAG_KNOWN_MAGICAL)) { |
| 2760 |
done_one = 0; |
| 2761 |
FOR_INV_PREPARE(op, tmp) { |
| 2762 |
if (!tmp->invisible && !QUERY_FLAG(tmp, FLAG_IDENTIFIED)) { |
| 2763 |
if (QUERY_FLAG(spell, FLAG_KNOWN_MAGICAL) |
| 2764 |
&& is_magical(tmp) |
| 2765 |
&& !QUERY_FLAG(tmp, FLAG_KNOWN_MAGICAL)) { |
| 2766 |
SET_FLAG(tmp, FLAG_KNOWN_MAGICAL); |
| 2767 |
if (op->type == PLAYER) |
| 2768 |
esrv_send_item(op, tmp); |
| 2769 |
} |
| 2770 |
if (QUERY_FLAG(spell, FLAG_KNOWN_CURSED) |
| 2771 |
&& !QUERY_FLAG(tmp, FLAG_KNOWN_CURSED) |
| 2772 |
&& (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED))) { |
| 2773 |
SET_FLAG(tmp, FLAG_KNOWN_CURSED); |
| 2774 |
if (op->type == PLAYER) |
| 2775 |
esrv_send_item(op, tmp); |
| 2776 |
} |
| 2777 |
} |
| 2778 |
} FOR_INV_FINISH(); |
| 2779 |
} |
| 2780 |
return 1; |
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
static void charge_mana_effect(object *victim, int caster_level) { |
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
if (victim->stats.maxsp <= 0) |
| 2795 |
return; |
| 2796 |
|
| 2797 |
draw_ext_info(NDI_UNIQUE, 0, victim, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2798 |
"You feel energy course through you."); |
| 2799 |
|
| 2800 |
if (victim->stats.sp >= victim->stats.maxsp*2) { |
| 2801 |
object *tmp; |
| 2802 |
|
| 2803 |
draw_ext_info(NDI_UNIQUE, 0, victim, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SPELL, |
| 2804 |
"Your head explodes!"); |
| 2805 |
|
| 2806 |
|
| 2807 |
tmp = create_archetype(EXPLODING_FIREBALL); |
| 2808 |
tmp->dam_modifier = random_roll(1, caster_level, victim, PREFER_LOW)/5+1; |
| 2809 |
tmp->stats.maxhp = random_roll(1, caster_level, victim, PREFER_LOW)/10+2; |
| 2810 |
object_insert_in_map_at(tmp, victim->map, NULL, 0, victim->x, victim->y); |
| 2811 |
victim->stats.sp = 2*victim->stats.maxsp; |
| 2812 |
} else if (victim->stats.sp >= victim->stats.maxsp*1.88) { |
| 2813 |
draw_ext_info(NDI_UNIQUE, NDI_ORANGE, victim, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2814 |
"You feel like your head is going to explode."); |
| 2815 |
} else if (victim->stats.sp >= victim->stats.maxsp*1.66) { |
| 2816 |
draw_ext_info(NDI_UNIQUE, 0, victim, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2817 |
"You get a splitting headache!"); |
| 2818 |
} else if (victim->stats.sp >= victim->stats.maxsp*1.5) { |
| 2819 |
draw_ext_info(NDI_UNIQUE, 0, victim, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2820 |
"Chaos fills your world."); |
| 2821 |
confuse_living(victim, victim, 99); |
| 2822 |
} else if (victim->stats.sp >= victim->stats.maxsp*1.25) { |
| 2823 |
draw_ext_info(NDI_UNIQUE, 0, victim, MSG_TYPE_SPELL, MSG_TYPE_SPELL_TARGET, |
| 2824 |
"You start hearing voices."); |
| 2825 |
} |
| 2826 |
} |
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
int cast_transfer(object *op, object *caster, object *spell, int dir) { |
| 2846 |
object *plyr = NULL; |
| 2847 |
int16_t x, y; |
| 2848 |
mapstruct *m; |
| 2849 |
int mflags; |
| 2850 |
|
| 2851 |
m = op->map; |
| 2852 |
x = op->x+freearr_x[dir]; |
| 2853 |
y = op->y+freearr_y[dir]; |
| 2854 |
|
| 2855 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 2856 |
if (!(mflags&P_OUT_OF_MAP) && mflags&P_IS_ALIVE) { |
| 2857 |
FOR_MAP_PREPARE(m, x, y, tmp) |
| 2858 |
plyr = tmp; |
| 2859 |
if (plyr != op && QUERY_FLAG(plyr, FLAG_ALIVE)) |
| 2860 |
break; |
| 2861 |
FOR_MAP_FINISH(); |
| 2862 |
} |
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
if (plyr == NULL) |
| 2868 |
FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) |
| 2869 |
plyr = tmp; |
| 2870 |
if (plyr != op && QUERY_FLAG(plyr, FLAG_ALIVE)) |
| 2871 |
break; |
| 2872 |
FOR_MAP_FINISH(); |
| 2873 |
|
| 2874 |
if (!plyr) { |
| 2875 |
draw_ext_info(NDI_BLACK, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 2876 |
"There is no one there."); |
| 2877 |
return 0; |
| 2878 |
} |
| 2879 |
|
| 2880 |
|
| 2881 |
if (spell->stats.dam > 0) { |
| 2882 |
plyr->stats.sp += spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 2883 |
charge_mana_effect(plyr, caster_level(caster, spell)); |
| 2884 |
return 1; |
| 2885 |
|
| 2886 |
} else if (op != plyr) { |
| 2887 |
|
| 2888 |
|
| 2889 |
int rate = -spell->stats.dam+SP_level_dam_adjust(caster, spell), sucked; |
| 2890 |
|
| 2891 |
if (rate > 95) |
| 2892 |
rate = 95; |
| 2893 |
|
| 2894 |
sucked = (plyr->stats.sp*rate)/100; |
| 2895 |
plyr->stats.sp -= sucked; |
| 2896 |
if (QUERY_FLAG(op, FLAG_ALIVE)) { |
| 2897 |
|
| 2898 |
sucked = (sucked*rate)/100; |
| 2899 |
op->stats.sp += sucked; |
| 2900 |
if (sucked > 0) { |
| 2901 |
charge_mana_effect(op, caster_level(caster, spell)); |
| 2902 |
} |
| 2903 |
} |
| 2904 |
return 1; |
| 2905 |
} |
| 2906 |
return 0; |
| 2907 |
} |
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
void counterspell(object *op, int dir) { |
| 2919 |
object *head; |
| 2920 |
int mflags; |
| 2921 |
mapstruct *m; |
| 2922 |
int16_t sx, sy; |
| 2923 |
|
| 2924 |
sx = op->x+freearr_x[dir]; |
| 2925 |
sy = op->y+freearr_y[dir]; |
| 2926 |
m = op->map; |
| 2927 |
mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
| 2928 |
if (mflags&P_OUT_OF_MAP) |
| 2929 |
return; |
| 2930 |
|
| 2931 |
FOR_MAP_PREPARE(m, sx, sy, tmp) { |
| 2932 |
object *owner; |
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
head = HEAD(tmp); |
| 2939 |
|
| 2940 |
|
| 2941 |
owner = object_get_owner(tmp); |
| 2942 |
if (owner != NULL && owner == object_get_owner(op)) |
| 2943 |
continue; |
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
if (head->attacktype&AT_MAGIC |
| 2951 |
&& !(head->attacktype&AT_COUNTERSPELL) |
| 2952 |
&& !QUERY_FLAG(head, FLAG_MONSTER) |
| 2953 |
&& (op->level > head->level)) { |
| 2954 |
object_remove(head); |
| 2955 |
object_free(head, 0); |
| 2956 |
} else switch (head->type) { |
| 2957 |
case SPELL_EFFECT: |
| 2958 |
if ((op->level > head->level) && !op->stats.food && !op->speed_left) { |
| 2959 |
object_remove(head); |
| 2960 |
object_free(head, 0); |
| 2961 |
} |
| 2962 |
break; |
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
case RUNE: |
| 2968 |
if (rndm(0, 149) == 0) { |
| 2969 |
head->stats.hp--; |
| 2970 |
if (!head->stats.hp) { |
| 2971 |
object_remove(head); |
| 2972 |
object_free(head, 0); |
| 2973 |
} |
| 2974 |
} |
| 2975 |
break; |
| 2976 |
} |
| 2977 |
} FOR_MAP_FINISH(); |
| 2978 |
} |
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
int cast_consecrate(object *op, object *caster, object *spell) { |
| 2995 |
char buf[MAX_BUF]; |
| 2996 |
const object *god = find_god(determine_god(op)); |
| 2997 |
|
| 2998 |
if (!god) { |
| 2999 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3000 |
"You can't consecrate anything if you don't worship a god!"); |
| 3001 |
return 0; |
| 3002 |
} |
| 3003 |
|
| 3004 |
FOR_BELOW_PREPARE(op, tmp) { |
| 3005 |
if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
| 3006 |
break; |
| 3007 |
if (tmp->type == HOLY_ALTAR) { |
| 3008 |
if (tmp->level > caster_level(caster, spell)) { |
| 3009 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 3010 |
"You are not powerful enough to reconsecrate the %s", |
| 3011 |
tmp->name); |
| 3012 |
return 0; |
| 3013 |
} else { |
| 3014 |
|
| 3015 |
object *new_altar; |
| 3016 |
size_t letter; |
| 3017 |
archetype *altar_arch; |
| 3018 |
|
| 3019 |
snprintf(buf, MAX_BUF, "altar_"); |
| 3020 |
letter = strlen(buf); |
| 3021 |
strncpy(buf+letter, god->name, MAX_BUF-letter); |
| 3022 |
for (; letter < strlen(buf); letter++) |
| 3023 |
buf[letter] = tolower(buf[letter]); |
| 3024 |
altar_arch = find_archetype(buf); |
| 3025 |
if (!altar_arch) { |
| 3026 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 3027 |
"You fail to consecrate the altar."); |
| 3028 |
LOG(llevError, "cast_consecrate: can't find altar %s for god %s\n", buf, god->name); |
| 3029 |
return 0; |
| 3030 |
} |
| 3031 |
new_altar = arch_to_object(altar_arch); |
| 3032 |
new_altar->level = tmp->level; |
| 3033 |
if (QUERY_FLAG(tmp, FLAG_IS_BUILDABLE)) |
| 3034 |
SET_FLAG(new_altar, FLAG_IS_BUILDABLE); |
| 3035 |
object_insert_in_map_at(new_altar, tmp->map, tmp, INS_BELOW_ORIGINATOR, tmp->x, tmp->y); |
| 3036 |
object_remove(tmp); |
| 3037 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 3038 |
"You consecrated the altar to %s!", |
| 3039 |
god->name); |
| 3040 |
return 1; |
| 3041 |
} |
| 3042 |
} |
| 3043 |
} FOR_BELOW_FINISH(); |
| 3044 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 3045 |
"You are not standing over an altar!"); |
| 3046 |
return 0; |
| 3047 |
} |
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
|
| 3053 |
|
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
int animate_weapon(object *op, object *caster, object *spell, int dir) { |
| 3073 |
object *weapon, *tmp; |
| 3074 |
char buf[MAX_BUF]; |
| 3075 |
int a, i; |
| 3076 |
int16_t x, y; |
| 3077 |
mapstruct *m; |
| 3078 |
materialtype_t *mt; |
| 3079 |
|
| 3080 |
if (!spell->other_arch) { |
| 3081 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3082 |
"Oops, program error!"); |
| 3083 |
LOG(llevError, "animate_weapon failed: spell %s missing other_arch!\n", spell->name); |
| 3084 |
return 0; |
| 3085 |
} |
| 3086 |
|
| 3087 |
|
| 3088 |
if (op->type != PLAYER) |
| 3089 |
return 0; |
| 3090 |
|
| 3091 |
|
| 3092 |
if (op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) { |
| 3093 |
pets_control_golem(op->contr->ranges[range_golem], dir); |
| 3094 |
return 0; |
| 3095 |
} |
| 3096 |
|
| 3097 |
|
| 3098 |
if (!dir) { |
| 3099 |
dir = object_find_free_spot(NULL, op->map, op->x, op->y, 1, 9); |
| 3100 |
if ( dir == -1 ) { |
| 3101 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3102 |
"There is something in the way."); |
| 3103 |
return 0; |
| 3104 |
} |
| 3105 |
} |
| 3106 |
|
| 3107 |
m = op->map; |
| 3108 |
x = op->x+freearr_x[dir]; |
| 3109 |
y = op->y+freearr_y[dir]; |
| 3110 |
|
| 3111 |
|
| 3112 |
if ((dir == -1) |
| 3113 |
|| (get_map_flags(m, &m, x, y, &x, &y)&P_OUT_OF_MAP) |
| 3114 |
|| ((spell->other_arch->clone.move_type&GET_MAP_MOVE_BLOCK(m, x, y)) == spell->other_arch->clone.move_type)) { |
| 3115 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3116 |
"There is something in the way."); |
| 3117 |
return 0; |
| 3118 |
} |
| 3119 |
|
| 3120 |
|
| 3121 |
weapon = find_marked_object(op); |
| 3122 |
|
| 3123 |
if (!weapon) { |
| 3124 |
draw_ext_info(NDI_BLACK, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3125 |
"You must mark a weapon to use with this spell!"); |
| 3126 |
return 0; |
| 3127 |
} |
| 3128 |
if (spell->race && strcmp(weapon->arch->name, spell->race)) { |
| 3129 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3130 |
"The spell fails to transform your weapon."); |
| 3131 |
return 0; |
| 3132 |
} |
| 3133 |
if (weapon->type != WEAPON) { |
| 3134 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3135 |
"You need to mark a weapon to animate it."); |
| 3136 |
return 0; |
| 3137 |
} |
| 3138 |
if (QUERY_FLAG(weapon, FLAG_UNPAID)) { |
| 3139 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3140 |
"You need to pay for the weapon to animate it."); |
| 3141 |
return 0; |
| 3142 |
} |
| 3143 |
if (QUERY_FLAG(weapon, FLAG_APPLIED)) { |
| 3144 |
char wn[MAX_BUF]; |
| 3145 |
|
| 3146 |
query_name(weapon, wn, MAX_BUF); |
| 3147 |
draw_ext_info_format(NDI_BLACK, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3148 |
"You need to unequip %s before using it in this spell", |
| 3149 |
wn); |
| 3150 |
return 0; |
| 3151 |
} |
| 3152 |
|
| 3153 |
if (weapon->nrof > 1) { |
| 3154 |
tmp = object_split(weapon, 1, NULL, 0); |
| 3155 |
esrv_update_item(UPD_NROF, op, weapon); |
| 3156 |
weapon = tmp; |
| 3157 |
} |
| 3158 |
|
| 3159 |
|
| 3160 |
tmp = arch_to_object(spell->other_arch); |
| 3161 |
|
| 3162 |
|
| 3163 |
CLEAR_FLAG(tmp, FLAG_MONSTER); |
| 3164 |
SET_FLAG(tmp, FLAG_FRIENDLY); |
| 3165 |
tmp->stats.exp = 0; |
| 3166 |
add_friendly_object(tmp); |
| 3167 |
tmp->type = GOLEM; |
| 3168 |
object_set_owner(tmp, op); |
| 3169 |
set_spell_skill(op, caster, spell, tmp); |
| 3170 |
op->contr->ranges[range_golem] = tmp; |
| 3171 |
op->contr->shoottype = range_golem; |
| 3172 |
op->contr->golem_count = tmp->count; |
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
if (!QUERY_FLAG(weapon, FLAG_REMOVED)) |
| 3179 |
object_remove(weapon); |
| 3180 |
object_insert_in_ob(weapon, tmp); |
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
SET_FLAG(tmp, FLAG_USE_WEAPON); |
| 3187 |
SET_FLAG(weapon, FLAG_APPLIED); |
| 3188 |
fix_object(tmp); |
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
tmp->stats.wc = tmp->stats.wc |
| 3197 |
-SP_level_range_adjust(caster, spell) |
| 3198 |
-5*weapon->stats.Dex |
| 3199 |
-2*weapon->stats.Str |
| 3200 |
-weapon->magic; |
| 3201 |
if (tmp->stats.wc < -127) |
| 3202 |
tmp->stats.wc = -127; |
| 3203 |
|
| 3204 |
|
| 3205 |
tmp->stats.maxhp = tmp->stats.maxhp |
| 3206 |
+spell->duration |
| 3207 |
+SP_level_duration_adjust(caster, spell) |
| 3208 |
+8*weapon->magic |
| 3209 |
+12*weapon->stats.Con; |
| 3210 |
if (tmp->stats.maxhp < 0) |
| 3211 |
tmp->stats.maxhp = 10; |
| 3212 |
tmp->stats.hp = tmp->stats.maxhp; |
| 3213 |
|
| 3214 |
|
| 3215 |
tmp->stats.dam = spell->stats.dam |
| 3216 |
+SP_level_dam_adjust(caster, spell) |
| 3217 |
+weapon->stats.dam |
| 3218 |
+weapon->magic |
| 3219 |
+5*weapon->stats.Str; |
| 3220 |
if (tmp->stats.dam < 0) |
| 3221 |
tmp->stats.dam = 127; |
| 3222 |
|
| 3223 |
|
| 3224 |
if (!tmp->attacktype) |
| 3225 |
tmp->attacktype = AT_PHYSICAL; |
| 3226 |
|
| 3227 |
mt = NULL; |
| 3228 |
if (op->materialname != NULL) |
| 3229 |
mt = name_to_material(op->materialname); |
| 3230 |
if (mt != NULL) { |
| 3231 |
for (i = 0; i < NROFATTACKS; i++) |
| 3232 |
tmp->resist[i] = 50-(mt->save[i]*5); |
| 3233 |
a = mt->save[0]; |
| 3234 |
} else { |
| 3235 |
for (i = 0; i < NROFATTACKS; i++) |
| 3236 |
tmp->resist[i] = 5; |
| 3237 |
a = 10; |
| 3238 |
} |
| 3239 |
|
| 3240 |
tmp->resist[ATNR_CONFUSION] = 100; |
| 3241 |
tmp->resist[ATNR_POISON] = 100; |
| 3242 |
tmp->resist[ATNR_SLOW] = 100; |
| 3243 |
tmp->resist[ATNR_PARALYZE] = 100; |
| 3244 |
tmp->resist[ATNR_TURN_UNDEAD] = 100; |
| 3245 |
tmp->resist[ATNR_FEAR] = 100; |
| 3246 |
tmp->resist[ATNR_DEPLETE] = 100; |
| 3247 |
tmp->resist[ATNR_DEATH] = 100; |
| 3248 |
tmp->resist[ATNR_BLIND] = 100; |
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
if (a > 14) |
| 3253 |
a = 14; |
| 3254 |
tmp->resist[ATNR_PHYSICAL] = 100-(int)((100.0-(float)tmp->resist[ATNR_PHYSICAL])/(30.0-2.0*a)); |
| 3255 |
|
| 3256 |
|
| 3257 |
tmp->speed = 0.4+0.1*SP_level_range_adjust(caster, spell); |
| 3258 |
|
| 3259 |
if (tmp->speed > 3.33) |
| 3260 |
tmp->speed = 3.33; |
| 3261 |
|
| 3262 |
if (!spell->race) { |
| 3263 |
snprintf(buf, sizeof(buf), "animated %s", weapon->name); |
| 3264 |
if (tmp->name) |
| 3265 |
free_string(tmp->name); |
| 3266 |
tmp->name = add_string(buf); |
| 3267 |
|
| 3268 |
tmp->face = weapon->face; |
| 3269 |
tmp->animation = weapon->animation; |
| 3270 |
tmp->anim_speed = weapon->anim_speed; |
| 3271 |
tmp->last_anim = weapon->last_anim; |
| 3272 |
tmp->state = weapon->state; |
| 3273 |
if (QUERY_FLAG(weapon, FLAG_ANIMATE)) { |
| 3274 |
SET_FLAG(tmp, FLAG_ANIMATE); |
| 3275 |
} else { |
| 3276 |
CLEAR_FLAG(tmp, FLAG_ANIMATE); |
| 3277 |
} |
| 3278 |
object_update_speed(tmp); |
| 3279 |
} |
| 3280 |
|
| 3281 |
|
| 3282 |
tmp->stats.exp *= 1+(MAX(spell->stats.maxgrace, spell->stats.sp)/caster_level(caster, spell)); |
| 3283 |
|
| 3284 |
tmp->speed_left = -1; |
| 3285 |
tmp->direction = dir; |
| 3286 |
object_insert_in_map_at(tmp, m, op, 0, x, y); |
| 3287 |
return 1; |
| 3288 |
} |
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
int cast_change_map_lightlevel(object *op, object *caster, object *spell) { |
| 3305 |
int success; |
| 3306 |
|
| 3307 |
if (!op->map) |
| 3308 |
return 0; |
| 3309 |
|
| 3310 |
success = change_map_light(op->map, spell->stats.dam); |
| 3311 |
if (!success) { |
| 3312 |
if (spell->stats.dam < 0) |
| 3313 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 3314 |
"It can be no brighter here."); |
| 3315 |
else |
| 3316 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 3317 |
"It can be no darker here."); |
| 3318 |
} |
| 3319 |
return success; |
| 3320 |
} |
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
int create_aura(object *op, object *caster, object *spell) { |
| 3337 |
int refresh = 0, i; |
| 3338 |
object *new_aura; |
| 3339 |
|
| 3340 |
new_aura = arch_present_in_ob(spell->other_arch, op); |
| 3341 |
if (new_aura) |
| 3342 |
refresh = 1; |
| 3343 |
else |
| 3344 |
new_aura = arch_to_object(spell->other_arch); |
| 3345 |
|
| 3346 |
new_aura->duration = spell->duration+10*SP_level_duration_adjust(caster, spell); |
| 3347 |
if (op->type == PLAYER) |
| 3348 |
store_spell_expiry(new_aura); |
| 3349 |
|
| 3350 |
new_aura->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 3351 |
|
| 3352 |
object_set_owner(new_aura, op); |
| 3353 |
set_spell_skill(op, caster, spell, new_aura); |
| 3354 |
new_aura->attacktype = spell->attacktype; |
| 3355 |
|
| 3356 |
new_aura->level = caster_level(caster, spell); |
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
for (i = 0; i < NROFATTACKS; i++) { |
| 3368 |
if (spell->resist[i]) { |
| 3369 |
int refresh1=1; |
| 3370 |
object *force; |
| 3371 |
|
| 3372 |
force = object_present_in_ob_by_name(FORCE, spell->name, op); |
| 3373 |
if (!force) { |
| 3374 |
force=create_archetype(FORCE_NAME); |
| 3375 |
force->subtype = FORCE_CHANGE_ABILITY; |
| 3376 |
free_string(force->name); |
| 3377 |
force->name = add_refcount(spell->name); |
| 3378 |
free_string(force->name_pl); |
| 3379 |
force->name_pl = add_refcount(spell->name); |
| 3380 |
refresh1=0; |
| 3381 |
} |
| 3382 |
force->duration = new_aura->duration; |
| 3383 |
force->speed = new_aura->speed; |
| 3384 |
memcpy(&force->resist, spell->resist, sizeof(spell->resist)); |
| 3385 |
SET_FLAG(force, FLAG_APPLIED); |
| 3386 |
|
| 3387 |
if (!refresh1) |
| 3388 |
object_insert_in_ob(force, op); |
| 3389 |
change_abil(op, new_aura); |
| 3390 |
fix_object(op); |
| 3391 |
break; |
| 3392 |
} |
| 3393 |
} |
| 3394 |
|
| 3395 |
if (refresh) |
| 3396 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 3397 |
"You recast the spell while in effect."); |
| 3398 |
else |
| 3399 |
object_insert_in_ob(new_aura, op); |
| 3400 |
return 1; |
| 3401 |
} |
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
int write_mark(object *op, object *spell, const char *msg) { |
| 3419 |
char rune[HUGE_BUF]; |
| 3420 |
object *tmp; |
| 3421 |
|
| 3422 |
if (!msg || msg[0] == 0) { |
| 3423 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3424 |
"Write what?"); |
| 3425 |
return 0; |
| 3426 |
} |
| 3427 |
|
| 3428 |
if (strcasestr_local(msg, "endmsg")) { |
| 3429 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, |
| 3430 |
"Trying to cheat are we?"); |
| 3431 |
LOG(llevInfo, "write_rune: player %s tried to write bogus rune %s\n", op->name, msg); |
| 3432 |
return 0; |
| 3433 |
} |
| 3434 |
|
| 3435 |
if (!spell->other_arch) |
| 3436 |
return 0; |
| 3437 |
tmp = arch_to_object(spell->other_arch); |
| 3438 |
strncpy(rune, msg, HUGE_BUF-2); |
| 3439 |
rune[HUGE_BUF-2] = 0; |
| 3440 |
strcat(rune, "\n"); |
| 3441 |
tmp->race = add_string(op->name); |
| 3442 |
object_set_msg(tmp, rune); |
| 3443 |
object_insert_in_map_at(tmp, op->map, op, INS_BELOW_ORIGINATOR, op->x, op->y); |
| 3444 |
return 1; |
| 3445 |
} |