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.41 by root, Wed Dec 31 17:35:37 2008 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 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and 25/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and
35#include <sproto.h> 36#include <sproto.h>
36 37
37/** 38/**
38 * Returns the id of specified god. 39 * Returns the id of specified god.
39 */ 40 */
40int 41static int
41lookup_god_by_name (const char *name) 42lookup_god_by_name (shstr_cmp name)
42{ 43{
43 shstr_cmp sname (name);
44
45 if (sname) 44 if (name)
46 for (godlink *gl = first_god; gl; gl = gl->next) 45 for (godlink *gl = first_god; gl; gl = gl->next)
47 if (gl->name == name) 46 if (gl->name == name)
48 return gl->id; 47 return gl->id;
49 48
50 return -1; 49 return -1;
52 51
53/** 52/**
54 * Returns pointer to specified god's object through pntr_to_god_obj.. 53 * Returns pointer to specified god's object through pntr_to_god_obj..
55 */ 54 */
56object * 55object *
57find_god (const char *name) 56find_god (shstr_cmp name)
58{ 57{
59 if (name) 58 if (name)
60 for (godlink *gl = first_god; gl; gl = gl->next) 59 for (godlink *gl = first_god; gl; gl = gl->next)
61 if (!strcmp (name, gl->name)) 60 if (gl->name == name)
62 return pntr_to_god_obj (gl); 61 return pntr_to_god_obj (gl);
63 62
64 return 0; 63 return 0;
64}
65
66/**
67 * Returns a string that is the name of the god that should be natively worshipped by a
68 * creature of who has race *race
69 * if we can't find a god that is appropriate, we return NULL
70 */
71static shstr_tmp
72get_god_for_race (shstr_cmp race)
73{
74 if (race)
75 for (godlink *gl = first_god; gl; gl = gl->next)
76 if (gl->arch->race == race)
77 return gl->name;
78
79 return shstr_tmp ();
65} 80}
66 81
67/** 82/**
68 * Determines if op worships a god. 83 * Determines if op worships a god.
69 * Returns the godname if they do or "none" if they have no god. 84 * Returns the godname if they do or "none" if they have no god.
88 /* find a random god */ 103 /* find a random god */
89 if (!op->title) 104 if (!op->title)
90 { 105 {
91 int godnr = rndm (1, first_god->id); 106 int godnr = rndm (1, first_god->id);
92 107
93 for (godlink *gl = first_god; gl && gl->id != godnr; gl = gl->next) 108 for (godlink *gl = first_god; gl; gl = gl->next)
94 if (gl->id == godnr) 109 if (gl->id == godnr)
95 { 110 {
96 op->title = gl->name; 111 op->title = gl->name;
97 break; 112 break;
98 } 113 }
199 return 0; 214 return 0;
200 215
201 if (follower_has_similar_item (op, tr->item)) 216 if (follower_has_similar_item (op, tr->item))
202 return 0; 217 return 0;
203 218
204 object *tmp = arch_to_object (tr->item); 219 object *tmp = tr->item->instance ();
205 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));
206 op->insert (tmp); 221 op->insert (tmp);
207 222
208 return 1; 223 return 1;
209}
210
211/**
212 * Player prays at altar.
213 * Checks for god changing, divine intervention, and so on.
214 */
215void
216pray_at_altar (object *pl, object *altar, object *skill)
217{
218 object *pl_god = find_god (determine_god (pl));
219
220 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
221 return;
222
223 /* If non consecrate altar, don't do anything */
224 if (!altar->other_arch)
225 return;
226
227 /* hmm. what happend depends on pl's current god, level, etc */
228 if (!pl_god)
229 { /*new convert */
230 become_follower (pl, altar->other_arch);
231 return;
232 }
233 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
234 {
235 /* pray at your gods altar */
236 int bonus = (pl->stats.Wis + skill->level) / 10;
237
238 /* we can get neg grace up faster */
239 if (pl->stats.grace < 0)
240 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
241
242 /* we can super-charge grace to 2x max */
243 if (pl->stats.grace < 2 * pl->stats.maxgrace)
244 pl->stats.grace += bonus / 2;
245 else
246 pl->stats.grace = 2 * pl->stats.maxgrace;
247
248 /* Every once in a while, the god decides to checkup on their
249 * follower, and may intervene to help them out.
250 */
251 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
252
253 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
254 god_intervention (pl, pl_god, skill);
255 }
256 else
257 { /* praying to another god! */
258 uint64 loss = 0;
259 int angry = 1;
260
261 /* I believe the logic for detecting opposing gods was completely
262 * broken - I think it should work now. altar->other_arch
263 * points to the god of this altar (which we have
264 * already verified is non null). pl_god->other_arch
265 * is the opposing god - we need to verify that exists before
266 * using its values.
267 */
268 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
269 {
270 angry = 2;
271 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
272 {
273 object *tmp;
274
275 /* you really screwed up */
276 angry = 3;
277 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
278 tmp = get_archetype (LOOSE_MANA);
279 cast_magic_storm (pl, tmp, pl_god->level + 20);
280 }
281 else
282 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
283 }
284 else
285 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
286
287 /* whether we will be successfull in defecting or not -
288 * we lose experience from the clerical experience obj
289 */
290
291 loss = angry * (skill->stats.exp / 10);
292 if (loss)
293 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
294
295 /* May switch Gods, but its random chance based on our current level
296 * note it gets harder to swap gods the higher we get
297 */
298 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
299 become_follower (pl, altar->other_arch);
300 else
301 {
302 /* toss this player off the altar. He can try again. */
303 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
304 pl->contr->fire_on = 0;
305 pl->speed_left = 1.f;
306 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
307 }
308 }
309} 224}
310 225
311/** 226/**
312 * Removes special prayers given by a god. 227 * Removes special prayers given by a god.
313 */ 228 */
327 next_tmp = tmp->below; 242 next_tmp = tmp->below;
328 243
329 /* 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
330 * in that category, not something we need to worry about. 245 * in that category, not something we need to worry about.
331 */ 246 */
332 if (tmp->type != SPELL || !QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 247 if (tmp->type != SPELL || !tmp->flag [FLAG_STARTEQUIP])
333 continue; 248 continue;
334 249
335 if (god->randomitems == NULL) 250 if (god->randomitems == NULL)
336 { 251 {
337 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);
365 do_forget_spell (op, tmp->name); 280 do_forget_spell (op, tmp->name);
366 } 281 }
367} 282}
368 283
369/** 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/**
370 * This function is called whenever a player has 351 * This function is called whenever a player has
371 * 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
372 * that happen to the player, including the removal of godgiven 353 * that happen to the player, including the removal of godgiven
373 * items (from the former cult). 354 * items (from the former cult).
374 */ 355 */
386 for (item = op->inv; item; item = next) 367 for (item = op->inv; item; item = next)
387 { 368 {
388 next = item->below; 369 next = item->below;
389 370
390 // 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
391 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 372 if (item->flag [FLAG_STARTEQUIP] && item->invisible &&
392 (item->type != SKILL) && (item->type != FORCE)) 373 (item->type != SKILL) && (item->type != FORCE))
393 { 374 {
394 if (item->type == SPELL) 375 if (item->type == SPELL)
395 { 376 {
396 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);
397 esrv_remove_spell (op->contr, item); 378 esrv_remove_spell (op->contr, item);
398 } 379 }
399 380
400 player_unready_range_ob (op->contr, item);
401 item->destroy (); 381 item->destroy ();
402 } 382 }
403 } 383 }
404 384
405 /* remove any godgiven items from the old god */ 385 /* remove any godgiven items from the old god */
406 if (old_god) 386 if (old_god)
407 for (tr = old_god->randomitems->items; tr; tr = tr->next) 387 for (tr = old_god->randomitems->items; tr; tr = tr->next)
408 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP)) 388 if (tr->item && tr->item->flag [FLAG_STARTEQUIP])
409 follower_remove_similar_item (op, tr->item); 389 follower_remove_similar_item (op, tr->item);
410 390
411 if (!op || !new_god) 391 if (!op || !new_god)
412 return; 392 return;
413 393
414 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 394 if (new_god->slaying && op->race.contains (new_god->slaying))
415 { 395 {
416 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 396 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name);
417 397
418 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 398 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0)
419 { 399 {
444 /* 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,
445 * things are really messed up anyways. 425 * things are really messed up anyways.
446 */ 426 */
447 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);
448 428
449 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 429 sk_applied = skop->flag [FLAG_APPLIED]; /* save skill status */
450 430
451 /* 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,
452 * so I set undeadified for that. 432 * so I set undeadified for that.
453 * - gros, 21th July 2006. 433 * - gros, 21th July 2006.
454 */ 434 */
455 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD)) 435 if (old_god && old_god->flag [FLAG_UNDEAD])
456 { 436 {
457 CLEAR_FLAG (skop, FLAG_UNDEAD); 437 skop->clr_flag (FLAG_UNDEAD);
458 undeadified = 1; 438 undeadified = 1;
459 } 439 }
460 440
461 if (skop->title) 441 if (skop->title)
462 { 442 {
464 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);
465 445
466 /* 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 */
467 if (sk_applied || undeadified) 447 if (sk_applied || undeadified)
468 { 448 {
469 CLEAR_FLAG (skop, FLAG_APPLIED); 449 skop->clr_flag (FLAG_APPLIED);
470 change_abil (op, skop); 450 change_abil (op, skop);
471 } 451 }
472 } 452 }
473 453
474 /* now change to the new gods attributes to exp_obj */ 454 /* now change to the new gods attributes to exp_obj */
525 stop_using_item (op, BOOTS, 1); 505 stop_using_item (op, BOOTS, 1);
526 stop_using_item (op, GLOVES, 1); 506 stop_using_item (op, GLOVES, 1);
527 stop_using_item (op, SHIELD, 1); 507 stop_using_item (op, SHIELD, 1);
528 } 508 }
529 509
530 SET_FLAG (skop, FLAG_APPLIED); 510 skop->set_flag (FLAG_APPLIED);
531 (void) change_abil (op, skop); 511 change_abil (op, skop);
532 512
533 /* return to previous skill status */ 513 /* return to previous skill status */
534 if (!sk_applied) 514 if (!sk_applied)
535 CLEAR_FLAG (skop, FLAG_APPLIED); 515 skop->clr_flag (FLAG_APPLIED);
536 516
537 check_special_prayers (op, new_god); 517 check_special_prayers (op, new_god);
538} 518}
539 519
540/**
541 * Forbids or let player use something item type.
542 * op is the player.
543 * exp_obj is the widsom experience.
544 * flag is the flag to check against.
545 * string is the string to print out.
546 */
547
548int
549worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
550{
551 if (QUERY_FLAG (op->arch, flag))
552 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
553 {
554 update_priest_flag (exp_obj, op, flag);
555 if (QUERY_FLAG (op, flag))
556 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
557 else
558 {
559 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
560 return 1;
561 }
562 }
563
564 return 0;
565}
566
567/**
568 * Unapplies up to number worth of items of type
569 */
570void
571stop_using_item (object *op, int type, int number)
572{
573 object *tmp;
574
575 for (tmp = op->inv; tmp && number; tmp = tmp->below)
576 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
577 {
578 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
579 number--;
580 }
581}
582
583/**
584 * If the god does/doesnt have this flag, we
585 * give/remove it from the experience object if it doesnt/does
586 * already exist. For players only!
587 */
588
589void
590update_priest_flag (object *god, object *exp_ob, uint32 flag)
591{
592 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
593 SET_FLAG (exp_ob, flag);
594 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
595 {
596 /* When this is called with the exp_ob set to the player,
597 * this check is broken, because most all players arch
598 * allow use of weapons. I'm not actually sure why this
599 * check is here - I guess if you had a case where the
600 * value in the archetype (wisdom) should over ride the restrictions
601 * the god places on it, this may make sense. But I don't think
602 * there is any case like that.
603 */
604
605/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
606 CLEAR_FLAG (exp_ob, flag);
607 };
608}
609
610archetype * 520archetype *
611determine_holy_arch (object *god, const char *type) 521determine_holy_arch (object *god, shstr_cmp type)
612{ 522{
613 treasure *tr; 523 treasure *tr;
614 524
615 if (!god || !god->randomitems) 525 if (!god || !god->randomitems)
616 { 526 {
623 if (!tr->item) 533 if (!tr->item)
624 continue; 534 continue;
625 535
626 object *item = tr->item; 536 object *item = tr->item;
627 537
628 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 538 if (item->type == BOOK && item->invisible && item->name == type)
629 return item->other_arch; 539 return item->other_arch;
630 } 540 }
631 541
632 return 0; 542 return 0;
633} 543}
643 for (object *tmp = op->inv; tmp; tmp = tmp->below) 553 for (object *tmp = op->inv; tmp; tmp = tmp->below)
644 { 554 {
645 if (tmp->invisible) 555 if (tmp->invisible)
646 continue; 556 continue;
647 557
648 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 558 if (tmp->flag [FLAG_DAMNED] && !remove_damnation)
649 continue; 559 continue;
650 560
651 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 561 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
652 { 562 {
653 success = 1; 563 success = 1;
654 CLEAR_FLAG (tmp, FLAG_DAMNED); 564 tmp->clr_flag (FLAG_DAMNED);
655 CLEAR_FLAG (tmp, FLAG_CURSED); 565 tmp->clr_flag (FLAG_CURSED);
656 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 566 tmp->clr_flag (FLAG_KNOWN_CURSED);
657 567
658 if (object *pl = tmp->visible_to ()) 568 if (object *pl = tmp->visible_to ())
659 esrv_update_item (UPD_FLAGS, pl, tmp); 569 esrv_update_item (UPD_FLAGS, pl, tmp);
660 } 570 }
661 } 571 }
680 590
681 if (level <= 40) 591 if (level <= 40)
682 return (20 + (level - 20) / 2) / difficulty; 592 return (20 + (level - 20) / 2) / difficulty;
683 593
684 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 */
685} 636}
686 637
687/** 638/**
688 * God wants to enchant weapon. 639 * God wants to enchant weapon.
689 * 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
696 object *weapon; 647 object *weapon;
697 uint32 attacktype; 648 uint32 attacktype;
698 int tmp; 649 int tmp;
699 650
700 for (weapon = op->inv; weapon; weapon = weapon->below) 651 for (weapon = op->inv; weapon; weapon = weapon->below)
701 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED)) 652 if ((weapon->type == WEAPON || weapon->type == BOW) && weapon->flag [FLAG_APPLIED])
702 break; 653 break;
703 654
704 if (!weapon || god_examines_item (god, weapon) <= 0) 655 if (!weapon || god_examines_item (god, weapon) <= 0)
705 return 0; 656 return 0;
706 657
744 695
745 return 1; 696 return 1;
746 } 697 }
747 698
748 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;
749} 743}
750 744
751/** 745/**
752 * 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.
753 * 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
754 * priest. -b.t. 748 * priest. -b.t.
755 * called from pray_at_altar() currently. 749 * called from pray_at_altar() currently.
756 */ 750 */
757void 751static void
758god_intervention (object *op, object *god, object *skill) 752god_intervention (object *op, object *god, object *skill)
759{ 753{
760 treasure *tr; 754 treasure *tr;
761 755
762 if (!god || !god->randomitems) 756 if (!god || !god->randomitems)
799 continue; 793 continue;
800 794
801 item = tr->item; 795 item = tr->item;
802 796
803 /* Grace limit */ 797 /* Grace limit */
804 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 798 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
805 { 799 {
806 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 800 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
807 { 801 {
808 object *tmp;
809
810 /* Follower lacks the required grace for the following 802 /* Follower lacks the required grace for the following
811 * treasure list items. */ 803 * treasure list items. */
812 804
813 tmp = get_archetype (HOLY_POSSESSION); 805 object *tmp = get_archetype (HOLY_POSSESSION);
814 cast_change_ability (op, op, tmp, 0, 1); 806 cast_change_ability (op, op, tmp, 0, 1);
815 tmp->destroy (); 807 tmp->destroy ();
816 return; 808 return;
817 } 809 }
818 810
819 continue; 811 continue;
820 } 812 }
821 813
822 /* Restore grace */ 814 /* Restore grace */
823 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 815 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
824 { 816 {
825 if (op->stats.grace >= 0) 817 if (op->stats.grace >= 0)
826 continue; 818 continue;
819
827 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 820 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
828 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace."); 821 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace.");
829 return; 822 return;
830 } 823 }
831 824
832 /* Heal damage */ 825 /* Heal damage */
833 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0) 826 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0)
834 { 827 {
835 if (op->stats.hp >= op->stats.maxhp) 828 if (op->stats.hp >= op->stats.maxhp)
836 continue; 829 continue;
830
837 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!"); 831 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!");
838 op->stats.hp = op->stats.maxhp; 832 op->stats.hp = op->stats.maxhp;
839 return; 833 return;
840 } 834 }
841 835
890 { 884 {
891 object *depl; 885 object *depl;
892 archetype *at; 886 archetype *at;
893 int i; 887 int i;
894 888
895 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 889 if ((at = archetype::find (shstr_depletion)) == NULL)
896 { 890 {
897 LOG (llevError, "Could not find archetype depletion.\n"); 891 LOG (llevError, "Could not find archetype depletion.\n");
898 continue; 892 continue;
899 } 893 }
894
900 depl = present_arch_in_ob (at, op); 895 depl = present_arch_in_ob (at, op);
901 896
902 if (depl == NULL) 897 if (depl == NULL)
903 continue; 898 continue;
904 899
964 959
965 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture."); 960 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture.");
966} 961}
967 962
968/** 963/**
969 * Checks and maybe punishes someone praying. 964 * Player prays at altar.
970 * All applied items are examined, if player is using more items of other gods, 965 * Checks for god changing, divine intervention, and so on.
971 * s/he loses experience in praying or general experience if no praying.
972 */ 966 */
973int 967void
974god_examines_priest (object *op, object *god) 968pray_at_altar (object *pl, object *altar, object *skill)
975{ 969{
976 int reaction = 1; 970 object *pl_god = find_god (determine_god (pl));
977 object *item = NULL, *skop;
978 971
979 for (item = op->inv; item; item = item->below) 972 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
980 if (QUERY_FLAG (item, FLAG_APPLIED))
981 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
982
983 /* well, well. Looks like we screwed up. Time for god's revenge */
984 if (reaction < 0)
985 {
986 int loss = 10000000;
987 int angry = abs (reaction);
988
989 for (skop = op->inv; skop; skop = skop->below)
990 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
991 break;
992
993 if (skop)
994 loss = 0.05f * skop->stats.exp;
995
996 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
997
998 if (random_roll (0, angry, op, PREFER_LOW))
999 {
1000 object *tmp = get_archetype (LOOSE_MANA);
1001
1002 cast_magic_storm (op, tmp, op->level + (angry * 3));
1003 }
1004
1005 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1006 }
1007
1008 return reaction;
1009}
1010
1011/**
1012 * God checks item the player is using.
1013 * Return either -1 (bad), 0 (neutral) or
1014 * 1 (item is ok). If you are using the item of an enemy
1015 * god, it can be bad...-b.t.
1016 */
1017
1018int
1019god_examines_item (object *god, object *item)
1020{
1021 char buf[MAX_BUF];
1022
1023 if (!god || !item)
1024 return 0; 973 return;
1025 974
1026 if (!item->title) 975 /* If non consecrate altar, don't do anything */
1027 return 1; /* unclaimed item are ok */ 976 if (!altar->other_arch)
977 return;
1028 978
1029 sprintf (buf, "of %s", &god->name); 979 /* hmm. what happend depends on pl's current god, level, etc */
1030 if (!strcmp (item->title, buf)) 980 if (!pl_god)
1031 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;
1032 990
1033 if (god->title) 991 /* we can get neg grace up faster */
1034 { /* check if we have any enemy blessed item */ 992 if (pl->stats.grace < 0)
1035 sprintf (buf, "of %s", &god->title); 993 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
1036 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.
1037 { 1003 */
1038 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)
1039 { 1025 {
1040 char buf[MAX_BUF]; 1026 object *tmp;
1041 1027
1042 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1028 /* you really screwed up */
1043 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);
1044 } 1033 }
1045 return -1; 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);
1039
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
1046 } 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 }
1047 } 1061 }
1048
1049 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1050}
1051
1052/**
1053 * Returns priest's god's id.
1054 * Straight calls lookup_god_by_name
1055 */
1056
1057int
1058get_god (object *priest)
1059{
1060 return lookup_god_by_name (determine_god (priest));
1061}
1062
1063/**
1064 * Returns a string that is the name of the god that should be natively worshipped by a
1065 * creature of who has race *race
1066 * if we can't find a god that is appropriate, we return NULL
1067 */
1068shstr_tmp
1069get_god_for_race (const char *race)
1070{
1071 if (race)
1072 for (godlink *gl = first_god; gl; gl = gl->next)
1073 if (!strcasecmp (gl->arch->race, race))
1074 return gl->name;
1075
1076 return shstr_null;
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