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.50 by root, Fri Nov 6 12:27:06 2009 UTC

222 222
223 return 1; 223 return 1;
224} 224}
225 225
226/** 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}
326
327/**
328 * Removes special prayers given by a god. 227 * Removes special prayers given by a god.
329 */ 228 */
330static void 229static void
331check_special_prayers (object *op, object *god) 230check_special_prayers (object *op, object *god)
332{ 231{
378 } 277 }
379 278
380 if (remove) 279 if (remove)
381 do_forget_spell (op, tmp->name); 280 do_forget_spell (op, tmp->name);
382 } 281 }
282}
283
284/**
285 * Unapplies up to number worth of items of type
286 */
287void
288stop_using_item (object *op, int type, int number)
289{
290 object *tmp;
291
292 for (tmp = op->inv; tmp && number; tmp = tmp->below)
293 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
294 {
295 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
296 number--;
297 }
298}
299
300/**
301 * If the god does/doesnt have this flag, we
302 * give/remove it from the experience object if it doesnt/does
303 * already exist. For players only!
304 */
305static void
306update_priest_flag (object *god, object *exp_ob, uint32 flag)
307{
308 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
309 SET_FLAG (exp_ob, flag);
310 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
311 {
312 /* When this is called with the exp_ob set to the player,
313 * this check is broken, because most all players arch
314 * allow use of weapons. I'm not actually sure why this
315 * check is here - I guess if you had a case where the
316 * value in the archetype (wisdom) should over ride the restrictions
317 * the god places on it, this may make sense. But I don't think
318 * there is any case like that.
319 */
320
321/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
322 CLEAR_FLAG (exp_ob, flag);
323 };
324}
325
326/**
327 * Forbids or let player use something item type.
328 * op is the player.
329 * exp_obj is the widsom experience.
330 * flag is the flag to check against.
331 * string is the string to print out.
332 */
333static int
334worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
335{
336 if (QUERY_FLAG (op->arch, flag))
337 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
338 {
339 update_priest_flag (exp_obj, op, flag);
340 if (QUERY_FLAG (op, flag))
341 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
342 else
343 {
344 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
345 return 1;
346 }
347 }
348
349 return 0;
383} 350}
384 351
385/** 352/**
386 * This function is called whenever a player has 353 * This function is called whenever a player has
387 * switched to a new god. It handles basically all the stat changes 354 * switched to a new god. It handles basically all the stat changes
551 CLEAR_FLAG (skop, FLAG_APPLIED); 518 CLEAR_FLAG (skop, FLAG_APPLIED);
552 519
553 check_special_prayers (op, new_god); 520 check_special_prayers (op, new_god);
554} 521}
555 522
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}
625
626archetype * 523archetype *
627determine_holy_arch (object *god, shstr_cmp type) 524determine_holy_arch (object *god, shstr_cmp type)
628{ 525{
629 treasure *tr; 526 treasure *tr;
630 527
699 596
700 return (30 + (level - 40) / 4) / difficulty; 597 return (30 + (level - 40) / 4) / difficulty;
701} 598}
702 599
703/** 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 */
639}
640
641/**
704 * God wants to enchant weapon. 642 * God wants to enchant weapon.
705 * 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
706 * it isn't a weapon for another god. If all is all right, update weapon with 644 * it isn't a weapon for another god. If all is all right, update weapon with
707 * attacktype, slaying and such. 645 * attacktype, slaying and such.
708 */ 646 */
763 701
764 return 0; 702 return 0;
765} 703}
766 704
767/** 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 (QUERY_FLAG (item, 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;
746}
747
748/**
768 * 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.
769 * 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
770 * priest. -b.t. 751 * priest. -b.t.
771 * called from pray_at_altar() currently. 752 * called from pray_at_altar() currently.
772 */ 753 */
773void 754static void
774god_intervention (object *op, object *god, object *skill) 755god_intervention (object *op, object *god, object *skill)
775{ 756{
776 treasure *tr; 757 treasure *tr;
777 758
778 if (!god || !god->randomitems) 759 if (!god || !god->randomitems)
981 962
982 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture."); 963 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture.");
983} 964}
984 965
985/** 966/**
986 * Checks and maybe punishes someone praying. 967 * Player prays at altar.
987 * All applied items are examined, if player is using more items of other gods, 968 * Checks for god changing, divine intervention, and so on.
988 * s/he loses experience in praying or general experience if no praying.
989 */ 969 */
990int 970void
991god_examines_priest (object *op, object *god) 971pray_at_altar (object *pl, object *altar, object *skill)
992{ 972{
993 int reaction = 1; 973 object *pl_god = find_god (determine_god (pl));
994 object *item = NULL, *skop;
995 974
996 for (item = op->inv; item; item = item->below) 975 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; 976 return;
1041 977
1042 if (!item->title) 978 /* If non consecrate altar, don't do anything */
1043 return 1; /* unclaimed item are ok */ 979 if (!altar->other_arch)
980 return;
1044 981
1045 sprintf (buf, "of %s", &god->name); 982 /* hmm. what happend depends on pl's current god, level, etc */
1046 if (!strcmp (&item->title, buf)) 983 if (!pl_god)
1047 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;
1048 993
1049 if (god->title) 994 /* we can get neg grace up faster */
1050 { /* check if we have any enemy blessed item */ 995 if (pl->stats.grace < 0)
1051 sprintf (buf, "of %s", &god->title); 996 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
1052 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.
1053 { 1006 */
1054 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)
1055 { 1028 {
1056 char buf[MAX_BUF]; 1029 object *tmp;
1057 1030
1058 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1031 /* you really screwed up */
1059 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);
1060 } 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);
1061 1042
1062 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
1063 } 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 }
1064 } 1064 }
1065
1066 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1067} 1065}
1068 1066
1069/** 1067/**
1070 * Returns priest's god's id. 1068 * Returns priest's god's id.
1071 * Straight calls lookup_god_by_name 1069 * Straight calls lookup_god_by_name

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines