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