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.12 by elmex, Wed Dec 20 10:31:00 2006 UTC vs.
Revision 1.39 by root, Mon Sep 29 10:20:49 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 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 (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23
24 23
25/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and 24/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and
26 * monster race initialization. b.t. 25 * monster race initialization. b.t.
27 */ 26 */
28 27
31#include <global.h> 30#include <global.h>
32#include <living.h> 31#include <living.h>
33#include <object.h> 32#include <object.h>
34#include <spells.h> 33#include <spells.h>
35#include <sounds.h> 34#include <sounds.h>
36#ifndef __CEXTRACT__
37# include <sproto.h> 35#include <sproto.h>
38#endif
39 36
40/** 37/**
41 * Returns the id of specified god. 38 * Returns the id of specified god.
42 */ 39 */
43int 40int
51 godlink *gl; 48 godlink *gl;
52 49
53 for (gl = first_god; gl; gl = gl->next) 50 for (gl = first_god; gl; gl = gl->next)
54 if (!strncmp (name, gl->name, MIN ((size_t) strlen (gl->name), nmlen))) 51 if (!strncmp (name, gl->name, MIN ((size_t) strlen (gl->name), nmlen)))
55 break; 52 break;
53
56 if (gl) 54 if (gl)
57 godnr = gl->id; 55 godnr = gl->id;
58 } 56 }
57
59 return godnr; 58 return godnr;
60} 59}
61 60
62/** 61/**
63 * Returns pointer to specified god's object through pntr_to_god_obj.. 62 * Returns pointer to specified god's object through pntr_to_god_obj..
105 { 104 {
106 105
107 /* find a god based on race */ 106 /* find a god based on race */
108 if (!op->title) 107 if (!op->title)
109 { 108 {
110 if (op->race != NULL) 109 if (op->race)
111 { 110 {
112 godname = get_god_for_race (op->race); 111 godname = get_god_for_race (op->race);
112
113 if (godname != NULL) 113 if (godname)
114 {
115 op->title = godname; 114 op->title = godname;
116 }
117 } 115 }
118 } 116 }
119 117
120 /* find a random god */ 118 /* find a random god */
121 if (!op->title) 119 if (!op->title)
125 godnr = rndm (1, gl->id); 123 godnr = rndm (1, gl->id);
126 while (gl) 124 while (gl)
127 { 125 {
128 if (gl->id == godnr) 126 if (gl->id == godnr)
129 break; 127 break;
128
130 gl = gl->next; 129 gl = gl->next;
131 } 130 }
131
132 op->title = gl->name; 132 op->title = gl->name;
133 } 133 }
134 134
135 return op->title; 135 return op->title;
136 } 136 }
141 * that skill, once we find it, we can return, either with the 141 * that skill, once we find it, we can return, either with the
142 * title or "none". 142 * title or "none".
143 */ 143 */
144 if (op->type == PLAYER) 144 if (op->type == PLAYER)
145 { 145 {
146 object *tmp;
147
148 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 146 for (object *tmp = op->inv; tmp; tmp = tmp->below)
149 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING) 147 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING)
150 { 148 {
151 if (tmp->title) 149 if (tmp->title)
152 return (tmp->title); 150 return tmp->title;
153 else 151 else
154 return ("none"); 152 return "none";
155 } 153 }
156 } 154 }
155
157 return ("none"); 156 return "none";
158} 157}
159 158
160/** 159/**
161 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0 160 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0
162 */ 161 */
172 return 0; 171 return 0;
173 else 172 else
174 return strcmp (s1, s2) == 0; 173 return strcmp (s1, s2) == 0;
175} 174}
176 175
177
178/** 176/**
179 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively). 177 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively).
180 * Any matching items in the inventory are deleted, and a 178 * Any matching items in the inventory are deleted, and a
181 * message is displayed to the player. 179 * message is displayed to the player.
182 */ 180 */
194 192
195 if (tmp->type == item->type 193 if (tmp->type == item->type
196 && same_string (tmp->name, item->name) 194 && same_string (tmp->name, item->name)
197 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying)) 195 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying))
198 { 196 {
199
200 /* message */ 197 /* message */
201 if (tmp->nrof > 1) 198 new_draw_info_format (NDI_UNIQUE, 0, op,
202 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumble to dust!", query_short_name (tmp)); 199 tmp->nrof > 1 ? "The %s crumble to dust!" : "The %s crumbles to dust!",
203 else 200 query_short_name (tmp));
204 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp));
205 201
206 tmp->remove (); /* remove obj from players inv. */ 202 tmp->destroy (true);
207 esrv_del_item (op->contr, tmp->count); /* notify client */
208 tmp->destroy (); /* free object */
209 } 203 }
210 204
211 if (tmp->inv) 205 if (tmp->inv)
212 follower_remove_similar_item (tmp, item); 206 follower_remove_similar_item (tmp, item);
213 } 207 }
239 * God gives an item to the player. 233 * God gives an item to the player.
240 */ 234 */
241static int 235static int
242god_gives_present (object *op, object *god, treasure *tr) 236god_gives_present (object *op, object *god, treasure *tr)
243{ 237{
244 object *tmp; 238 if (!tr->item)
245
246 if (follower_has_similar_item (op, &tr->item->clone))
247 return 0; 239 return 0;
248 240
241 if (follower_has_similar_item (op, tr->item))
242 return 0;
243
249 tmp = arch_to_object (tr->item); 244 object *tmp = arch_to_object (tr->item);
250 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp)); 245 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp));
251 tmp = insert_ob_in_ob (tmp, op); 246 op->insert (tmp);
252 if (op->type == PLAYER) 247
253 esrv_send_item (op, tmp);
254 return 1; 248 return 1;
255} 249}
256 250
257/** 251/**
258 * Player prays at altar. 252 * Player prays at altar.
271 return; 265 return;
272 266
273 /* hmm. what happend depends on pl's current god, level, etc */ 267 /* hmm. what happend depends on pl's current god, level, etc */
274 if (!pl_god) 268 if (!pl_god)
275 { /*new convert */ 269 { /*new convert */
276 become_follower (pl, &altar->other_arch->clone); 270 become_follower (pl, altar->other_arch);
277 return; 271 return;
278
279 } 272 }
280 else if (!strcmp (&pl_god->name, altar->other_arch->clone.name)) 273 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
281 { 274 {
282 /* pray at your gods altar */ 275 /* pray at your gods altar */
283 int bonus = (pl->stats.Wis + skill->level) / 10; 276 int bonus = (pl->stats.Wis + skill->level) / 10;
284 277
285 /* we can get neg grace up faster */ 278 /* we can get neg grace up faster */
286 if (pl->stats.grace < 0) 279 if (pl->stats.grace < 0)
287 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10)); 280 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
281
288 /* we can super-charge grace to 2x max */ 282 /* we can super-charge grace to 2x max */
289 if (pl->stats.grace < (2 * pl->stats.maxgrace)) 283 if (pl->stats.grace < 2 * pl->stats.maxgrace)
290 {
291 pl->stats.grace += bonus / 2; 284 pl->stats.grace += bonus / 2;
292 } 285 else
293 if (pl->stats.grace > (2 * pl->stats.maxgrace))
294 {
295 pl->stats.grace = (2 * pl->stats.maxgrace); 286 pl->stats.grace = 2 * pl->stats.maxgrace;
296 }
297 287
298 /* Every once in a while, the god decides to checkup on their 288 /* Every once in a while, the god decides to checkup on their
299 * follower, and may intervene to help them out. 289 * follower, and may intervene to help them out.
300 */ 290 */
301 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */ 291 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
302 292
303 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0) 293 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
304 god_intervention (pl, pl_god, skill); 294 god_intervention (pl, pl_god, skill);
305
306 } 295 }
307 else 296 else
308 { /* praying to another god! */ 297 { /* praying to another god! */
309 uint64 loss = 0; 298 uint64 loss = 0;
310 int angry = 1; 299 int angry = 1;
314 * points to the god of this altar (which we have 303 * points to the god of this altar (which we have
315 * already verified is non null). pl_god->other_arch 304 * already verified is non null). pl_god->other_arch
316 * is the opposing god - we need to verify that exists before 305 * is the opposing god - we need to verify that exists before
317 * using its values. 306 * using its values.
318 */ 307 */
319 if (pl_god->other_arch && (altar->other_arch->name == pl_god->other_arch->name)) 308 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
320 { 309 {
321 angry = 2; 310 angry = 2;
322 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0) 311 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
323 { 312 {
324 object *tmp; 313 object *tmp;
345 334
346 /* May switch Gods, but its random chance based on our current level 335 /* May switch Gods, but its random chance based on our current level
347 * note it gets harder to swap gods the higher we get 336 * note it gets harder to swap gods the higher we get
348 */ 337 */
349 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW))) 338 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
350 {
351 become_follower (pl, &altar->other_arch->clone); 339 become_follower (pl, altar->other_arch);
352 }
353 else 340 else
354 { 341 {
355 /* toss this player off the altar. He can try again. */ 342 /* toss this player off the altar. He can try again. */
356 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar."); 343 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
344 pl->contr->fire_on = 0;
345 pl->speed_left = 1.f;
357 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */ 346 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
358 } 347 }
359 } 348 }
360} 349}
361 350
396 remove = 1; 385 remove = 1;
397 for (tr = god->randomitems->items; tr; tr = tr->next) 386 for (tr = god->randomitems->items; tr; tr = tr->next)
398 { 387 {
399 object *item; 388 object *item;
400 389
401 if (tr->item == NULL) 390 if (!tr->item)
402 continue; 391 continue;
392
403 item = &tr->item->clone; 393 item = tr->item;
404 394
405 /* Basically, see if the matching spell is granted by this god. */ 395 /* Basically, see if the matching spell is granted by this god. */
406 396
407 if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) 397 if (tr->item->type == SPELL && tr->item->object::name == tmp->name)
408 { 398 {
409 remove = 0; 399 remove = 0;
410 break; 400 break;
411 } 401 }
412 } 402 }
403
413 if (remove) 404 if (remove)
414 { 405 do_forget_spell (op, tmp->name);
415 /* just do the work of removing the spell ourselves - we already
416 * know that the player knows the spell
417 */
418 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &tmp->name);
419 player_unready_range_ob (op->contr, tmp);
420 tmp->destroy ();
421 }
422
423 } 406 }
424} 407}
425 408
426/** 409/**
427 * This function is called whenever a player has 410 * This function is called whenever a player has
435 object *old_god = NULL; /* old god */ 418 object *old_god = NULL; /* old god */
436 treasure *tr; 419 treasure *tr;
437 object *item, *skop, *next; 420 object *item, *skop, *next;
438 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */ 421 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */
439 422
440
441 old_god = find_god (determine_god (op)); 423 old_god = find_god (determine_god (op));
442 424
443 /* take away any special god-characteristic items. */ 425 /* take away any special god-characteristic items. */
444 for (item = op->inv; item != NULL; item = next) 426 for (item = op->inv; item; item = next)
445 { 427 {
446 next = item->below; 428 next = item->below;
429
447 // remove all invisible startequip items which are not skill, exp or force 430 // remove all invisible startequip items which are not skill, exp or force
448 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 431 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible &&
449 (item->type != SKILL) && (item->type != FORCE)) 432 (item->type != SKILL) && (item->type != FORCE))
450 { 433 {
451
452 if (item->type == SPELL) 434 if (item->type == SPELL)
435 {
453 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name); 436 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name);
437 esrv_remove_spell (op->contr, item);
438 }
454 439
455 player_unready_range_ob (op->contr, item); 440 player_unready_range_ob (op->contr, item);
456 item->destroy (); 441 item->destroy (true);
457 } 442 }
458 } 443 }
459 444
460 /* remove any godgiven items from the old god */ 445 /* remove any godgiven items from the old god */
461 if (old_god) 446 if (old_god)
462 {
463 for (tr = old_god->randomitems->items; tr != NULL; tr = tr->next) 447 for (tr = old_god->randomitems->items; tr; tr = tr->next)
464 {
465 if (tr->item && QUERY_FLAG (&tr->item->clone, FLAG_STARTEQUIP)) 448 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP))
466 follower_remove_similar_item (op, &tr->item->clone); 449 follower_remove_similar_item (op, tr->item);
467 }
468 }
469 450
470 if (!op || !new_god) 451 if (!op || !new_god)
471 return; 452 return;
472 453
473 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 454 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying))
474 { 455 {
475 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 456 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name);
457
476 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 458 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0)
477 { 459 {
478 object *tmp = get_archetype (LOOSE_MANA); 460 object *tmp = get_archetype (LOOSE_MANA);
479 461
480 cast_magic_storm (op, tmp, new_god->level + 10); 462 cast_magic_storm (op, tmp, new_god->level + 10);
481 } 463 }
464
482 return; 465 return;
483 } 466 }
484 467
485
486 /* give the player any special god-characteristic-items. */ 468 /* give the player any special god-characteristic-items. */
487 for (tr = new_god->randomitems->items; tr != NULL; tr = tr->next) 469 for (tr = new_god->randomitems->items; tr; tr = tr->next)
488 { 470 {
489 if (tr->item && tr->item->clone.invisible && tr->item->clone.type != SPELLBOOK && 471 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
490 tr->item->clone.type != BOOK && tr->item->clone.type != SPELL) 472 && tr->item->type != BOOK && tr->item->type != SPELL)
491 god_gives_present (op, new_god, tr); 473 god_gives_present (op, new_god, tr);
492 } 474 }
493 475
494
495 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name); 476 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name);
496 477
497 for (skop = op->inv; skop != NULL; skop = skop->below) 478 for (skop = op->inv; skop; skop = skop->below)
498 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 479 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
499 break; 480 break;
500 481
501 /* Player has no skill - give them the skill */ 482 /* Player has no skill - give them the skill */
502 if (!skop) 483 if (!skop)
503 {
504 /* The arhetype should always be defined - if we crash here because it doesn't, 484 /* The archetype should always be defined - if we crash here because it doesn't,
505 * things are really messed up anyways. 485 * things are really messed up anyways.
506 */ 486 */
507 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->clone.skill); 487 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill);
508 link_player_skills (op);
509 }
510 488
511 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 489 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
512 490
513 /* Clear the "undead" status. We also need to force a call to change_abil, 491 /* Clear the "undead" status. We also need to force a call to change_abil,
514 * so I set undeadified for that. 492 * so I set undeadified for that.
515 * - gros, 21th July 2006. 493 * - gros, 21th July 2006.
516 */ 494 */
517 if ((old_god) && (QUERY_FLAG (old_god, FLAG_UNDEAD))) 495 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD))
518 { 496 {
519 CLEAR_FLAG (skop, FLAG_UNDEAD); 497 CLEAR_FLAG (skop, FLAG_UNDEAD);
520 undeadified = 1; 498 undeadified = 1;
521 } 499 }
522 500
523 if (skop->title) 501 if (skop->title)
524 { /* get rid of old god */ 502 {
503 /* get rid of old god */
525 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title); 504 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title);
505
526 /* The point of this is to really show what abilities the player just lost */ 506 /* The point of this is to really show what abilities the player just lost */
527 if (sk_applied || undeadified) 507 if (sk_applied || undeadified)
528 { 508 {
529
530 CLEAR_FLAG (skop, FLAG_APPLIED); 509 CLEAR_FLAG (skop, FLAG_APPLIED);
531 (void) change_abil (op, skop); 510 change_abil (op, skop);
532 } 511 }
533 } 512 }
534 513
535 /* now change to the new gods attributes to exp_obj */ 514 /* now change to the new gods attributes to exp_obj */
536 skop->title = new_god->name; 515 skop->title = new_god->name;
571 * This also can happen for monks which cannot use weapons. In this case 550 * This also can happen for monks which cannot use weapons. In this case
572 * do not allow to use weapons even if the god otherwise would allow it. 551 * do not allow to use weapons even if the god otherwise would allow it.
573 */ 552 */
574 if (!present_in_ob_by_name (FORCE, "no weapon force", op)) 553 if (!present_in_ob_by_name (FORCE, "no weapon force", op))
575 update_priest_flag (new_god, skop, FLAG_USE_WEAPON); 554 update_priest_flag (new_god, skop, FLAG_USE_WEAPON);
555
576 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR); 556 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR);
577 557
578 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons")) 558 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons"))
579 stop_using_item (op, WEAPON, 2); 559 stop_using_item (op, WEAPON, 2);
580 560
606 */ 586 */
607 587
608int 588int
609worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string) 589worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
610{ 590{
611
612 if (QUERY_FLAG (&op->arch->clone, flag)) 591 if (QUERY_FLAG (op->arch, flag))
613 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag)) 592 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
614 { 593 {
615 update_priest_flag (exp_obj, op, flag); 594 update_priest_flag (exp_obj, op, flag);
616 if (QUERY_FLAG (op, flag)) 595 if (QUERY_FLAG (op, flag))
617 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string); 596 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
619 { 598 {
620 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string); 599 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
621 return 1; 600 return 1;
622 } 601 }
623 } 602 }
603
624 return 0; 604 return 0;
625} 605}
626 606
627/** 607/**
628 * Unapplies up to number worth of items of type 608 * Unapplies up to number worth of items of type
665/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/ 645/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
666 CLEAR_FLAG (exp_ob, flag); 646 CLEAR_FLAG (exp_ob, flag);
667 }; 647 };
668} 648}
669 649
670
671
672archetype * 650archetype *
673determine_holy_arch (object *god, const char *type) 651determine_holy_arch (object *god, const char *type)
674{ 652{
675 treasure *tr; 653 treasure *tr;
676 654
677 if (!god || !god->randomitems) 655 if (!god || !god->randomitems)
678 { 656 {
679 LOG (llevError, "BUG: determine_holy_arch(): no god or god without " "randomitems\n"); 657 LOG (llevError, "BUG: determine_holy_arch(): no god or god without " "randomitems\n");
680 return NULL; 658 return 0;
681 } 659 }
682 660
683 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) 661 for (tr = god->randomitems->items; tr; tr = tr->next)
684 { 662 {
685 object *item;
686
687 if (!tr->item) 663 if (!tr->item)
688 continue; 664 continue;
689 item = &tr->item->clone; 665
666 object *item = tr->item;
690 667
691 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 668 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0)
692 return item->other_arch; 669 return item->other_arch;
693 } 670 }
671
694 return NULL; 672 return 0;
695} 673}
696 674
697/** 675/**
698 * God helps player by removing curse and/or damnation. 676 * God helps player by removing curse and/or damnation.
699 */ 677 */
700static int 678static int
701god_removes_curse (object *op, int remove_damnation) 679god_removes_curse (object *op, int remove_damnation)
702{ 680{
703 object *tmp;
704 int success = 0; 681 int success = 0;
705 682
706 for (tmp = op->inv; tmp; tmp = tmp->below) 683 for (object *tmp = op->inv; tmp; tmp = tmp->below)
707 { 684 {
708 if (tmp->invisible) 685 if (tmp->invisible)
709 continue; 686 continue;
687
710 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 688 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation)
711 continue; 689 continue;
690
712 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 691 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
713 { 692 {
714 success = 1; 693 success = 1;
715 CLEAR_FLAG (tmp, FLAG_DAMNED); 694 CLEAR_FLAG (tmp, FLAG_DAMNED);
716 CLEAR_FLAG (tmp, FLAG_CURSED); 695 CLEAR_FLAG (tmp, FLAG_CURSED);
717 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 696 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED);
718 if (op->type == PLAYER) 697
698 if (object *pl = tmp->visible_to ())
719 esrv_send_item (op, tmp); 699 esrv_update_item (UPD_FLAGS, pl, tmp);
720 } 700 }
721 } 701 }
722 702
723 if (success) 703 if (success)
724 new_draw_info (NDI_UNIQUE, 0, op, "You feel like someone is helping you."); 704 new_draw_info (NDI_UNIQUE, 0, op, "You feel like someone is helping you.");
705
725 return success; 706 return success;
726} 707}
727 708
728static int 709static int
729follower_level_to_enchantments (int level, int difficulty) 710follower_level_to_enchantments (int level, int difficulty)
734 return 0; 715 return 0;
735 } 716 }
736 717
737 if (level <= 20) 718 if (level <= 20)
738 return level / difficulty; 719 return level / difficulty;
720
739 if (level <= 40) 721 if (level <= 40)
740 return (20 + (level - 20) / 2) / difficulty; 722 return (20 + (level - 20) / 2) / difficulty;
723
741 return (30 + (level - 40) / 4) / difficulty; 724 return (30 + (level - 40) / 4) / difficulty;
742} 725}
743 726
744/** 727/**
745 * God wants to enchant weapon. 728 * God wants to enchant weapon.
748 * attacktype, slaying and such. 731 * attacktype, slaying and such.
749 */ 732 */
750static int 733static int
751god_enchants_weapon (object *op, object *god, object *tr, object *skill) 734god_enchants_weapon (object *op, object *god, object *tr, object *skill)
752{ 735{
753 char buf[MAX_BUF];
754 object *weapon; 736 object *weapon;
755 uint32 attacktype; 737 uint32 attacktype;
756 int tmp; 738 int tmp;
757 739
758 for (weapon = op->inv; weapon; weapon = weapon->below) 740 for (weapon = op->inv; weapon; weapon = weapon->below)
759 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED)) 741 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED))
760 break; 742 break;
743
761 if (weapon == NULL || god_examines_item (god, weapon) <= 0) 744 if (!weapon || god_examines_item (god, weapon) <= 0)
762 return 0; 745 return 0;
763 746
764 /* First give it a title, so other gods won't touch it */ 747 /* First give it a title, so other gods won't touch it */
765 if (!weapon->title) 748 if (!weapon->title)
766 { 749 {
767 sprintf (buf, "of %s", &god->name); 750 weapon->title = format ("of %s", &god->name);
768 weapon->title = buf; 751
769 if (op->type == PLAYER) 752 if (object *pl = weapon->visible_to ())
770 esrv_update_item (UPD_NAME, op, weapon); 753 esrv_update_item (UPD_NAME, pl, weapon);
754
771 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon quivers as if struck!"); 755 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon quivers as if struck!");
772 } 756 }
773 757
774 /* Allow the weapon to slay enemies */ 758 /* Allow the weapon to slay enemies */
775 if (!weapon->slaying && god->slaying) 759 if (!weapon->slaying && god->slaying)
792 tmp = follower_level_to_enchantments (skill->level, tr->level); 776 tmp = follower_level_to_enchantments (skill->level, tr->level);
793 if (weapon->magic < tmp) 777 if (weapon->magic < tmp)
794 { 778 {
795 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!"); 779 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!");
796 weapon->magic++; 780 weapon->magic++;
797 if (op->type == PLAYER) 781
782 if (object *pl = weapon->visible_to ())
798 esrv_update_item (UPD_NAME, op, weapon); 783 esrv_update_item (UPD_NAME, pl, weapon);
784
799 return 1; 785 return 1;
800 } 786 }
801 787
802 return 0; 788 return 0;
803} 789}
804
805 790
806/** 791/**
807 * Every once in a while the god will intervene to help the worshiper. 792 * Every once in a while the god will intervene to help the worshiper.
808 * Later, this fctn can be used to supply quests, etc for the 793 * Later, this fctn can be used to supply quests, etc for the
809 * priest. -b.t. 794 * priest. -b.t.
810 * called from pray_at_altar() currently. 795 * called from pray_at_altar() currently.
811 */ 796 */
812
813void 797void
814god_intervention (object *op, object *god, object *skill) 798god_intervention (object *op, object *god, object *skill)
815{ 799{
816 treasure *tr; 800 treasure *tr;
817 801
825 809
826 /* lets do some checks of whether we are kosher with our god */ 810 /* lets do some checks of whether we are kosher with our god */
827 if (god_examines_priest (op, god) < 0) 811 if (god_examines_priest (op, god) < 0)
828 return; 812 return;
829 813
814 op->play_sound (sound_find ("god_intervention"));
830 new_draw_info (NDI_UNIQUE, 0, op, "You feel a holy presence!"); 815 new_draw_info (NDI_UNIQUE, 0, op, "You feel a holy presence!");
831 816
832 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) 817 for (tr = god->randomitems->items; tr; tr = tr->next)
833 { 818 {
834 object *item; 819 object *item;
835 820
836 if (tr->chance <= random_roll (0, 99, op, PREFER_HIGH)) 821 if (tr->chance <= random_roll (0, 99, op, PREFER_HIGH))
837 continue; 822 continue;
838 823
839 /* Treasurelist - generate some treasure for the follower */ 824 /* Treasurelist - generate some treasure for the follower */
840 if (tr->name) 825 if (tr->name)
841 { 826 {
842 treasurelist *tl = find_treasurelist (tr->name); 827 treasurelist *tl = treasurelist::find (tr->name);
843 828
844 if (tl == NULL) 829 if (tl == NULL)
845 continue; 830 continue;
846 831
847 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your " "eyes. You catch it before it falls to the ground."); 832 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your eyes. You catch it before it falls to the ground.");
848 833
849 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD | GT_UPDATE_INV, skill->level, 0); 834 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD, skill->level, 0);
850 return; 835 return;
851 } 836 }
852 837
853 if (!tr->item) 838 if (!tr->item)
854 {
855 LOG (llevError, "BUG: empty entry in %s's treasure list\n", &god->name);
856 continue; 839 continue;
857 } 840
858 item = &tr->item->clone; 841 item = tr->item;
859 842
860 /* Grace limit */ 843 /* Grace limit */
861 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 844 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0)
862 { 845 {
863 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 846 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
867 /* Follower lacks the required grace for the following 850 /* Follower lacks the required grace for the following
868 * treasure list items. */ 851 * treasure list items. */
869 852
870 tmp = get_archetype (HOLY_POSSESSION); 853 tmp = get_archetype (HOLY_POSSESSION);
871 cast_change_ability (op, op, tmp, 0, 1); 854 cast_change_ability (op, op, tmp, 0, 1);
872 tmp->destroy (); 855 tmp->destroy (true);
873 return; 856 return;
874 } 857 }
858
875 continue; 859 continue;
876 } 860 }
877 861
878 /* Restore grace */ 862 /* Restore grace */
879 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 863 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0)
903 /* Restore to 50 .. 100%, if sp < 50% */ 887 /* Restore to 50 .. 100%, if sp < 50% */
904 int new_sp = (int) (random_roll (1000, 1999, op, PREFER_HIGH) / 2000.0 * max); 888 int new_sp = (int) (random_roll (1000, 1999, op, PREFER_HIGH) / 2000.0 * max);
905 889
906 if (op->stats.sp >= max / 2) 890 if (op->stats.sp >= max / 2)
907 continue; 891 continue;
892
908 new_draw_info (NDI_UNIQUE, 0, op, "A blue lightning strikes " "your head but doesn't hurt you!"); 893 new_draw_info (NDI_UNIQUE, 0, op, "A blue lightning strikes your head but doesn't hurt you!");
909 op->stats.sp = new_sp; 894 op->stats.sp = new_sp;
910 } 895 }
911 896
912 /* Various heal spells */ 897 /* Various heal spells */
913 if (item->type == BOOK && item->invisible && strcmp (item->name, "heal spell") == 0) 898 if (item->type == BOOK && item->invisible && strcmp (item->name, "heal spell") == 0)
914 { 899 {
915 object *tmp;
916 int success;
917
918 tmp = get_archetype_by_object_name (item->slaying); 900 object *tmp = archetype::get (item->slaying);
919
920 success = cast_heal (op, op, tmp, 0); 901 int success = cast_heal (op, op, tmp, 0);
921 tmp->destroy (); 902 tmp->destroy (true);
903
922 if (success) 904 if (success)
923 return; 905 return;
924 else 906 else
925 continue; 907 continue;
926 } 908 }
961 continue; 943 continue;
962 944
963 new_draw_info (NDI_UNIQUE, 0, op, "Shimmering light surrounds and restores you!"); 945 new_draw_info (NDI_UNIQUE, 0, op, "Shimmering light surrounds and restores you!");
964 946
965 for (i = 0; i < NUM_STATS; i++) 947 for (i = 0; i < NUM_STATS; i++)
966 if (get_attr_value (&depl->stats, i)) 948 if (depl->stats.stat (i))
967 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 949 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
968 950
969 depl->destroy (); 951 depl->destroy (true);
970 fix_player (op); 952 op->update_stats ();
971 return; 953 return;
972 } 954 }
973 955
974 /* Voices */ 956 /* Voices */
975 if (item->type == BOOK && item->invisible && strcmp (item->name, "voice_behind") == 0) 957 if (item->type == BOOK && item->invisible && strcmp (item->name, "voice_behind") == 0)
976 { 958 {
977 new_draw_info (NDI_UNIQUE, 0, op, "You hear a voice from behind you, but you don't dare to " "turn around:"); 959 new_draw_info (NDI_UNIQUE, 0, op, "You hear a voice from behind you, but you don't dare to turn around:");
978 new_draw_info (NDI_WHITE, 0, op, item->msg); 960 new_draw_info (NDI_WHITE, 0, op, item->msg);
979 return; 961 return;
980 } 962 }
981 963
982 /* Messages */ 964 /* Messages */
1033{ 1015{
1034 int reaction = 1; 1016 int reaction = 1;
1035 object *item = NULL, *skop; 1017 object *item = NULL, *skop;
1036 1018
1037 for (item = op->inv; item; item = item->below) 1019 for (item = op->inv; item; item = item->below)
1038 {
1039 if (QUERY_FLAG (item, FLAG_APPLIED)) 1020 if (QUERY_FLAG (item, FLAG_APPLIED))
1040 {
1041 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1); 1021 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
1042 }
1043 }
1044 1022
1045 /* well, well. Looks like we screwed up. Time for god's revenge */ 1023 /* well, well. Looks like we screwed up. Time for god's revenge */
1046 if (reaction < 0) 1024 if (reaction < 0)
1047 { 1025 {
1048 int loss = 10000000; 1026 int loss = 10000000;
1049 int angry = abs (reaction); 1027 int angry = abs (reaction);
1050 1028
1051 for (skop = op->inv; skop != NULL; skop = skop->below) 1029 for (skop = op->inv; skop; skop = skop->below)
1052 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 1030 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1053 break; 1031 break;
1054 1032
1055 if (skop) 1033 if (skop)
1056 loss = (int) (0.05 * (float) skop->stats.exp); 1034 loss = 0.05f * skop->stats.exp;
1035
1057 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP); 1036 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1037
1058 if (random_roll (0, angry, op, PREFER_LOW)) 1038 if (random_roll (0, angry, op, PREFER_LOW))
1059 { 1039 {
1060 object *tmp = get_archetype (LOOSE_MANA); 1040 object *tmp = get_archetype (LOOSE_MANA);
1061 1041
1062 cast_magic_storm (op, tmp, op->level + (angry * 3)); 1042 cast_magic_storm (op, tmp, op->level + (angry * 3));
1063 } 1043 }
1044
1064 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name); 1045 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1065 } 1046 }
1047
1066 return reaction; 1048 return reaction;
1067} 1049}
1068 1050
1069/** 1051/**
1070 * God checks item the player is using. 1052 * God checks item the player is using.
1133 1115
1134 if (race == NULL) 1116 if (race == NULL)
1135 return NULL; 1117 return NULL;
1136 while (gl) 1118 while (gl)
1137 { 1119 {
1138 if (!strcasecmp (gl->arch->clone.race, race)) 1120 if (!strcasecmp (gl->arch->race, race))
1139 { 1121 {
1140 godname = gl->name; 1122 godname = gl->name;
1141 break; 1123 break;
1142 } 1124 }
1143 gl = gl->next; 1125 gl = gl->next;
1148/** 1130/**
1149 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1131 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1150 * Returns false if there was no race to assign to the slaying field of the spell, but 1132 * Returns false if there was no race to assign to the slaying field of the spell, but
1151 * the spell attacktype contains AT_HOLYWORD. -b.t. 1133 * the spell attacktype contains AT_HOLYWORD. -b.t.
1152 */ 1134 */
1153
1154int 1135int
1155tailor_god_spell (object *spellop, object *caster) 1136tailor_god_spell (object *spellop, object *caster)
1156{ 1137{
1157 object *god = find_god (determine_god (caster)); 1138 object *god = find_god (determine_god (caster));
1158 int caster_is_spell = 0; 1139 int caster_is_spell = 0;
1172 if (!caster_is_spell) 1153 if (!caster_is_spell)
1173 new_draw_info (NDI_UNIQUE, 0, caster, "This prayer is useless unless you worship an appropriate god"); 1154 new_draw_info (NDI_UNIQUE, 0, caster, "This prayer is useless unless you worship an appropriate god");
1174 else 1155 else
1175 LOG (llevError, "BUG: tailor_god_spell(): no god\n"); 1156 LOG (llevError, "BUG: tailor_god_spell(): no god\n");
1176 1157
1177 spellop->destroy (); 1158 spellop->destroy (true);
1178 return 0; 1159 return 0;
1179 } 1160 }
1180 1161
1181 /* either holy word or godpower attacks will set the slaying field */ 1162 /* either holy word or godpower attacks will set the slaying field */
1182 if (spellop->attacktype & AT_HOLYWORD || spellop->attacktype & AT_GODPOWER) 1163 if (spellop->attacktype & AT_HOLYWORD || spellop->attacktype & AT_GODPOWER)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines