ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/gods.C
(Generate patch)

Comparing deliantra/server/server/gods.C (file contents):
Revision 1.49 by root, Sat Oct 17 21:40:38 2009 UTC vs.
Revision 1.60 by root, Sun Apr 11 00:34:06 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
36#include <sproto.h> 36#include <sproto.h>
37 37
38/** 38/**
39 * Returns the id of specified god. 39 * Returns the id of specified god.
40 */ 40 */
41int 41static int
42lookup_god_by_name (shstr_cmp name) 42lookup_god_by_name (shstr_cmp name)
43{ 43{
44 if (name) 44 if (name)
45 for (godlink *gl = first_god; gl; gl = gl->next) 45 for (godlink *gl = first_god; gl; gl = gl->next)
46 if (gl->name == name) 46 if (gl->name == name)
214 return 0; 214 return 0;
215 215
216 if (follower_has_similar_item (op, tr->item)) 216 if (follower_has_similar_item (op, tr->item))
217 return 0; 217 return 0;
218 218
219 object *tmp = arch_to_object (tr->item); 219 object *tmp = tr->item->instance ();
220 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp)); 220 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp));
221 op->insert (tmp); 221 op->insert (tmp);
222 222
223 return 1; 223 return 1;
224}
225
226/**
227 * Player prays at altar.
228 * Checks for god changing, divine intervention, and so on.
229 */
230void
231pray_at_altar (object *pl, object *altar, object *skill)
232{
233 object *pl_god = find_god (determine_god (pl));
234
235 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
236 return;
237
238 /* If non consecrate altar, don't do anything */
239 if (!altar->other_arch)
240 return;
241
242 /* hmm. what happend depends on pl's current god, level, etc */
243 if (!pl_god)
244 { /*new convert */
245 become_follower (pl, altar->other_arch);
246 return;
247 }
248 else if (pl_god->name == altar->other_arch->object::name)
249 {
250 /* pray at your gods altar */
251 /* this leads to very low levels of wis and pray to result in no doubling! */
252 int bonus = (pl->stats.Wis + skill->level) / 10;
253
254 /* we can get neg grace up faster */
255 if (pl->stats.grace < 0)
256 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
257
258 /* we can super-charge grace to 2x max */
259 if (pl->stats.grace < 2 * pl->stats.maxgrace)
260 pl->stats.grace += bonus / 2;
261 else
262 pl->stats.grace = 2 * pl->stats.maxgrace;
263
264 /* Every once in a while, the god decides to checkup on their
265 * follower, and may intervene to help them out.
266 */
267 bonus = max (1, bonus + max (pl->stats.luck, -3)); /* -- DAMN -- */
268
269 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
270 god_intervention (pl, pl_god, skill);
271 }
272 else
273 { /* praying to another god! */
274 uint64 loss = 0;
275 int angry = 1;
276
277 /* I believe the logic for detecting opposing gods was completely
278 * broken - I think it should work now. altar->other_arch
279 * points to the god of this altar (which we have
280 * already verified is non null). pl_god->other_arch
281 * is the opposing god - we need to verify that exists before
282 * using its values.
283 */
284 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
285 {
286 angry = 2;
287 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
288 {
289 object *tmp;
290
291 /* you really screwed up */
292 angry = 3;
293 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
294 tmp = get_archetype (LOOSE_MANA);
295 cast_magic_storm (pl, tmp, pl_god->level + 20);
296 }
297 else
298 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
299 }
300 else
301 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
302
303 /* whether we will be successfull in defecting or not -
304 * we lose experience from the clerical experience obj
305 */
306
307 loss = angry * (skill->stats.exp / 10);
308 if (loss)
309 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
310
311 /* May switch Gods, but its random chance based on our current level
312 * note it gets harder to swap gods the higher we get
313 */
314 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
315 become_follower (pl, altar->other_arch);
316 else
317 {
318 /* toss this player off the altar. He can try again. */
319 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
320 pl->contr->fire_on = 0;
321 pl->speed_left = 1.f;
322 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
323 }
324 }
325} 224}
326 225
327/** 226/**
328 * Removes special prayers given by a god. 227 * Removes special prayers given by a god.
329 */ 228 */
343 next_tmp = tmp->below; 242 next_tmp = tmp->below;
344 243
345 /* we mark special prayers with the STARTEQUIP flag, so if it isn't 244 /* we mark special prayers with the STARTEQUIP flag, so if it isn't
346 * in that category, not something we need to worry about. 245 * in that category, not something we need to worry about.
347 */ 246 */
348 if (tmp->type != SPELL || !QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 247 if (tmp->type != SPELL || !tmp->flag [FLAG_STARTEQUIP])
349 continue; 248 continue;
350 249
351 if (god->randomitems == NULL) 250 if (god->randomitems == NULL)
352 { 251 {
353 LOG (llevError, "BUG: check_special_prayers(): god %s without randomitems\n", &god->name); 252 LOG (llevError, "BUG: check_special_prayers(): god %s without randomitems\n", &god->name);
381 do_forget_spell (op, tmp->name); 280 do_forget_spell (op, tmp->name);
382 } 281 }
383} 282}
384 283
385/** 284/**
285 * Unapplies up to number worth of items of type
286 */
287static void
288stop_using_item (object *op, int type, int number)
289{
290 for (object *tmp = op->inv; tmp && number; tmp = tmp->below)
291 if (tmp->type == type && tmp->flag [FLAG_APPLIED])
292 {
293 op->apply (tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
294 --number;
295 }
296}
297
298/**
299 * If the god does/doesnt have this flag, we
300 * give/remove it from the experience object if it doesnt/does
301 * already exist. For players only!
302 */
303static void
304update_priest_flag (object *god, object *exp_ob, uint32 flag)
305{
306 if (god->flag [flag] && !exp_ob->flag [flag])
307 exp_ob->flag [flag];
308 else if (exp_ob->flag [flag] && !god->flag [flag])
309 {
310 /* When this is called with the exp_ob set to the player,
311 * this check is broken, because most all players arch
312 * allow use of weapons. I'm not actually sure why this
313 * check is here - I guess if you had a case where the
314 * value in the archetype (wisdom) should over ride the restrictions
315 * the god places on it, this may make sense. But I don't think
316 * there is any case like that.
317 */
318
319/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
320 exp_ob->clr_flag (flag);
321 };
322}
323
324/**
325 * Forbids or let player use something item type.
326 * op is the player.
327 * exp_obj is the widsom experience.
328 * flag is the flag to check against.
329 * string is the string to print out.
330 */
331static int
332worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
333{
334 if (op->arch->flag [flag])
335 if (op->flag [flag] != exp_obj->flag [flag])
336 {
337 update_priest_flag (exp_obj, op, flag);
338 if (op->flag [flag])
339 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
340 else
341 {
342 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
343 return 1;
344 }
345 }
346
347 return 0;
348}
349
350/**
386 * This function is called whenever a player has 351 * This function is called whenever a player has
387 * switched to a new god. It handles basically all the stat changes 352 * switched to a new god. It handles basically all the stat changes
388 * that happen to the player, including the removal of godgiven 353 * that happen to the player, including the removal of godgiven
389 * items (from the former cult). 354 * items (from the former cult).
390 */ 355 */
402 for (item = op->inv; item; item = next) 367 for (item = op->inv; item; item = next)
403 { 368 {
404 next = item->below; 369 next = item->below;
405 370
406 // remove all invisible startequip items which are not skill, exp or force 371 // remove all invisible startequip items which are not skill, exp or force
407 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 372 if (item->flag [FLAG_STARTEQUIP] && item->invisible &&
408 (item->type != SKILL) && (item->type != FORCE)) 373 (item->type != SKILL) && (item->type != FORCE))
409 { 374 {
410 if (item->type == SPELL) 375 if (item->type == SPELL)
411 { 376 {
412 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name); 377 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name);
413 esrv_remove_spell (op->contr, item); 378 esrv_remove_spell (op->contr, item);
414 } 379 }
415 380
416 player_unready_range_ob (op->contr, item);
417 item->destroy (); 381 item->destroy ();
418 } 382 }
419 } 383 }
420 384
421 /* remove any godgiven items from the old god */ 385 /* remove any godgiven items from the old god */
422 if (old_god) 386 if (old_god)
423 for (tr = old_god->randomitems->items; tr; tr = tr->next) 387 for (tr = old_god->randomitems->items; tr; tr = tr->next)
424 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP)) 388 if (tr->item && tr->item->flag [FLAG_STARTEQUIP])
425 follower_remove_similar_item (op, tr->item); 389 follower_remove_similar_item (op, tr->item);
426 390
427 if (!op || !new_god) 391 if (!op || !new_god)
428 return; 392 return;
429 393
460 /* The archetype should always be defined - if we crash here because it doesn't, 424 /* The archetype should always be defined - if we crash here because it doesn't,
461 * things are really messed up anyways. 425 * things are really messed up anyways.
462 */ 426 */
463 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill); 427 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill);
464 428
465 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 429 sk_applied = skop->flag [FLAG_APPLIED]; /* save skill status */
466 430
467 /* Clear the "undead" status. We also need to force a call to change_abil, 431 /* Clear the "undead" status. We also need to force a call to change_abil,
468 * so I set undeadified for that. 432 * so I set undeadified for that.
469 * - gros, 21th July 2006. 433 * - gros, 21th July 2006.
470 */ 434 */
471 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD)) 435 if (old_god && old_god->flag [FLAG_UNDEAD])
472 { 436 {
473 CLEAR_FLAG (skop, FLAG_UNDEAD); 437 skop->clr_flag (FLAG_UNDEAD);
474 undeadified = 1; 438 undeadified = 1;
475 } 439 }
476 440
477 if (skop->title) 441 if (skop->title)
478 { 442 {
480 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title); 444 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title);
481 445
482 /* The point of this is to really show what abilities the player just lost */ 446 /* The point of this is to really show what abilities the player just lost */
483 if (sk_applied || undeadified) 447 if (sk_applied || undeadified)
484 { 448 {
485 CLEAR_FLAG (skop, FLAG_APPLIED); 449 skop->clr_flag (FLAG_APPLIED);
486 change_abil (op, skop); 450 change_abil (op, skop);
487 } 451 }
488 } 452 }
489 453
490 /* now change to the new gods attributes to exp_obj */ 454 /* now change to the new gods attributes to exp_obj */
541 stop_using_item (op, BOOTS, 1); 505 stop_using_item (op, BOOTS, 1);
542 stop_using_item (op, GLOVES, 1); 506 stop_using_item (op, GLOVES, 1);
543 stop_using_item (op, SHIELD, 1); 507 stop_using_item (op, SHIELD, 1);
544 } 508 }
545 509
546 SET_FLAG (skop, FLAG_APPLIED); 510 skop->set_flag (FLAG_APPLIED);
547 (void) change_abil (op, skop); 511 change_abil (op, skop);
548 512
549 /* return to previous skill status */ 513 /* return to previous skill status */
550 if (!sk_applied) 514 if (!sk_applied)
551 CLEAR_FLAG (skop, FLAG_APPLIED); 515 skop->clr_flag (FLAG_APPLIED);
552 516
553 check_special_prayers (op, new_god); 517 check_special_prayers (op, new_god);
554}
555
556/**
557 * Forbids or let player use something item type.
558 * op is the player.
559 * exp_obj is the widsom experience.
560 * flag is the flag to check against.
561 * string is the string to print out.
562 */
563
564int
565worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
566{
567 if (QUERY_FLAG (op->arch, flag))
568 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
569 {
570 update_priest_flag (exp_obj, op, flag);
571 if (QUERY_FLAG (op, flag))
572 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
573 else
574 {
575 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
576 return 1;
577 }
578 }
579
580 return 0;
581}
582
583/**
584 * Unapplies up to number worth of items of type
585 */
586void
587stop_using_item (object *op, int type, int number)
588{
589 object *tmp;
590
591 for (tmp = op->inv; tmp && number; tmp = tmp->below)
592 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
593 {
594 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
595 number--;
596 }
597}
598
599/**
600 * If the god does/doesnt have this flag, we
601 * give/remove it from the experience object if it doesnt/does
602 * already exist. For players only!
603 */
604
605void
606update_priest_flag (object *god, object *exp_ob, uint32 flag)
607{
608 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
609 SET_FLAG (exp_ob, flag);
610 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
611 {
612 /* When this is called with the exp_ob set to the player,
613 * this check is broken, because most all players arch
614 * allow use of weapons. I'm not actually sure why this
615 * check is here - I guess if you had a case where the
616 * value in the archetype (wisdom) should over ride the restrictions
617 * the god places on it, this may make sense. But I don't think
618 * there is any case like that.
619 */
620
621/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
622 CLEAR_FLAG (exp_ob, flag);
623 };
624} 518}
625 519
626archetype * 520archetype *
627determine_holy_arch (object *god, shstr_cmp type) 521determine_holy_arch (object *god, shstr_cmp type)
628{ 522{
659 for (object *tmp = op->inv; tmp; tmp = tmp->below) 553 for (object *tmp = op->inv; tmp; tmp = tmp->below)
660 { 554 {
661 if (tmp->invisible) 555 if (tmp->invisible)
662 continue; 556 continue;
663 557
664 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 558 if (tmp->flag [FLAG_DAMNED] && !remove_damnation)
665 continue; 559 continue;
666 560
667 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 561 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
668 { 562 {
669 success = 1; 563 success = 1;
670 CLEAR_FLAG (tmp, FLAG_DAMNED); 564 tmp->clr_flag (FLAG_DAMNED);
671 CLEAR_FLAG (tmp, FLAG_CURSED); 565 tmp->clr_flag (FLAG_CURSED);
672 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 566 tmp->clr_flag (FLAG_KNOWN_CURSED);
673 567
674 if (object *pl = tmp->visible_to ()) 568 if (object *pl = tmp->visible_to ())
675 esrv_update_item (UPD_FLAGS, pl, tmp); 569 esrv_update_item (UPD_FLAGS, pl, tmp);
676 } 570 }
677 } 571 }
696 590
697 if (level <= 40) 591 if (level <= 40)
698 return (20 + (level - 20) / 2) / difficulty; 592 return (20 + (level - 20) / 2) / difficulty;
699 593
700 return (30 + (level - 40) / 4) / difficulty; 594 return (30 + (level - 40) / 4) / difficulty;
595}
596
597/**
598 * God checks item the player is using.
599 * Return either -1 (bad), 0 (neutral) or
600 * 1 (item is ok). If you are using the item of an enemy
601 * god, it can be bad...-b.t.
602 */
603static int
604god_examines_item (object *god, object *item)
605{
606 char buf[MAX_BUF];
607
608 if (!god || !item)
609 return 0;
610
611 if (!item->title)
612 return 1; /* unclaimed item are ok */
613
614 sprintf (buf, "of %s", &god->name);
615 if (!strcmp (&item->title, buf))
616 return 1; /* belongs to that God */
617
618 if (god->title)
619 { /* check if we have any enemy blessed item */
620 sprintf (buf, "of %s", &god->title);
621 if (!strcmp (&item->title, buf))
622 {
623 if (item->env)
624 {
625 char buf[MAX_BUF];
626
627 sprintf (buf, "Heretic! You are using %s!", query_name (item));
628 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
629 }
630
631 return -1;
632 }
633 }
634
635 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
701} 636}
702 637
703/** 638/**
704 * God wants to enchant weapon. 639 * God wants to enchant weapon.
705 * Affected weapon is the applied one (weapon or bow). It's checked to make sure 640 * Affected weapon is the applied one (weapon or bow). It's checked to make sure
712 object *weapon; 647 object *weapon;
713 uint32 attacktype; 648 uint32 attacktype;
714 int tmp; 649 int tmp;
715 650
716 for (weapon = op->inv; weapon; weapon = weapon->below) 651 for (weapon = op->inv; weapon; weapon = weapon->below)
717 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED)) 652 if ((weapon->type == WEAPON || weapon->type == BOW) && weapon->flag [FLAG_APPLIED])
718 break; 653 break;
719 654
720 if (!weapon || god_examines_item (god, weapon) <= 0) 655 if (!weapon || god_examines_item (god, weapon) <= 0)
721 return 0; 656 return 0;
722 657
760 695
761 return 1; 696 return 1;
762 } 697 }
763 698
764 return 0; 699 return 0;
700}
701
702/**
703 * Checks and maybe punishes someone praying.
704 * All applied items are examined, if player is using more items of other gods,
705 * s/he loses experience in praying or general experience if no praying.
706 */
707static int
708god_examines_priest (object *op, object *god)
709{
710 int reaction = 1;
711 object *item = NULL, *skop;
712
713 for (item = op->inv; item; item = item->below)
714 if (item->flag [FLAG_APPLIED])
715 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
716
717 /* well, well. Looks like we screwed up. Time for god's revenge */
718 if (reaction < 0)
719 {
720 int loss = 10000000;
721 int angry = abs (reaction);
722
723 for (skop = op->inv; skop; skop = skop->below)
724 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
725 break;
726
727 if (skop)
728 loss = 0.05f * skop->stats.exp;
729
730 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
731
732 if (random_roll (0, angry, op, PREFER_LOW))
733 {
734 object *tmp = get_archetype (LOOSE_MANA);
735
736 cast_magic_storm (op, tmp, op->level + (angry * 3));
737 }
738
739 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
740 }
741
742 return reaction;
765} 743}
766 744
767/** 745/**
768 * Every once in a while the god will intervene to help the worshiper. 746 * Every once in a while the god will intervene to help the worshiper.
769 * Later, this fctn can be used to supply quests, etc for the 747 * Later, this fctn can be used to supply quests, etc for the
770 * priest. -b.t. 748 * priest. -b.t.
771 * called from pray_at_altar() currently. 749 * called from pray_at_altar() currently.
772 */ 750 */
773void 751static void
774god_intervention (object *op, object *god, object *skill) 752god_intervention (object *op, object *god, object *skill)
775{ 753{
776 treasure *tr; 754 treasure *tr;
777 755
778 if (!god || !god->randomitems) 756 if (!god || !god->randomitems)
906 { 884 {
907 object *depl; 885 object *depl;
908 archetype *at; 886 archetype *at;
909 int i; 887 int i;
910 888
911 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 889 if ((at = archetype::find (shstr_depletion)) == NULL)
912 { 890 {
913 LOG (llevError, "Could not find archetype depletion.\n"); 891 LOG (llevError, "Could not find archetype depletion.\n");
914 continue; 892 continue;
915 } 893 }
916 894
981 959
982 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture."); 960 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture.");
983} 961}
984 962
985/** 963/**
986 * Checks and maybe punishes someone praying. 964 * Player prays at altar.
987 * All applied items are examined, if player is using more items of other gods, 965 * Checks for god changing, divine intervention, and so on.
988 * s/he loses experience in praying or general experience if no praying.
989 */ 966 */
990int 967void
991god_examines_priest (object *op, object *god) 968pray_at_altar (object *pl, object *altar, object *skill)
992{ 969{
993 int reaction = 1; 970 object *pl_god = find_god (determine_god (pl));
994 object *item = NULL, *skop;
995 971
996 for (item = op->inv; item; item = item->below) 972 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
997 if (QUERY_FLAG (item, FLAG_APPLIED))
998 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
999
1000 /* well, well. Looks like we screwed up. Time for god's revenge */
1001 if (reaction < 0)
1002 {
1003 int loss = 10000000;
1004 int angry = abs (reaction);
1005
1006 for (skop = op->inv; skop; skop = skop->below)
1007 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1008 break;
1009
1010 if (skop)
1011 loss = 0.05f * skop->stats.exp;
1012
1013 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1014
1015 if (random_roll (0, angry, op, PREFER_LOW))
1016 {
1017 object *tmp = get_archetype (LOOSE_MANA);
1018
1019 cast_magic_storm (op, tmp, op->level + (angry * 3));
1020 }
1021
1022 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1023 }
1024
1025 return reaction;
1026}
1027
1028/**
1029 * God checks item the player is using.
1030 * Return either -1 (bad), 0 (neutral) or
1031 * 1 (item is ok). If you are using the item of an enemy
1032 * god, it can be bad...-b.t.
1033 */
1034int
1035god_examines_item (object *god, object *item)
1036{
1037 char buf[MAX_BUF];
1038
1039 if (!god || !item)
1040 return 0; 973 return;
1041 974
1042 if (!item->title) 975 /* If non consecrate altar, don't do anything */
1043 return 1; /* unclaimed item are ok */ 976 if (!altar->other_arch)
977 return;
1044 978
1045 sprintf (buf, "of %s", &god->name); 979 /* hmm. what happend depends on pl's current god, level, etc */
1046 if (!strcmp (&item->title, buf)) 980 if (!pl_god)
1047 return 1; /* belongs to that God */ 981 { /*new convert */
982 become_follower (pl, altar->other_arch);
983 return;
984 }
985 else if (pl_god->name == altar->other_arch->object::name)
986 {
987 /* pray at your gods altar */
988 /* this leads to very low levels of wis and pray to result in no doubling! */
989 int bonus = (pl->stats.Wis + skill->level) / 10;
1048 990
1049 if (god->title) 991 /* we can get neg grace up faster */
1050 { /* check if we have any enemy blessed item */ 992 if (pl->stats.grace < 0)
1051 sprintf (buf, "of %s", &god->title); 993 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
1052 if (!strcmp (&item->title, buf)) 994
995 /* we can super-charge grace to 2x max */
996 if (pl->stats.grace < 2 * pl->stats.maxgrace)
997 pl->stats.grace += bonus / 2;
998 else
999 pl->stats.grace = 2 * pl->stats.maxgrace;
1000
1001 /* Every once in a while, the god decides to checkup on their
1002 * follower, and may intervene to help them out.
1053 { 1003 */
1054 if (item->env) 1004 bonus = max (1, bonus + max (pl->stats.luck, -3)); /* -- DAMN -- */
1005
1006 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
1007 god_intervention (pl, pl_god, skill);
1008 }
1009 else
1010 { /* praying to another god! */
1011 uint64 loss = 0;
1012 int angry = 1;
1013
1014 /* I believe the logic for detecting opposing gods was completely
1015 * broken - I think it should work now. altar->other_arch
1016 * points to the god of this altar (which we have
1017 * already verified is non null). pl_god->other_arch
1018 * is the opposing god - we need to verify that exists before
1019 * using its values.
1020 */
1021 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
1022 {
1023 angry = 2;
1024 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
1055 { 1025 {
1056 char buf[MAX_BUF]; 1026 object *tmp;
1057 1027
1058 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1028 /* you really screwed up */
1059 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1029 angry = 3;
1030 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
1031 tmp = get_archetype (LOOSE_MANA);
1032 cast_magic_storm (pl, tmp, pl_god->level + 20);
1060 } 1033 }
1034 else
1035 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
1036 }
1037 else
1038 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
1061 1039
1062 return -1; 1040 /* whether we will be successfull in defecting or not -
1041 * we lose experience from the clerical experience obj
1042 */
1043
1044 loss = angry * (skill->stats.exp / 10);
1045 if (loss)
1046 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
1047
1048 /* May switch Gods, but its random chance based on our current level
1049 * note it gets harder to swap gods the higher we get
1050 */
1051 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
1052 become_follower (pl, altar->other_arch);
1053 else
1063 } 1054 {
1055 /* toss this player off the altar. He can try again. */
1056 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
1057 pl->contr->fire_on = 0;
1058 pl->speed_left = 1.f;
1059 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
1060 }
1064 } 1061 }
1065
1066 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1067}
1068
1069/**
1070 * Returns priest's god's id.
1071 * Straight calls lookup_god_by_name
1072 */
1073int
1074get_god (object *priest)
1075{
1076 return lookup_god_by_name (determine_god (priest));
1077} 1062}
1078 1063
1079/** 1064/**
1080 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1065 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1081 * Returns false if there was no race to assign to the slaying field of the spell, but 1066 * Returns false if there was no race to assign to the slaying field of the spell, but

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines