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.45 by root, Thu Jan 1 16:05:13 2009 UTC vs.
Revision 1.74 by root, Sat Nov 17 23:40:03 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License 19 * 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/>. 20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
20 * 22 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 24 */
23 25
24/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and 26/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and
25 * monster race initialization. b.t. 27 * monster race initialization. b.t.
35#include <sproto.h> 37#include <sproto.h>
36 38
37/** 39/**
38 * Returns the id of specified god. 40 * Returns the id of specified god.
39 */ 41 */
40int 42static int
41lookup_god_by_name (shstr_cmp name) 43lookup_god_by_name (shstr_cmp name)
42{ 44{
43 if (name) 45 if (name)
44 for (godlink *gl = first_god; gl; gl = gl->next) 46 for (godlink *gl = first_god; gl; gl = gl->next)
45 if (gl->name == name) 47 if (gl->name == name)
61 63
62 return 0; 64 return 0;
63} 65}
64 66
65/** 67/**
66 * Returns a string that is the name of the god that should be natively worshipped by a 68 * Returns a string that is the name of the god that should be natively worshipped by a
67 * creature of who has race *race 69 * creature of who has race *race
68 * if we can't find a god that is appropriate, we return NULL 70 * if we can't find a god that is appropriate, we return NULL
69 */ 71 */
70static shstr_tmp 72static shstr_tmp
71get_god_for_race (shstr_cmp race) 73get_god_for_race (shstr_cmp race)
79} 81}
80 82
81/** 83/**
82 * Determines if op worships a god. 84 * Determines if op worships a god.
83 * Returns the godname if they do or "none" if they have no god. 85 * Returns the godname if they do or "none" if they have no god.
84 * In the case of an NPC, if they have no god, we try and guess 86 * In the case of an NPC, if they have no god, we try and guess
85 * who they should worship based on their race. If that fails we 87 * who they should worship based on their race. If that fails we
86 * give them a random one. 88 * give them a random one.
87 */ 89 */
88shstr_tmp 90shstr_tmp
89determine_god (object *op) 91determine_god (object *op)
90{ 92{
102 /* find a random god */ 104 /* find a random god */
103 if (!op->title) 105 if (!op->title)
104 { 106 {
105 int godnr = rndm (1, first_god->id); 107 int godnr = rndm (1, first_god->id);
106 108
107 for (godlink *gl = first_god; gl && gl->id != godnr; gl = gl->next) 109 for (godlink *gl = first_god; gl; gl = gl->next)
108 if (gl->id == godnr) 110 if (gl->id == godnr)
109 { 111 {
110 op->title = gl->name; 112 op->title = gl->name;
111 break; 113 break;
112 } 114 }
213 return 0; 215 return 0;
214 216
215 if (follower_has_similar_item (op, tr->item)) 217 if (follower_has_similar_item (op, tr->item))
216 return 0; 218 return 0;
217 219
218 object *tmp = arch_to_object (tr->item); 220 object *tmp = tr->item->instance ();
219 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp)); 221 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp));
220 op->insert (tmp); 222 op->insert (tmp);
221 223
222 return 1; 224 return 1;
223}
224
225/**
226 * Player prays at altar.
227 * Checks for god changing, divine intervention, and so on.
228 */
229void
230pray_at_altar (object *pl, object *altar, object *skill)
231{
232 object *pl_god = find_god (determine_god (pl));
233
234 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
235 return;
236
237 /* If non consecrate altar, don't do anything */
238 if (!altar->other_arch)
239 return;
240
241 /* hmm. what happend depends on pl's current god, level, etc */
242 if (!pl_god)
243 { /*new convert */
244 become_follower (pl, altar->other_arch);
245 return;
246 }
247 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
248 {
249 /* pray at your gods altar */
250 int bonus = (pl->stats.Wis + skill->level) / 10;
251
252 /* we can get neg grace up faster */
253 if (pl->stats.grace < 0)
254 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
255
256 /* we can super-charge grace to 2x max */
257 if (pl->stats.grace < 2 * pl->stats.maxgrace)
258 pl->stats.grace += bonus / 2;
259 else
260 pl->stats.grace = 2 * pl->stats.maxgrace;
261
262 /* Every once in a while, the god decides to checkup on their
263 * follower, and may intervene to help them out.
264 */
265 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
266
267 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
268 god_intervention (pl, pl_god, skill);
269 }
270 else
271 { /* praying to another god! */
272 uint64 loss = 0;
273 int angry = 1;
274
275 /* I believe the logic for detecting opposing gods was completely
276 * broken - I think it should work now. altar->other_arch
277 * points to the god of this altar (which we have
278 * already verified is non null). pl_god->other_arch
279 * is the opposing god - we need to verify that exists before
280 * using its values.
281 */
282 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
283 {
284 angry = 2;
285 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
286 {
287 object *tmp;
288
289 /* you really screwed up */
290 angry = 3;
291 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
292 tmp = get_archetype (LOOSE_MANA);
293 cast_magic_storm (pl, tmp, pl_god->level + 20);
294 }
295 else
296 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
297 }
298 else
299 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
300
301 /* whether we will be successfull in defecting or not -
302 * we lose experience from the clerical experience obj
303 */
304
305 loss = angry * (skill->stats.exp / 10);
306 if (loss)
307 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
308
309 /* May switch Gods, but its random chance based on our current level
310 * note it gets harder to swap gods the higher we get
311 */
312 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
313 become_follower (pl, altar->other_arch);
314 else
315 {
316 /* toss this player off the altar. He can try again. */
317 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
318 pl->contr->fire_on = 0;
319 pl->speed_left = 1.f;
320 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
321 }
322 }
323} 225}
324 226
325/** 227/**
326 * Removes special prayers given by a god. 228 * Removes special prayers given by a god.
327 */ 229 */
341 next_tmp = tmp->below; 243 next_tmp = tmp->below;
342 244
343 /* we mark special prayers with the STARTEQUIP flag, so if it isn't 245 /* we mark special prayers with the STARTEQUIP flag, so if it isn't
344 * in that category, not something we need to worry about. 246 * in that category, not something we need to worry about.
345 */ 247 */
346 if (tmp->type != SPELL || !QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 248 if (tmp->type != SPELL || !tmp->flag [FLAG_STARTEQUIP])
347 continue; 249 continue;
348 250
349 if (god->randomitems == NULL) 251 if (god->randomitems == NULL)
350 { 252 {
351 LOG (llevError, "BUG: check_special_prayers(): god %s without randomitems\n", &god->name); 253 LOG (llevError, "BUG: check_special_prayers(): god %s without randomitems\n", &god->name);
379 do_forget_spell (op, tmp->name); 281 do_forget_spell (op, tmp->name);
380 } 282 }
381} 283}
382 284
383/** 285/**
286 * Unapplies up to number worth of items of type
287 */
288static void
289stop_using_item (object *op, int type, int number)
290{
291 for (object *tmp = op->inv; tmp && number; tmp = tmp->below)
292 if (tmp->type == type && tmp->flag [FLAG_APPLIED])
293 {
294 op->apply (tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
295 --number;
296 }
297}
298
299/**
300 * If the god does/doesnt have this flag, we
301 * give/remove it from the experience object if it doesnt/does
302 * already exist. For players only!
303 */
304static inline void
305update_priest_flag (object *god, object *exp_ob, uint32 flag)
306{
307 exp_ob->flag [flag] = god->flag [flag];
308 return;
309
310 // old code follows for reference...
311 if (god->flag [flag] && !exp_ob->flag [flag])
312 exp_ob->set_flag (flag);
313 else if (exp_ob->flag [flag] && !god->flag [flag])
314 {
315 /* When this is called with the exp_ob set to the player,
316 * this check is broken, because most all players arch
317 * allow use of weapons. I'm not actually sure why this
318 * check is here - I guess if you had a case where the
319 * value in the archetype (wisdom) should over ride the restrictions
320 * the god places on it, this may make sense. But I don't think
321 * there is any case like that.
322 */
323/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
324 exp_ob->clr_flag (flag);
325 };
326}
327
328/**
329 * Forbids or let player use something item type.
330 * op is the player.
331 * exp_obj is the widsom experience.
332 * flag is the flag to check against.
333 * string is the string to print out.
334 */
335static int
336worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
337{
338 if (op->arch->flag [flag])
339 if (op->flag [flag] != exp_obj->flag [flag])
340 {
341 update_priest_flag (exp_obj, op, flag);
342 if (op->flag [flag])
343 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
344 else
345 {
346 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
347 return 1;
348 }
349 }
350
351 return 0;
352}
353
354/**
384 * This function is called whenever a player has 355 * This function is called whenever a player has
385 * switched to a new god. It handles basically all the stat changes 356 * switched to a new god. It handles basically all the stat changes
386 * that happen to the player, including the removal of godgiven 357 * that happen to the player, including the removal of godgiven
387 * items (from the former cult). 358 * items (from the former cult).
388 */ 359 */
389void 360void
390become_follower (object *op, object *new_god) 361object::become_follower (object *new_god)
391{ 362{
392 object *old_god = NULL; /* old god */ 363 object *old_god = 0; /* old god */
393 treasure *tr; 364 treasure *tr;
394 object *item, *skop, *next; 365 object *item, *skop, *next;
395 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */ 366 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */
396 367
368 if (!contr)
369 return;
370
371 contr->queue_stats_update ();
372
397 old_god = find_god (determine_god (op)); 373 old_god = find_god (determine_god (this));
398 374
399 /* take away any special god-characteristic items. */ 375 /* take away any special god-characteristic items. */
400 for (item = op->inv; item; item = next) 376 for (item = inv; item; item = next)
401 { 377 {
402 next = item->below; 378 next = item->below;
403 379
404 // remove all invisible startequip items which are not skill, exp or force 380 // remove all invisible startequip items which are not skill, exp or force
405 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 381 if (item->flag [FLAG_STARTEQUIP] && item->invisible
406 (item->type != SKILL) && (item->type != FORCE)) 382 && item->type != SKILL && item->type != FORCE)
407 { 383 {
408 if (item->type == SPELL) 384 if (item->type == SPELL)
409 { 385 {
410 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name); 386 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, this, "You lose knowledge of %s.", &item->name);
411 esrv_remove_spell (op->contr, item); 387 esrv_remove_spell (contr, item);
412 } 388 }
413 389
414 player_unready_range_ob (op->contr, item);
415 item->destroy (); 390 item->destroy ();
416 } 391 }
417 } 392 }
418 393
419 /* remove any godgiven items from the old god */ 394 /* remove any godgiven items from the old god */
420 if (old_god) 395 if (old_god)
421 for (tr = old_god->randomitems->items; tr; tr = tr->next) 396 for (tr = old_god->randomitems->items; tr; tr = tr->next)
422 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP)) 397 if (tr->item && tr->item->flag [FLAG_STARTEQUIP])
423 follower_remove_similar_item (op, tr->item); 398 follower_remove_similar_item (this, tr->item);
424 399
425 if (!op || !new_god) 400 if (!new_god)
426 return; 401 return;
427 402
428 if (op->race && new_god->slaying && op->race.contains (new_god->slaying)) 403 if (new_god->slaying && new_god->slaying.contains (race))
429 { 404 {
430 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 405 failmsgf ("Fool! %s detests your kind! H<This god does not accept followers of your race.>", &new_god->name);
431 406
432 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 407 if (random_roll (0, level - 1, this, PREFER_LOW) - 5 > 0)
433 { 408 {
434 object *tmp = get_archetype (LOOSE_MANA); 409 object *tmp = archetype::get (LOOSE_MANA);
435 410
436 cast_magic_storm (op, tmp, new_god->level + 10); 411 cast_magic_storm (this, tmp, new_god->level + 10);
437 } 412 }
438 413
439 return; 414 return;
440 } 415 }
441 416
442 /* give the player any special god-characteristic-items. */ 417 /* give the player any special god-characteristic-items. */
443 for (tr = new_god->randomitems->items; tr; tr = tr->next) 418 for (tr = new_god->randomitems->items; tr; tr = tr->next)
444 {
445 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK 419 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
446 && tr->item->type != BOOK && tr->item->type != SPELL) 420 && tr->item->type != BOOK && tr->item->type != SPELL)
447 god_gives_present (op, new_god, tr); 421 god_gives_present (this, new_god, tr);
448 }
449 422
450 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name); 423 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, this, "You become a follower of %s!", &new_god->name);
451 424
452 for (skop = op->inv; skop; skop = skop->below) 425 for (skop = inv; skop; skop = skop->below)
453 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 426 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
454 break; 427 break;
455 428
456 /* Player has no skill - give them the skill */ 429 /* Player has no skill - give them the skill */
457 if (!skop) 430 if (!skop)
458 /* The archetype should always be defined - if we crash here because it doesn't, 431 /* The archetype should always be defined - if we crash here because it doesn't,
459 * things are really messed up anyways. 432 * things are really messed up anyways.
460 */ 433 */
461 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill); 434 skop = give_skill_by_name (this, shstr_praying);
462 435
463 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 436 sk_applied = skop->flag [FLAG_APPLIED]; /* save skill status */
464 437
465 /* Clear the "undead" status. We also need to force a call to change_abil, 438 /* Clear the "undead" status. We also need to force a call to change_abil,
466 * so I set undeadified for that. 439 * so I set undeadified for that.
467 * - gros, 21th July 2006. 440 * - gros, 21th July 2006.
468 */ 441 */
469 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD)) 442 if (old_god && old_god->flag [FLAG_UNDEAD])
470 { 443 {
471 CLEAR_FLAG (skop, FLAG_UNDEAD); 444 skop->clr_flag (FLAG_UNDEAD);
472 undeadified = 1; 445 undeadified = 1;
473 } 446 }
474 447
475 if (skop->title) 448 if (skop->title)
476 { 449 {
477 /* get rid of old god */ 450 /* get rid of old god */
478 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title); 451 new_draw_info_format (NDI_UNIQUE, 0, this, "%s's blessing is withdrawn from you.", &skop->title);
479 452
480 /* The point of this is to really show what abilities the player just lost */ 453 /* The point of this is to really show what abilities the player just lost */
481 if (sk_applied || undeadified) 454 if (sk_applied || undeadified)
482 { 455 {
483 CLEAR_FLAG (skop, FLAG_APPLIED); 456 skop->clr_flag (FLAG_APPLIED);
484 change_abil (op, skop); 457 change_abil (this, skop);
485 } 458 }
486 } 459 }
487 460
488 /* now change to the new gods attributes to exp_obj */ 461 /* now change to the new gods attributes to exp_obj */
489 skop->title = new_god->name; 462 skop->title = new_god->name;
492 skop->path_denied = new_god->path_denied; 465 skop->path_denied = new_god->path_denied;
493 /* copy god's resistances */ 466 /* copy god's resistances */
494 memcpy (skop->resist, new_god->resist, sizeof (new_god->resist)); 467 memcpy (skop->resist, new_god->resist, sizeof (new_god->resist));
495 468
496 /* make sure that certain immunities do NOT get passed 469 /* make sure that certain immunities do NOT get passed
497 * to the follower! 470 * to the follower!
498 */ 471 */
499 for (i = 0; i < NROFATTACKS; i++) 472 for (i = 0; i < NROFATTACKS; i++)
500 if (skop->resist[i] > 30 && (i == ATNR_FIRE || i == ATNR_COLD || i == ATNR_ELECTRICITY || i == ATNR_POISON)) 473 if (skop->resist[i] > 30 && (i == ATNR_FIRE || i == ATNR_COLD || i == ATNR_ELECTRICITY || i == ATNR_POISON))
501 skop->resist[i] = 30; 474 skop->resist[i] = 30;
502 475
513 update_priest_flag (new_god, skop, FLAG_MAKE_INVIS); 486 update_priest_flag (new_god, skop, FLAG_MAKE_INVIS);
514 update_priest_flag (new_god, skop, FLAG_UNDEAD); 487 update_priest_flag (new_god, skop, FLAG_UNDEAD);
515 update_priest_flag (new_god, skop, FLAG_BLIND); 488 update_priest_flag (new_god, skop, FLAG_BLIND);
516 update_priest_flag (new_god, skop, FLAG_XRAYS); /* better have this if blind! */ 489 update_priest_flag (new_god, skop, FLAG_XRAYS); /* better have this if blind! */
517 490
518 new_draw_info_format (NDI_UNIQUE, 0, op, "You are bathed in %s's aura.", &new_god->name); 491 new_draw_info_format (NDI_UNIQUE, 0, this, "You are bathed in %s's aura.", &new_god->name);
519 492
520 /* Weapon/armour use are special...handle flag toggles here as this can 493 /* Weapon/armour use are special...handle flag toggles here as this can
521 * only happen when gods are worshipped and if the new priest could 494 * only happen when gods are worshipped and if the new priest could
522 * have used armour/weapons in the first place. 495 * have used armour/weapons in the first place.
523 * 496 *
524 * This also can happen for monks which cannot use weapons. In this case 497 * This also can happen for monks which cannot use weapons. In this case
525 * do not allow to use weapons even if the god otherwise would allow it. 498 * do not allow to use weapons even if the god otherwise would allow it.
526 */ 499 */
527 if (!present_in_ob_by_name (FORCE, "no weapon force", op)) 500 if (!present_in_ob_by_name (FORCE, "no weapon force", this))
528 update_priest_flag (new_god, skop, FLAG_USE_WEAPON); 501 update_priest_flag (new_god, skop, FLAG_USE_WEAPON);
529 502
530 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR); 503 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR);
531 504
532 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons")) 505 if (worship_forbids_use (this, skop, FLAG_USE_WEAPON, "weapons"))
533 stop_using_item (op, WEAPON, 2); 506 stop_using_item (this, WEAPON, 2);
534 507
535 if (worship_forbids_use (op, skop, FLAG_USE_ARMOUR, "armour")) 508 if (worship_forbids_use (this, skop, FLAG_USE_ARMOUR, "armour"))
536 { 509 {
537 stop_using_item (op, ARMOUR, 1); 510 stop_using_item (this, ARMOUR, 1);
538 stop_using_item (op, HELMET, 1); 511 stop_using_item (this, HELMET, 1);
539 stop_using_item (op, BOOTS, 1); 512 stop_using_item (this, BOOTS, 1);
540 stop_using_item (op, GLOVES, 1); 513 stop_using_item (this, GLOVES, 1);
541 stop_using_item (op, SHIELD, 1); 514 stop_using_item (this, SHIELD, 1);
542 } 515 }
543 516
544 SET_FLAG (skop, FLAG_APPLIED); 517 skop->set_flag (FLAG_APPLIED);
545 (void) change_abil (op, skop); 518 change_abil (this, skop);
546 519
547 /* return to previous skill status */ 520 /* return to previous skill status */
548 if (!sk_applied) 521 if (!sk_applied)
549 CLEAR_FLAG (skop, FLAG_APPLIED); 522 {
523 skop->clr_flag (FLAG_APPLIED);
524 contr->queue_stats_update ();
525 }
550 526
551 check_special_prayers (op, new_god); 527 check_special_prayers (this, new_god);
552}
553
554/**
555 * Forbids or let player use something item type.
556 * op is the player.
557 * exp_obj is the widsom experience.
558 * flag is the flag to check against.
559 * string is the string to print out.
560 */
561
562int
563worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
564{
565 if (QUERY_FLAG (op->arch, flag))
566 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
567 {
568 update_priest_flag (exp_obj, op, flag);
569 if (QUERY_FLAG (op, flag))
570 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
571 else
572 {
573 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
574 return 1;
575 }
576 }
577
578 return 0;
579}
580
581/**
582 * Unapplies up to number worth of items of type
583 */
584void
585stop_using_item (object *op, int type, int number)
586{
587 object *tmp;
588
589 for (tmp = op->inv; tmp && number; tmp = tmp->below)
590 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
591 {
592 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
593 number--;
594 }
595}
596
597/**
598 * If the god does/doesnt have this flag, we
599 * give/remove it from the experience object if it doesnt/does
600 * already exist. For players only!
601 */
602
603void
604update_priest_flag (object *god, object *exp_ob, uint32 flag)
605{
606 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
607 SET_FLAG (exp_ob, flag);
608 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
609 {
610 /* When this is called with the exp_ob set to the player,
611 * this check is broken, because most all players arch
612 * allow use of weapons. I'm not actually sure why this
613 * check is here - I guess if you had a case where the
614 * value in the archetype (wisdom) should over ride the restrictions
615 * the god places on it, this may make sense. But I don't think
616 * there is any case like that.
617 */
618
619/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
620 CLEAR_FLAG (exp_ob, flag);
621 };
622} 528}
623 529
624archetype * 530archetype *
625determine_holy_arch (object *god, shstr_cmp type) 531determine_holy_arch (object *god, shstr_cmp type)
626{ 532{
657 for (object *tmp = op->inv; tmp; tmp = tmp->below) 563 for (object *tmp = op->inv; tmp; tmp = tmp->below)
658 { 564 {
659 if (tmp->invisible) 565 if (tmp->invisible)
660 continue; 566 continue;
661 567
662 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 568 if (tmp->flag [FLAG_DAMNED] && !remove_damnation)
663 continue; 569 continue;
664 570
665 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 571 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
666 { 572 {
667 success = 1; 573 success = 1;
668 CLEAR_FLAG (tmp, FLAG_DAMNED); 574 tmp->clr_flag (FLAG_DAMNED);
669 CLEAR_FLAG (tmp, FLAG_CURSED); 575 tmp->clr_flag (FLAG_CURSED);
670 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 576 tmp->clr_flag (FLAG_KNOWN_CURSED);
671 577
672 if (object *pl = tmp->visible_to ()) 578 if (object *pl = tmp->visible_to ())
673 esrv_update_item (UPD_FLAGS, pl, tmp); 579 esrv_update_item (UPD_FLAGS, pl, tmp);
674 } 580 }
675 } 581 }
694 600
695 if (level <= 40) 601 if (level <= 40)
696 return (20 + (level - 20) / 2) / difficulty; 602 return (20 + (level - 20) / 2) / difficulty;
697 603
698 return (30 + (level - 40) / 4) / difficulty; 604 return (30 + (level - 40) / 4) / difficulty;
605}
606
607/**
608 * God checks item the player is using.
609 * Return either -1 (bad), 0 (neutral) or
610 * 1 (item is ok). If you are using the item of an enemy
611 * god, it can be bad...-b.t.
612 */
613static int
614god_examines_item (object *god, object *item)
615{
616 char buf[MAX_BUF];
617
618 if (!god || !item)
619 return 0;
620
621 if (!item->title)
622 return 1; /* unclaimed item are ok */
623
624 sprintf (buf, "of %s", &god->name);
625 if (!strcmp (&item->title, buf))
626 return 1; /* belongs to that God */
627
628 if (god->title)
629 { /* check if we have any enemy blessed item */
630 sprintf (buf, "of %s", &god->title);
631 if (!strcmp (&item->title, buf))
632 {
633 if (item->env)
634 {
635 char buf[MAX_BUF];
636
637 sprintf (buf, "Heretic! You are using %s!", query_name (item));
638 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
639 }
640
641 return -1;
642 }
643 }
644
645 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
699} 646}
700 647
701/** 648/**
702 * God wants to enchant weapon. 649 * God wants to enchant weapon.
703 * Affected weapon is the applied one (weapon or bow). It's checked to make sure 650 * Affected weapon is the applied one (weapon or bow). It's checked to make sure
705 * attacktype, slaying and such. 652 * attacktype, slaying and such.
706 */ 653 */
707static int 654static int
708god_enchants_weapon (object *op, object *god, object *tr, object *skill) 655god_enchants_weapon (object *op, object *god, object *tr, object *skill)
709{ 656{
710 object *weapon; 657 if (!op->contr)
711 uint32 attacktype; 658 return 0;
712 int tmp;
713 659
714 for (weapon = op->inv; weapon; weapon = weapon->below) 660 object *weapon = op->contr->combat_ob;
715 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED))
716 break;
717 661
662 if (!weapon)
663 return 0;
664
665 if (weapon->type != WEAPON && weapon->type != BOW)
666 return 0;
667
718 if (!weapon || god_examines_item (god, weapon) <= 0) 668 if (god_examines_item (god, weapon) <= 0)
719 return 0; 669 return 0;
720 670
721 /* First give it a title, so other gods won't touch it */ 671 /* First give it a title, so other gods won't touch it */
722 if (!weapon->title) 672 if (!weapon->title)
723 { 673 {
736 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s now hungers to slay enemies of your god!", &weapon->name); 686 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s now hungers to slay enemies of your god!", &weapon->name);
737 return 1; 687 return 1;
738 } 688 }
739 689
740 /* Add the gods attacktype */ 690 /* Add the gods attacktype */
741 attacktype = (weapon->attacktype == 0) ? AT_PHYSICAL : weapon->attacktype; 691 uint32 attacktype = (weapon->attacktype == 0) ? AT_PHYSICAL : weapon->attacktype;
692
742 if ((attacktype & god->attacktype) != god->attacktype) 693 if ((attacktype & god->attacktype) != god->attacktype)
743 { 694 {
744 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon suddenly glows!"); 695 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon suddenly glows!");
745 weapon->attacktype = attacktype | god->attacktype; 696 weapon->attacktype = attacktype | god->attacktype;
746 return 1; 697 return 1;
747 } 698 }
748 699
749 /* Higher magic value */ 700 /* Higher magic value */
750 tmp = follower_level_to_enchantments (skill->level, tr->level); 701 if (weapon->magic < follower_level_to_enchantments (skill->level, tr->level))
751 if (weapon->magic < tmp)
752 { 702 {
753 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!"); 703 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!");
754 weapon->magic++; 704 weapon->magic++;
755 705
756 if (object *pl = weapon->visible_to ()) 706 if (object *pl = weapon->visible_to ())
761 711
762 return 0; 712 return 0;
763} 713}
764 714
765/** 715/**
716 * Checks and maybe punishes someone praying.
717 * All applied items are examined, if player is using more items of other gods,
718 * s/he loses experience in praying or general experience if no praying.
719 */
720static int
721god_examines_priest (object *op, object *god)
722{
723 int reaction = 1;
724 object *item = NULL, *skop;
725
726 for (item = op->inv; item; item = item->below)
727 if (item->flag [FLAG_APPLIED])
728 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
729
730 /* well, well. Looks like we screwed up. Time for god's revenge */
731 if (reaction < 0)
732 {
733 int loss = 10000000;
734 int angry = abs (reaction);
735
736 for (skop = op->inv; skop; skop = skop->below)
737 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
738 break;
739
740 if (skop)
741 loss = 0.05f * skop->stats.exp;
742
743 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? skop->skill : shstr_none, SK_SUBTRACT_SKILL_EXP);
744
745 if (random_roll (0, angry, op, PREFER_LOW))
746 {
747 object *tmp = archetype::get (LOOSE_MANA);
748
749 cast_magic_storm (op, tmp, op->level + (angry * 3));
750 }
751
752 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
753 }
754
755 return reaction;
756}
757
758/**
766 * Every once in a while the god will intervene to help the worshiper. 759 * Every once in a while the god will intervene to help the worshiper.
767 * Later, this fctn can be used to supply quests, etc for the 760 * Later, this fctn can be used to supply quests, etc for the
768 * priest. -b.t. 761 * priest. -b.t.
769 * called from pray_at_altar() currently. 762 * called from pray_at_altar() currently.
770 */ 763 */
771void 764static void
772god_intervention (object *op, object *god, object *skill) 765god_intervention (object *op, object *god, object *skill)
773{ 766{
774 treasure *tr; 767 treasure *tr;
775 768
776 if (!god || !god->randomitems) 769 if (!god || !god->randomitems)
820 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 813 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
821 { 814 {
822 /* Follower lacks the required grace for the following 815 /* Follower lacks the required grace for the following
823 * treasure list items. */ 816 * treasure list items. */
824 817
825 object *tmp = get_archetype (HOLY_POSSESSION); 818 object *tmp = archetype::get (HOLY_POSSESSION);
826 cast_change_ability (op, op, tmp, 0, 1); 819 cast_change_ability (op, op, tmp, 0, 1);
827 tmp->destroy (); 820 tmp->destroy ();
828 return; 821 return;
829 } 822 }
830 823
904 { 897 {
905 object *depl; 898 object *depl;
906 archetype *at; 899 archetype *at;
907 int i; 900 int i;
908 901
909 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 902 if ((at = archetype::find (shstr_depletion)) == NULL)
910 { 903 {
911 LOG (llevError, "Could not find archetype depletion.\n"); 904 LOG (llevError, "Could not find archetype depletion.\n");
912 continue; 905 continue;
913 } 906 }
914 907
979 972
980 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture."); 973 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture.");
981} 974}
982 975
983/** 976/**
984 * Checks and maybe punishes someone praying. 977 * Player prays at altar.
985 * All applied items are examined, if player is using more items of other gods, 978 * Checks for god changing, divine intervention, and so on.
986 * s/he loses experience in praying or general experience if no praying.
987 */ 979 */
988int 980void
989god_examines_priest (object *op, object *god) 981pray_at_altar (object *pl, object *altar, object *skill)
990{ 982{
991 int reaction = 1; 983 object *pl_god = find_god (determine_god (pl));
992 object *item = NULL, *skop;
993 984
994 for (item = op->inv; item; item = item->below) 985 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
995 if (QUERY_FLAG (item, FLAG_APPLIED))
996 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
997
998 /* well, well. Looks like we screwed up. Time for god's revenge */
999 if (reaction < 0)
1000 {
1001 int loss = 10000000;
1002 int angry = abs (reaction);
1003
1004 for (skop = op->inv; skop; skop = skop->below)
1005 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1006 break;
1007
1008 if (skop)
1009 loss = 0.05f * skop->stats.exp;
1010
1011 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1012
1013 if (random_roll (0, angry, op, PREFER_LOW))
1014 {
1015 object *tmp = get_archetype (LOOSE_MANA);
1016
1017 cast_magic_storm (op, tmp, op->level + (angry * 3));
1018 }
1019
1020 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1021 }
1022
1023 return reaction;
1024}
1025
1026/**
1027 * God checks item the player is using.
1028 * Return either -1 (bad), 0 (neutral) or
1029 * 1 (item is ok). If you are using the item of an enemy
1030 * god, it can be bad...-b.t.
1031 */
1032int
1033god_examines_item (object *god, object *item)
1034{
1035 char buf[MAX_BUF];
1036
1037 if (!god || !item)
1038 return 0; 986 return;
1039 987
1040 if (!item->title) 988 /* If non consecrate altar, don't do anything */
1041 return 1; /* unclaimed item are ok */ 989 if (!altar->other_arch)
990 return;
1042 991
1043 sprintf (buf, "of %s", &god->name); 992 /* hmm. what happend depends on pl's current god, level, etc */
1044 if (!strcmp (&item->title, buf)) 993 if (!pl_god)
1045 return 1; /* belongs to that God */ 994 { /*new convert */
995 pl->become_follower (altar->other_arch);
996 return;
997 }
998 else if (pl_god->name == altar->other_arch->object::name)
999 {
1000 /* pray at your gods altar */
1001 /* this leads to very low levels of wis and pray to result in no doubling! */
1002 int bonus = (pl->stats.Wis + skill->level) / 10;
1046 1003
1047 if (god->title) 1004 /* we can get neg grace up faster */
1048 { /* check if we have any enemy blessed item */ 1005 if (pl->stats.grace < 0)
1049 sprintf (buf, "of %s", &god->title); 1006 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
1050 if (!strcmp (&item->title, buf)) 1007
1008 /* we can super-charge grace to 2x max */
1009 if (pl->stats.grace < 2 * pl->stats.maxgrace)
1010 pl->stats.grace += bonus / 2;
1011 else
1012 pl->stats.grace = 2 * pl->stats.maxgrace;
1013
1014 /* Every once in a while, the god decides to checkup on their
1015 * follower, and may intervene to help them out.
1051 { 1016 */
1052 if (item->env) 1017 bonus = max (1, bonus + max (pl->stats.luck, -3)); /* -- DAMN -- */
1018
1019 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
1020 god_intervention (pl, pl_god, skill);
1021 }
1022 else
1023 { /* praying to another god! */
1024 uint64 loss = 0;
1025 int angry = 1;
1026
1027 /* I believe the logic for detecting opposing gods was completely
1028 * broken - I think it should work now. altar->other_arch
1029 * points to the god of this altar (which we have
1030 * already verified is non null). pl_god->other_arch
1031 * is the opposing god - we need to verify that exists before
1032 * using its values.
1033 */
1034 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
1035 {
1036 angry = 2;
1037 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
1053 { 1038 {
1054 char buf[MAX_BUF]; 1039 object *tmp;
1055 1040
1056 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1041 /* you really screwed up */
1057 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1042 angry = 3;
1043 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
1044 tmp = archetype::get (LOOSE_MANA);
1045 cast_magic_storm (pl, tmp, pl_god->level + 20);
1058 } 1046 }
1047 else
1048 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
1049 }
1050 else
1051 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
1059 1052
1060 return -1; 1053 /* whether we will be successfull in defecting or not -
1054 * we lose experience from the clerical experience obj
1055 */
1056
1057 loss = angry * (skill->stats.exp / 10);
1058 if (loss)
1059 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? skill->skill : shstr_none, SK_SUBTRACT_SKILL_EXP);
1060
1061 /* May switch Gods, but its random chance based on our current level
1062 * note it gets harder to swap gods the higher we get
1063 */
1064 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
1065 pl->become_follower (altar->other_arch);
1066 else
1061 } 1067 {
1068 /* toss this player off the altar. He can try again. */
1069 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
1070 pl->contr->fire_on = 0;
1071 pl->speed_left = 1.f;
1072 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
1073 }
1062 } 1074 }
1063
1064 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1065}
1066
1067/**
1068 * Returns priest's god's id.
1069 * Straight calls lookup_god_by_name
1070 */
1071int
1072get_god (object *priest)
1073{
1074 return lookup_god_by_name (determine_god (priest));
1075} 1075}
1076 1076
1077/** 1077/**
1078 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1078 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1079 * Returns false if there was no race to assign to the slaying field of the spell, but 1079 * 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