| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "global.h" |
| 25 |
|
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#include "living.h" |
| 30 |
#include "object.h" |
| 31 |
#include "sounds.h" |
| 32 |
#include "spells.h" |
| 33 |
#include "sproto.h" |
| 34 |
|
| 35 |
static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string); |
| 36 |
static void stop_using_item(object *op, int type, int number); |
| 37 |
static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag); |
| 38 |
static void god_intervention(object *op, const object *god, object *skill, object *altar); |
| 39 |
static int god_examines_priest(object *op, const object *god); |
| 40 |
static int god_examines_item(const object *god, object *item); |
| 41 |
static const char *get_god_for_race(const char *race); |
| 42 |
static void remove_special_prayers(object *op, const object *god); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static int lookup_god_by_name(const char *name) { |
| 55 |
int godnr = -1; |
| 56 |
size_t nmlen = strlen(name); |
| 57 |
|
| 58 |
if (name && strcmp(name, "none")) { |
| 59 |
godlink *gl; |
| 60 |
for (gl = first_god; gl; gl = gl->next) |
| 61 |
if (!strncmp(name, gl->name, MIN(strlen(gl->name), nmlen))) |
| 62 |
break; |
| 63 |
if (gl) |
| 64 |
godnr = gl->id; |
| 65 |
} |
| 66 |
return godnr; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
const object *find_god(const char *name) { |
| 81 |
godlink *gl; |
| 82 |
|
| 83 |
if (!name) |
| 84 |
return NULL; |
| 85 |
|
| 86 |
for (gl = first_god; gl; gl = gl->next) { |
| 87 |
if (!strcmp(name, gl->name)) |
| 88 |
return pntr_to_god_obj(gl); |
| 89 |
} |
| 90 |
|
| 91 |
return NULL; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
const char *determine_god(object *op) { |
| 107 |
int godnr = -1; |
| 108 |
const char *godname; |
| 109 |
|
| 110 |
|
| 111 |
if ((op->type == SPELL || op->type == SPELL_EFFECT) |
| 112 |
&& op->title) { |
| 113 |
if (lookup_god_by_name(op->title) >= 0) |
| 114 |
return op->title; |
| 115 |
} |
| 116 |
|
| 117 |
if (op->type != PLAYER && QUERY_FLAG(op, FLAG_ALIVE)) { |
| 118 |
|
| 119 |
if (!op->title) { |
| 120 |
if (op->race != NULL) { |
| 121 |
godname = get_god_for_race(op->race); |
| 122 |
if (godname != NULL) { |
| 123 |
op->title = add_string(godname); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
if (!op->title) { |
| 130 |
godlink *gl = first_god; |
| 131 |
|
| 132 |
godnr = rndm(1, gl->id); |
| 133 |
while (gl) { |
| 134 |
if (gl->id == godnr) |
| 135 |
{ |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
op->title = add_string(gl->name); |
| 141 |
|
| 142 |
break; |
| 143 |
} |
| 144 |
gl = gl->next; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
return op->title; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
if (op->type == PLAYER) { |
| 157 |
object *tmp; |
| 158 |
|
| 159 |
tmp = object_find_by_type_subtype(op, SKILL, SK_PRAYING); |
| 160 |
if (tmp != NULL) { |
| 161 |
return tmp->title != NULL ? tmp->title : "none"; |
| 162 |
} |
| 163 |
} |
| 164 |
return ("none"); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
static int same_string(const char *s1, const char *s2) { |
| 176 |
if (s1 == NULL) |
| 177 |
return s2 == NULL; |
| 178 |
else |
| 179 |
return s2 != NULL && strcmp(s1, s2) == 0; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
static void follower_remove_given_items(object *pl, object *op, const object *god) { |
| 198 |
const char *given_by; |
| 199 |
|
| 200 |
|
| 201 |
FOR_INV_PREPARE(op, tmp) { |
| 202 |
given_by = object_get_value(tmp, "divine_giver_name"); |
| 203 |
if (given_by == god->name) { |
| 204 |
char name[HUGE_BUF]; |
| 205 |
|
| 206 |
query_short_name(tmp, name, HUGE_BUF); |
| 207 |
|
| 208 |
if (tmp->nrof > 1) |
| 209 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, |
| 210 |
"The %s crumble to dust!", |
| 211 |
name); |
| 212 |
else |
| 213 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, |
| 214 |
"The %s crumbles to dust!", |
| 215 |
name); |
| 216 |
|
| 217 |
object_remove(tmp); |
| 218 |
object_free_drop_inventory(tmp); |
| 219 |
} else if (tmp->inv) |
| 220 |
follower_remove_given_items(pl, tmp, god); |
| 221 |
} FOR_INV_FINISH(); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
static int follower_has_similar_item(object *op, object *item) { |
| 234 |
FOR_INV_PREPARE(op, tmp) { |
| 235 |
if (tmp->type == item->type |
| 236 |
&& same_string(tmp->name, item->name) |
| 237 |
&& same_string(tmp->title, item->title) |
| 238 |
&& tmp->msg == item->msg |
| 239 |
&& same_string(tmp->slaying, item->slaying)) |
| 240 |
return 1; |
| 241 |
if (tmp->inv && follower_has_similar_item(tmp, item)) |
| 242 |
return 1; |
| 243 |
} FOR_INV_FINISH(); |
| 244 |
return 0; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
static int god_gives_present(object *op, const object *god, treasure *tr) { |
| 260 |
object *tmp; |
| 261 |
char name[HUGE_BUF]; |
| 262 |
|
| 263 |
if (follower_has_similar_item(op, &tr->item->clone)) |
| 264 |
return 0; |
| 265 |
|
| 266 |
tmp = arch_to_object(tr->item); |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
fix_generated_item(tmp, NULL, 120, 120, GT_ONLY_GOOD); |
| 273 |
|
| 274 |
|
| 275 |
if ((tmp->type == ROD || tmp->type == WAND) && (tmp->inv == NULL)) { |
| 276 |
object_free(tmp, 0); |
| 277 |
return 0; |
| 278 |
} |
| 279 |
|
| 280 |
query_short_name(tmp, name, HUGE_BUF); |
| 281 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD, |
| 282 |
"%s lets %s appear in your hands.", |
| 283 |
god->name, name); |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
object_set_value(tmp, "divine_giver_name", god->name, TRUE); |
| 288 |
object_insert_in_ob(tmp, op); |
| 289 |
return 1; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
static bool try_leave_cult(object* pl, object* skill, int angry) { |
| 297 |
const uint64_t loss = angry * (skill->stats.exp / 10); |
| 298 |
if (loss) |
| 299 |
change_exp(pl, -random_roll64(0, loss, pl, PREFER_LOW), |
| 300 |
skill ? skill->skill : "none", SK_SUBTRACT_SKILL_EXP); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
if ((angry == 1) && !(random_roll(0, skill->level, pl, PREFER_LOW))) { |
| 306 |
return true; |
| 307 |
} else { |
| 308 |
return false; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
void pray_at_altar(object *pl, object *altar, object *skill) { |
| 324 |
const object *pl_god = find_god(determine_god(pl)); |
| 325 |
|
| 326 |
|
| 327 |
if (execute_event(altar, EVENT_APPLY, pl, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 328 |
return; |
| 329 |
|
| 330 |
|
| 331 |
if (!altar->other_arch) |
| 332 |
return; |
| 333 |
|
| 334 |
|
| 335 |
if (!pl_god) { |
| 336 |
become_follower(pl, &altar->other_arch->clone); |
| 337 |
return; |
| 338 |
} |
| 339 |
|
| 340 |
if (!strcmp(pl_god->name, altar->other_arch->clone.name)) { |
| 341 |
|
| 342 |
int bonus = (pl->stats.Wis+skill->level)/10; |
| 343 |
|
| 344 |
|
| 345 |
if (pl->stats.grace < 0) |
| 346 |
pl->stats.grace += (bonus > -1*(pl->stats.grace/10) ? bonus : -1*(pl->stats.grace/10)); |
| 347 |
|
| 348 |
if (pl->stats.grace < (2*pl->stats.maxgrace)) { |
| 349 |
pl->stats.grace += bonus/2; |
| 350 |
} |
| 351 |
if (pl->stats.grace > (2*pl->stats.maxgrace)) { |
| 352 |
pl->stats.grace = (2*pl->stats.maxgrace); |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
bonus = MAX(1, bonus+MAX(pl->stats.luck, -3)); |
| 359 |
|
| 360 |
if (((random_roll(0, 399, pl, PREFER_LOW))-bonus) < 0) |
| 361 |
god_intervention(pl, pl_god, skill, altar); |
| 362 |
} else { |
| 363 |
int angry = 1; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
if (pl_god->other_arch |
| 373 |
&& (altar->other_arch->name == pl_god->other_arch->name)) { |
| 374 |
angry = 2; |
| 375 |
if (random_roll(0, skill->level+2, pl, PREFER_LOW)-5 > 0) { |
| 376 |
object *tmp; |
| 377 |
|
| 378 |
|
| 379 |
angry = 3; |
| 380 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 381 |
"Foul Priest! %s punishes you!", |
| 382 |
pl_god->name); |
| 383 |
tmp = create_archetype(LOOSE_MANA); |
| 384 |
cast_magic_storm(pl, tmp, pl_god->level+20); |
| 385 |
} else |
| 386 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 387 |
"Foolish heretic! %s is livid!", |
| 388 |
pl_god->name); |
| 389 |
} else |
| 390 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 391 |
"Heretic! %s is angered!", |
| 392 |
pl_god->name); |
| 393 |
|
| 394 |
if (try_leave_cult(pl, skill, angry)) { |
| 395 |
become_follower(pl, &altar->other_arch->clone); |
| 396 |
} else { |
| 397 |
|
| 398 |
draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 399 |
"A divine force pushes you off the altar."); |
| 400 |
|
| 401 |
move_player(pl, absdir(pl->facing+4)); |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
static void remove_special_prayers(object *op, const object *god) { |
| 417 |
treasure *tr; |
| 418 |
int remove = 0; |
| 419 |
|
| 420 |
if (god->randomitems == NULL) { |
| 421 |
LOG(llevError, "BUG: remove_special_prayers(): god %s without randomitems\n", god->name); |
| 422 |
return; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
FOR_INV_PREPARE(op, tmp) { |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
if (tmp->type != SPELL || !QUERY_FLAG(tmp, FLAG_STARTEQUIP)) |
| 432 |
continue; |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
remove = 0; |
| 438 |
for (tr = god->randomitems->items; tr; tr = tr->next) { |
| 439 |
if (tr->item == NULL) |
| 440 |
continue; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) { |
| 445 |
remove = 1; |
| 446 |
break; |
| 447 |
} |
| 448 |
} |
| 449 |
if (remove) { |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, |
| 454 |
MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 455 |
"You lose knowledge of %s.", |
| 456 |
tmp->name); |
| 457 |
player_unready_range_ob(op->contr, tmp); |
| 458 |
object_remove(tmp); |
| 459 |
object_free_drop_inventory(tmp); |
| 460 |
} |
| 461 |
} FOR_INV_FINISH(); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
int become_follower(object *op, const object *new_god) { |
| 480 |
|
| 481 |
FOR_INV_PREPARE(op, item) { |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
if (QUERY_FLAG(item, FLAG_STARTEQUIP) |
| 486 |
&& item->invisible |
| 487 |
&& (item->type != SKILL) |
| 488 |
&& (item->type != FORCE) |
| 489 |
&& (item->type != SPELL)) { |
| 490 |
player_unready_range_ob(op->contr, item); |
| 491 |
object_remove(item); |
| 492 |
object_free_drop_inventory(item); |
| 493 |
} |
| 494 |
} FOR_INV_FINISH(); |
| 495 |
|
| 496 |
|
| 497 |
const object *old_god = find_god(determine_god(op)); |
| 498 |
if (old_god) { |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
follower_remove_given_items(op, op, old_god); |
| 505 |
remove_special_prayers(op, old_god); |
| 506 |
} |
| 507 |
|
| 508 |
if (!op || !new_god) |
| 509 |
return 0; |
| 510 |
|
| 511 |
if (op->race && new_god->slaying && strstr(op->race, new_god->slaying)) { |
| 512 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 513 |
"Fool! %s detests your kind!", |
| 514 |
new_god->name); |
| 515 |
if (random_roll(0, op->level-1, op, PREFER_LOW)-5 > 0) { |
| 516 |
object *tmp = create_archetype(LOOSE_MANA); |
| 517 |
cast_magic_storm(op, tmp, new_god->level+10); |
| 518 |
} |
| 519 |
return 0; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
for (treasure *tr = new_god->randomitems->items; tr != NULL; tr = tr->next) { |
| 524 |
if (tr->item |
| 525 |
&& tr->item->clone.invisible |
| 526 |
&& tr->item->clone.type != SPELLBOOK |
| 527 |
&& tr->item->clone.type != BOOK |
| 528 |
&& tr->item->clone.type != SPELL) |
| 529 |
god_gives_present(op, new_god, tr); |
| 530 |
} |
| 531 |
|
| 532 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 533 |
"You become a follower of %s!", |
| 534 |
new_god->name); |
| 535 |
|
| 536 |
object *skop = object_find_by_type_subtype(op, SKILL, SK_PRAYING); |
| 537 |
|
| 538 |
if (!skop) { |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
skop = give_skill_by_name(op, get_archetype_by_type_subtype(SKILL, SK_PRAYING)->clone.skill); |
| 543 |
link_player_skills(op); |
| 544 |
} |
| 545 |
|
| 546 |
int sk_applied = QUERY_FLAG(skop, FLAG_APPLIED); |
| 547 |
|
| 548 |
int undeadified = 0; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
if ((old_god) && (QUERY_FLAG(old_god, FLAG_UNDEAD))) { |
| 555 |
CLEAR_FLAG(skop, FLAG_UNDEAD); |
| 556 |
undeadified = 1; |
| 557 |
} |
| 558 |
|
| 559 |
if (skop->title) { |
| 560 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 561 |
"%s's blessing is withdrawn from you.", |
| 562 |
skop->title); |
| 563 |
|
| 564 |
|
| 565 |
if (sk_applied || undeadified) { |
| 566 |
CLEAR_FLAG(skop, FLAG_APPLIED); |
| 567 |
(void)change_abil(op, skop); |
| 568 |
} |
| 569 |
free_string(skop->title); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
skop->title = add_string(new_god->name); |
| 574 |
skop->path_attuned = new_god->path_attuned; |
| 575 |
skop->path_repelled = new_god->path_repelled; |
| 576 |
skop->path_denied = new_god->path_denied; |
| 577 |
|
| 578 |
memcpy(skop->resist, new_god->resist, sizeof(new_god->resist)); |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
for (int i = 0; i < NROFATTACKS; i++) |
| 584 |
if (skop->resist[i] > 30 |
| 585 |
&& (i == ATNR_FIRE || i == ATNR_COLD || i == ATNR_ELECTRICITY || i == ATNR_POISON)) |
| 586 |
skop->resist[i] = 30; |
| 587 |
|
| 588 |
skop->stats.hp = (int16_t)new_god->last_heal; |
| 589 |
skop->stats.sp = (int16_t)new_god->last_sp; |
| 590 |
skop->stats.grace = (int16_t)new_god->last_grace; |
| 591 |
skop->stats.food = (int16_t)new_god->last_eat; |
| 592 |
skop->stats.luck = (int8_t)new_god->stats.luck; |
| 593 |
|
| 594 |
update_priest_flag(new_god, skop, FLAG_SEE_IN_DARK); |
| 595 |
update_priest_flag(new_god, skop, FLAG_REFL_SPELL); |
| 596 |
update_priest_flag(new_god, skop, FLAG_REFL_MISSILE); |
| 597 |
update_priest_flag(new_god, skop, FLAG_STEALTH); |
| 598 |
update_priest_flag(new_god, skop, FLAG_MAKE_INVIS); |
| 599 |
update_priest_flag(new_god, skop, FLAG_UNDEAD); |
| 600 |
update_priest_flag(new_god, skop, FLAG_BLIND); |
| 601 |
update_priest_flag(new_god, skop, FLAG_XRAYS); |
| 602 |
update_priest_flag(new_god, skop, FLAG_USE_WEAPON); |
| 603 |
update_priest_flag(new_god, skop, FLAG_USE_ARMOUR); |
| 604 |
update_priest_flag(new_god, skop, FLAG_USE_SHIELD); |
| 605 |
|
| 606 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 607 |
"You are bathed in %s's aura.", |
| 608 |
new_god->name); |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
if (!object_present_in_ob_by_name(FORCE, "no weapon force", op)) { |
| 618 |
if (worship_forbids_use(op, skop, FLAG_USE_WEAPON, "weapons")) |
| 619 |
stop_using_item(op, WEAPON, 2); |
| 620 |
} |
| 621 |
update_priest_flag(new_god, skop, FLAG_USE_ARMOUR); |
| 622 |
|
| 623 |
if (worship_forbids_use(op, skop, FLAG_USE_ARMOUR, "armour")) { |
| 624 |
stop_using_item(op, ARMOUR, 1); |
| 625 |
stop_using_item(op, HELMET, 1); |
| 626 |
stop_using_item(op, BOOTS, 1); |
| 627 |
stop_using_item(op, GLOVES, 1); |
| 628 |
} |
| 629 |
|
| 630 |
if (worship_forbids_use(op, skop, FLAG_USE_SHIELD, "shield")) |
| 631 |
stop_using_item(op, SHIELD, 1); |
| 632 |
|
| 633 |
SET_FLAG(skop, FLAG_APPLIED); |
| 634 |
(void)change_abil(op, skop); |
| 635 |
|
| 636 |
|
| 637 |
if (!sk_applied) |
| 638 |
CLEAR_FLAG(skop, FLAG_APPLIED); |
| 639 |
|
| 640 |
return 1; |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string) { |
| 657 |
if (QUERY_FLAG(&op->arch->clone, flag)) { |
| 658 |
if (QUERY_FLAG(op, flag) != QUERY_FLAG(exp_obj, flag)) { |
| 659 |
update_priest_flag(exp_obj, op, flag); |
| 660 |
if (QUERY_FLAG(op, flag)) |
| 661 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 662 |
"You may use %s again.", |
| 663 |
string); |
| 664 |
else { |
| 665 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 666 |
"You are forbidden to use %s.", |
| 667 |
string); |
| 668 |
return 1; |
| 669 |
} |
| 670 |
} |
| 671 |
} |
| 672 |
return 0; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
static void stop_using_item(object *op, int type, int number) { |
| 687 |
FOR_INV_PREPARE(op, tmp) |
| 688 |
if (tmp->type == type && QUERY_FLAG(tmp, FLAG_APPLIED)) { |
| 689 |
apply_special(op, tmp, AP_UNAPPLY|AP_IGNORE_CURSE); |
| 690 |
number--; |
| 691 |
if (number <= 0) |
| 692 |
break; |
| 693 |
} |
| 694 |
FOR_INV_FINISH(); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag) { |
| 710 |
if (QUERY_FLAG(god, flag) && !QUERY_FLAG(exp_ob, flag)) |
| 711 |
SET_FLAG(exp_ob, flag); |
| 712 |
else if (QUERY_FLAG(exp_ob, flag) && !QUERY_FLAG(god, flag)) { |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
CLEAR_FLAG(exp_ob, flag); |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
archetype *determine_holy_arch(const object *god, const char *type) { |
| 742 |
treasure *tr; |
| 743 |
int count; |
| 744 |
object *item; |
| 745 |
|
| 746 |
if (!god || !god->randomitems) { |
| 747 |
LOG(llevError, "BUG: determine_holy_arch(): no god or god without randomitems\n"); |
| 748 |
return NULL; |
| 749 |
} |
| 750 |
|
| 751 |
count = 0; |
| 752 |
for (tr = god->randomitems->items; tr != NULL; tr = tr->next) { |
| 753 |
if (!tr->item) |
| 754 |
continue; |
| 755 |
item = &tr->item->clone; |
| 756 |
if (item->type == BOOK && item->invisible && item->name == type) |
| 757 |
count++; |
| 758 |
} |
| 759 |
if (count == 0) { |
| 760 |
return NULL; |
| 761 |
} |
| 762 |
|
| 763 |
count = rndm(1, count); |
| 764 |
|
| 765 |
for (tr = god->randomitems->items; tr != NULL; tr = tr->next) { |
| 766 |
if (!tr->item) |
| 767 |
continue; |
| 768 |
item = &tr->item->clone; |
| 769 |
if (item->type == BOOK && item->invisible && item->name == type) { |
| 770 |
count--; |
| 771 |
if (count == 0) |
| 772 |
return item->other_arch; |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
return NULL; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
static int god_removes_curse(object *op, int remove_damnation) { |
| 790 |
int success = 0; |
| 791 |
|
| 792 |
FOR_INV_PREPARE(op, tmp) { |
| 793 |
if (tmp->invisible) |
| 794 |
continue; |
| 795 |
if (QUERY_FLAG(tmp, FLAG_DAMNED) && !remove_damnation) |
| 796 |
continue; |
| 797 |
if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { |
| 798 |
success = 1; |
| 799 |
CLEAR_FLAG(tmp, FLAG_DAMNED); |
| 800 |
CLEAR_FLAG(tmp, FLAG_CURSED); |
| 801 |
CLEAR_FLAG(tmp, FLAG_KNOWN_CURSED); |
| 802 |
if (op->type == PLAYER) |
| 803 |
esrv_update_item(UPD_FLAGS, op, tmp); |
| 804 |
} |
| 805 |
} FOR_INV_FINISH(); |
| 806 |
|
| 807 |
if (success) |
| 808 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 809 |
"You feel like someone is helping you."); |
| 810 |
return success; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
static int follower_level_to_enchantments(int level, int difficulty) { |
| 823 |
if (difficulty < 1) { |
| 824 |
LOG(llevError, "follower_level_to_enchantments(): difficulty %d is invalid\n", difficulty); |
| 825 |
return 0; |
| 826 |
} |
| 827 |
|
| 828 |
if (level <= 20) |
| 829 |
return level/difficulty; |
| 830 |
if (level <= 40) |
| 831 |
return (20+(level-20)/2)/difficulty; |
| 832 |
return (30+(level-40)/4)/difficulty; |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
static int improve_weapon_magic(object *op, object *tr, object *weapon, object *skill) { |
| 854 |
int tmp = follower_level_to_enchantments(skill->level, tr->level); |
| 855 |
|
| 856 |
if (weapon->magic < tmp) { |
| 857 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 858 |
"A phosphorescent glow envelops your weapon!"); |
| 859 |
weapon->magic++; |
| 860 |
if (op->type == PLAYER) |
| 861 |
esrv_update_item(UPD_NAME, op, weapon); |
| 862 |
weapon->item_power++; |
| 863 |
return 1; |
| 864 |
} |
| 865 |
|
| 866 |
return 0; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
static int god_enchants_weapon(object *op, const object *god, object *tr, object *skill) { |
| 887 |
char buf[MAX_BUF]; |
| 888 |
object *weapon; |
| 889 |
uint32_t attacktype; |
| 890 |
|
| 891 |
weapon = object_find_by_type_applied(op, WEAPON); |
| 892 |
if (weapon == NULL) |
| 893 |
weapon = object_find_by_type_applied(op, BOW); |
| 894 |
if (weapon == NULL || god_examines_item(god, weapon) <= 0) |
| 895 |
return 0; |
| 896 |
|
| 897 |
if (weapon->item_power >= MAX_WEAPON_ITEM_POWER) { |
| 898 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 899 |
"%s considers your %s is not worthy to be enchanted any more.", |
| 900 |
god->name, |
| 901 |
weapon->name); |
| 902 |
return 0; |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
if (settings.personalized_blessings) { |
| 913 |
const char *divine_owner = object_get_value(weapon, "divine_blessing_name"); |
| 914 |
const char *owner = object_get_value(weapon, "item_owner"); |
| 915 |
object *skillop = NULL; |
| 916 |
|
| 917 |
if (divine_owner != NULL && strcmp(divine_owner, god->name) != 0) { |
| 918 |
|
| 919 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 920 |
"Your %s already belongs to %s !", |
| 921 |
weapon->name, divine_owner); |
| 922 |
return 0; |
| 923 |
} |
| 924 |
|
| 925 |
if ((owner != NULL) && (strcmp(owner, op->name) != 0)) { |
| 926 |
|
| 927 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 928 |
"The %s is not yours, and is magically protected against such changes !", |
| 929 |
weapon->name); |
| 930 |
return 0; |
| 931 |
} |
| 932 |
skillop = find_skill_by_number(op, SK_PRAYING); |
| 933 |
if (skillop == NULL) { |
| 934 |
LOG(llevError, "god_enchants_weapon: no praying skill object found ?!\n"); |
| 935 |
snprintf(buf, sizeof(buf), "%d", 1); |
| 936 |
} else |
| 937 |
snprintf(buf, sizeof(buf), "%"FMT64, skillop->stats.exp); |
| 938 |
object_set_value(weapon, "divine_blessing_name", god->name, TRUE); |
| 939 |
object_set_value(weapon, "item_owner", op->name, TRUE); |
| 940 |
object_set_value(weapon, "item_willpower", buf, TRUE); |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
if (!weapon->title) { |
| 945 |
snprintf(buf, sizeof(buf), "of %s", god->name); |
| 946 |
weapon->title = add_string(buf); |
| 947 |
if (op->type == PLAYER) |
| 948 |
esrv_update_item(UPD_NAME, op, weapon); |
| 949 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 950 |
"Your weapon quivers as if struck!"); |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
if (!weapon->slaying && god->slaying) { |
| 955 |
weapon->slaying = add_string(god->slaying); |
| 956 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 957 |
"Your %s now hungers to slay enemies of your god!", |
| 958 |
weapon->name); |
| 959 |
weapon->item_power++; |
| 960 |
return 1; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
attacktype = (weapon->attacktype == 0) ? AT_PHYSICAL : weapon->attacktype; |
| 965 |
if ((attacktype&god->attacktype) != god->attacktype) { |
| 966 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 967 |
"Your weapon suddenly glows!"); |
| 968 |
weapon->attacktype = attacktype|god->attacktype; |
| 969 |
weapon->item_power++; |
| 970 |
return 1; |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
return improve_weapon_magic(op, tr, weapon, skill); |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
static void god_intervention(object *op, const object *god, object *skill, object *altar) { |
| 993 |
treasure *tr; |
| 994 |
|
| 995 |
if (!god || !god->randomitems) { |
| 996 |
LOG(llevError, "BUG: god_intervention(): no god or god without randomitems\n"); |
| 997 |
return; |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
if (god_examines_priest(op, god) < 0) |
| 1002 |
return; |
| 1003 |
|
| 1004 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1005 |
"You feel a holy presence!"); |
| 1006 |
|
| 1007 |
if (altar->anim_suffix != NULL) |
| 1008 |
apply_anim_suffix(altar, altar->anim_suffix); |
| 1009 |
|
| 1010 |
for (tr = god->randomitems->items; tr != NULL; tr = tr->next) { |
| 1011 |
object *item; |
| 1012 |
|
| 1013 |
if (tr->chance <= random_roll(0, 99, op, PREFER_HIGH)) |
| 1014 |
continue; |
| 1015 |
|
| 1016 |
|
| 1017 |
if (tr->name) { |
| 1018 |
treasurelist *tl = find_treasurelist(tr->name); |
| 1019 |
if (tl == NULL) |
| 1020 |
continue; |
| 1021 |
|
| 1022 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD, |
| 1023 |
"Something appears before your eyes. You catch it before it falls to the ground."); |
| 1024 |
|
| 1025 |
create_treasure(tl, op, GT_STARTEQUIP|GT_ONLY_GOOD|GT_UPDATE_INV, skill->level, 0); |
| 1026 |
return; |
| 1027 |
} |
| 1028 |
|
| 1029 |
if (!tr->item) { |
| 1030 |
LOG(llevError, "BUG: empty entry in %s's treasure list\n", god->name); |
| 1031 |
continue; |
| 1032 |
} |
| 1033 |
item = &tr->item->clone; |
| 1034 |
|
| 1035 |
|
| 1036 |
if (item->type == BOOK && item->invisible |
| 1037 |
&& strcmp(item->name, "grace limit") == 0) { |
| 1038 |
if (op->stats.grace < item->stats.grace |
| 1039 |
|| op->stats.grace < op->stats.maxgrace) { |
| 1040 |
object *tmp; |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
tmp = create_archetype(HOLY_POSSESSION); |
| 1046 |
cast_change_ability(op, op, tmp, 0, 1); |
| 1047 |
object_free_drop_inventory(tmp); |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
continue; |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
if (item->type == BOOK && item->invisible |
| 1055 |
&& strcmp(item->name, "restore grace") == 0) { |
| 1056 |
if (op->stats.grace >= 0) |
| 1057 |
continue; |
| 1058 |
op->stats.grace = random_roll(0, 9, op, PREFER_HIGH); |
| 1059 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1060 |
"You are returned to a state of grace."); |
| 1061 |
return; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
if (item->type == BOOK && item->invisible |
| 1066 |
&& strcmp(item->name, "restore hitpoints") == 0) { |
| 1067 |
if (op->stats.hp >= op->stats.maxhp) |
| 1068 |
continue; |
| 1069 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1070 |
"A white light surrounds and heals you!"); |
| 1071 |
op->stats.hp = op->stats.maxhp; |
| 1072 |
return; |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
if (item->type == BOOK |
| 1077 |
&& item->invisible |
| 1078 |
&& strcmp(item->name, "restore spellpoints") == 0) { |
| 1079 |
int max = op->stats.maxsp*(item->stats.maxsp/100.0); |
| 1080 |
|
| 1081 |
int new_sp = random_roll(1000, 1999, op, PREFER_HIGH)/2000.0*max; |
| 1082 |
if (op->stats.sp >= max/2) |
| 1083 |
continue; |
| 1084 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1085 |
"A blue lightning strikes your head but doesn't hurt you!"); |
| 1086 |
op->stats.sp = new_sp; |
| 1087 |
} |
| 1088 |
|
| 1089 |
|
| 1090 |
if (item->type == BOOK && item->invisible |
| 1091 |
&& strcmp(item->name, "heal spell") == 0) { |
| 1092 |
object *tmp; |
| 1093 |
int success; |
| 1094 |
|
| 1095 |
tmp = create_archetype_by_object_name(item->slaying); |
| 1096 |
|
| 1097 |
success = cast_heal(op, op, tmp, 0); |
| 1098 |
object_free_drop_inventory(tmp); |
| 1099 |
if (success) |
| 1100 |
return; |
| 1101 |
|
| 1102 |
continue; |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
if (item->type == BOOK && item->invisible |
| 1107 |
&& strcmp(item->name, "remove curse") == 0) { |
| 1108 |
if (god_removes_curse(op, 0)) |
| 1109 |
return; |
| 1110 |
|
| 1111 |
continue; |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
if (item->type == BOOK && item->invisible |
| 1116 |
&& strcmp(item->name, "remove damnation") == 0) { |
| 1117 |
if (god_removes_curse(op, 1)) |
| 1118 |
return; |
| 1119 |
|
| 1120 |
continue; |
| 1121 |
} |
| 1122 |
|
| 1123 |
|
| 1124 |
if (item->type == BOOK && item->invisible |
| 1125 |
&& strcmp(item->name, "heal depletion") == 0) { |
| 1126 |
if (remove_depletion(op, -1)) { |
| 1127 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1128 |
"Shimmering light surrounds and restores you!"); |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
if (item->type == BOOK && item->invisible |
| 1134 |
&& strcmp(item->name, "voice_behind") == 0) { |
| 1135 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1136 |
"You hear a voice from behind you, but you don't dare to " |
| 1137 |
"turn around:"); |
| 1138 |
draw_ext_info(NDI_WHITE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1139 |
item->msg); |
| 1140 |
return; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
if (item->type == BOOK && item->invisible |
| 1145 |
&& strcmp(item->name, "message") == 0) { |
| 1146 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1147 |
item->msg); |
| 1148 |
return; |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
if (item->type == BOOK && item->invisible |
| 1153 |
&& strcmp(item->name, "enchant weapon") == 0) { |
| 1154 |
if (god_enchants_weapon(op, god, item, skill)) |
| 1155 |
return; |
| 1156 |
|
| 1157 |
continue; |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
if (item->type == SPELL) { |
| 1162 |
if (check_spell_known(op, item->name)) |
| 1163 |
continue; |
| 1164 |
if (item->level > skill->level) |
| 1165 |
continue; |
| 1166 |
|
| 1167 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1168 |
"%s grants you use of a special prayer!", |
| 1169 |
god->name); |
| 1170 |
do_learn_spell(op, item, 1); |
| 1171 |
return; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
if (!item->invisible) { |
| 1176 |
if (god_gives_present(op, god, tr)) |
| 1177 |
return; |
| 1178 |
|
| 1179 |
continue; |
| 1180 |
} |
| 1181 |
|
| 1182 |
} |
| 1183 |
|
| 1184 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, |
| 1185 |
"You feel rapture."); |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
static int god_examines_priest(object *op, const object *god) { |
| 1201 |
int reaction = 1; |
| 1202 |
object *skop; |
| 1203 |
|
| 1204 |
FOR_INV_PREPARE(op, item) |
| 1205 |
if (QUERY_FLAG(item, FLAG_APPLIED)) { |
| 1206 |
reaction += god_examines_item(god, item)*(item->magic ? abs(item->magic) : 1); |
| 1207 |
} |
| 1208 |
FOR_INV_FINISH(); |
| 1209 |
|
| 1210 |
|
| 1211 |
if (reaction < 0) { |
| 1212 |
int loss = 10000000; |
| 1213 |
int angry = abs(reaction); |
| 1214 |
|
| 1215 |
skop = object_find_by_type_subtype(op, SKILL, SK_PRAYING); |
| 1216 |
if (skop) |
| 1217 |
loss = 0.05*(float)skop->stats.exp; |
| 1218 |
change_exp(op, -random_roll(0, loss*angry-1, op, PREFER_LOW), skop ? skop->skill : "none", SK_SUBTRACT_SKILL_EXP); |
| 1219 |
if (random_roll(0, angry, op, PREFER_LOW)) { |
| 1220 |
object *tmp = create_archetype(LOOSE_MANA); |
| 1221 |
|
| 1222 |
cast_magic_storm(op, tmp, op->level+(angry*3)); |
| 1223 |
} |
| 1224 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 1225 |
"%s becomes angry and punishes you!", |
| 1226 |
god->name); |
| 1227 |
} |
| 1228 |
return reaction; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
static int god_examines_item(const object *god, object *item) { |
| 1248 |
char buf[MAX_BUF]; |
| 1249 |
|
| 1250 |
if (!god || !item) |
| 1251 |
return 0; |
| 1252 |
|
| 1253 |
if (!item->title) |
| 1254 |
return 1; |
| 1255 |
|
| 1256 |
snprintf(buf, sizeof(buf), "of %s", god->name); |
| 1257 |
if (!strcmp(item->title, buf)) |
| 1258 |
return 1; |
| 1259 |
|
| 1260 |
if (god->title) { |
| 1261 |
snprintf(buf, sizeof(buf), "of %s", god->title); |
| 1262 |
if (!strcmp(item->title, buf)) { |
| 1263 |
if (item->env) { |
| 1264 |
char name[MAX_BUF]; |
| 1265 |
|
| 1266 |
query_name(item, name, MAX_BUF); |
| 1267 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, item->env, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 1268 |
"Heretic! You are using %s!", |
| 1269 |
name); |
| 1270 |
} |
| 1271 |
return -1; |
| 1272 |
} |
| 1273 |
} |
| 1274 |
return 0; |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
static const char *get_god_for_race(const char *race) { |
| 1288 |
godlink *gl = first_god; |
| 1289 |
const char *godname = NULL; |
| 1290 |
|
| 1291 |
if (race == NULL) |
| 1292 |
return NULL; |
| 1293 |
while (gl) { |
| 1294 |
if (gl->arch->clone.race && !strcasecmp(gl->arch->clone.race, race)) { |
| 1295 |
godname = gl->name; |
| 1296 |
break; |
| 1297 |
} |
| 1298 |
gl = gl->next; |
| 1299 |
} |
| 1300 |
return godname; |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
int tailor_god_spell(object *spellop, object *caster) { |
| 1315 |
const object *god = find_god(determine_god(caster)); |
| 1316 |
int caster_is_spell = 0; |
| 1317 |
|
| 1318 |
if (caster->type == SPELL_EFFECT || caster->type == SPELL) |
| 1319 |
caster_is_spell = 1; |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
if (!god && object_get_owner(caster)) |
| 1326 |
god = find_god(determine_god(object_get_owner(caster))); |
| 1327 |
|
| 1328 |
if (!god || (spellop->attacktype&AT_HOLYWORD && !god->race)) { |
| 1329 |
if (!caster_is_spell) |
| 1330 |
draw_ext_info(NDI_UNIQUE, 0, caster, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, |
| 1331 |
"This prayer is useless unless you worship an appropriate god"); |
| 1332 |
else |
| 1333 |
LOG(llevError, "BUG: tailor_god_spell(): no god\n"); |
| 1334 |
object_free_drop_inventory(spellop); |
| 1335 |
return 0; |
| 1336 |
} |
| 1337 |
|
| 1338 |
|
| 1339 |
if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) { |
| 1340 |
if (spellop->slaying) { |
| 1341 |
free_string(spellop->slaying); |
| 1342 |
spellop->slaying = NULL; |
| 1343 |
} |
| 1344 |
if (!caster_is_spell) |
| 1345 |
spellop->slaying = god->slaying ? add_string(god->slaying) : NULL; |
| 1346 |
else if (caster->slaying) |
| 1347 |
spellop->slaying = add_string(caster->slaying); |
| 1348 |
} |
| 1349 |
|
| 1350 |
|
| 1351 |
if (spellop->attacktype&AT_GODPOWER) |
| 1352 |
spellop->attacktype = spellop->attacktype|god->attacktype; |
| 1353 |
|
| 1354 |
|
| 1355 |
if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) { |
| 1356 |
if (spellop->title) |
| 1357 |
free_string(spellop->title); |
| 1358 |
spellop->title = add_string(god->name); |
| 1359 |
if (spellop->title) { |
| 1360 |
char buf[MAX_BUF]; |
| 1361 |
|
| 1362 |
snprintf(buf, sizeof(buf), "%s of %s", spellop->name, spellop->title); |
| 1363 |
FREE_AND_COPY(spellop->name, buf); |
| 1364 |
FREE_AND_COPY(spellop->name_pl, buf); |
| 1365 |
} |
| 1366 |
} |
| 1367 |
|
| 1368 |
return 1; |
| 1369 |
} |