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.18 by pippijn, Mon Jan 15 21:06:20 2007 UTC vs.
Revision 1.40 by root, Mon Sep 29 10:32:50 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 (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24
25 23
26/* 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
27 * monster race initialization. b.t. 25 * monster race initialization. b.t.
28 */ 26 */
29 27
50 godlink *gl; 48 godlink *gl;
51 49
52 for (gl = first_god; gl; gl = gl->next) 50 for (gl = first_god; gl; gl = gl->next)
53 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)))
54 break; 52 break;
53
55 if (gl) 54 if (gl)
56 godnr = gl->id; 55 godnr = gl->id;
57 } 56 }
57
58 return godnr; 58 return godnr;
59} 59}
60 60
61/** 61/**
62 * 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..
104 { 104 {
105 105
106 /* find a god based on race */ 106 /* find a god based on race */
107 if (!op->title) 107 if (!op->title)
108 { 108 {
109 if (op->race != NULL) 109 if (op->race)
110 { 110 {
111 godname = get_god_for_race (op->race); 111 godname = get_god_for_race (op->race);
112
112 if (godname != NULL) 113 if (godname)
113 {
114 op->title = godname; 114 op->title = godname;
115 }
116 } 115 }
117 } 116 }
118 117
119 /* find a random god */ 118 /* find a random god */
120 if (!op->title) 119 if (!op->title)
124 godnr = rndm (1, gl->id); 123 godnr = rndm (1, gl->id);
125 while (gl) 124 while (gl)
126 { 125 {
127 if (gl->id == godnr) 126 if (gl->id == godnr)
128 break; 127 break;
128
129 gl = gl->next; 129 gl = gl->next;
130 } 130 }
131
131 op->title = gl->name; 132 op->title = gl->name;
132 } 133 }
133 134
134 return op->title; 135 return op->title;
135 } 136 }
140 * 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
141 * title or "none". 142 * title or "none".
142 */ 143 */
143 if (op->type == PLAYER) 144 if (op->type == PLAYER)
144 { 145 {
145 object *tmp;
146
147 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 146 for (object *tmp = op->inv; tmp; tmp = tmp->below)
148 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING) 147 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING)
149 { 148 {
150 if (tmp->title) 149 if (tmp->title)
151 return (tmp->title); 150 return tmp->title;
152 else 151 else
153 return ("none"); 152 return "none";
154 } 153 }
155 } 154 }
155
156 return ("none"); 156 return "none";
157} 157}
158 158
159/** 159/**
160 * 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
161 */ 161 */
171 return 0; 171 return 0;
172 else 172 else
173 return strcmp (s1, s2) == 0; 173 return strcmp (s1, s2) == 0;
174} 174}
175 175
176
177/** 176/**
178 * 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).
179 * Any matching items in the inventory are deleted, and a 178 * Any matching items in the inventory are deleted, and a
180 * message is displayed to the player. 179 * message is displayed to the player.
181 */ 180 */
193 192
194 if (tmp->type == item->type 193 if (tmp->type == item->type
195 && same_string (tmp->name, item->name) 194 && same_string (tmp->name, item->name)
196 && 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))
197 { 196 {
198
199 /* message */ 197 /* message */
200 if (tmp->nrof > 1) 198 new_draw_info_format (NDI_UNIQUE, 0, op,
201 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!",
202 else 200 query_short_name (tmp));
203 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp));
204 201
205 tmp->remove (); /* remove obj from players inv. */ 202 tmp->destroy ();
206 esrv_del_item (op->contr, tmp->count); /* notify client */
207 tmp->destroy (); /* free object */
208 } 203 }
209 204
210 if (tmp->inv) 205 if (tmp->inv)
211 follower_remove_similar_item (tmp, item); 206 follower_remove_similar_item (tmp, item);
212 } 207 }
238 * God gives an item to the player. 233 * God gives an item to the player.
239 */ 234 */
240static int 235static int
241god_gives_present (object *op, object *god, treasure *tr) 236god_gives_present (object *op, object *god, treasure *tr)
242{ 237{
243 object *tmp;
244
245 if (!tr->item) 238 if (!tr->item)
246 return 0; 239 return 0;
247 240
248 if (follower_has_similar_item (op, &tr->item->clone)) 241 if (follower_has_similar_item (op, tr->item))
249 return 0; 242 return 0;
250 243
251 tmp = arch_to_object (tr->item); 244 object *tmp = arch_to_object (tr->item);
252 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));
253 tmp = insert_ob_in_ob (tmp, op); 246 op->insert (tmp);
254 if (op->type == PLAYER)
255 esrv_send_item (op, tmp);
256 247
257 return 1; 248 return 1;
258} 249}
259 250
260/** 251/**
274 return; 265 return;
275 266
276 /* hmm. what happend depends on pl's current god, level, etc */ 267 /* hmm. what happend depends on pl's current god, level, etc */
277 if (!pl_god) 268 if (!pl_god)
278 { /*new convert */ 269 { /*new convert */
279 become_follower (pl, &altar->other_arch->clone); 270 become_follower (pl, altar->other_arch);
280 return; 271 return;
281
282 } 272 }
283 else if (!strcmp (&pl_god->name, altar->other_arch->clone.name)) 273 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
284 { 274 {
285 /* pray at your gods altar */ 275 /* pray at your gods altar */
286 int bonus = (pl->stats.Wis + skill->level) / 10; 276 int bonus = (pl->stats.Wis + skill->level) / 10;
287 277
288 /* we can get neg grace up faster */ 278 /* we can get neg grace up faster */
289 if (pl->stats.grace < 0) 279 if (pl->stats.grace < 0)
290 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
291 /* we can super-charge grace to 2x max */ 282 /* we can super-charge grace to 2x max */
292 if (pl->stats.grace < (2 * pl->stats.maxgrace)) 283 if (pl->stats.grace < 2 * pl->stats.maxgrace)
293 {
294 pl->stats.grace += bonus / 2; 284 pl->stats.grace += bonus / 2;
295 } 285 else
296 if (pl->stats.grace > (2 * pl->stats.maxgrace))
297 {
298 pl->stats.grace = (2 * pl->stats.maxgrace); 286 pl->stats.grace = 2 * pl->stats.maxgrace;
299 }
300 287
301 /* 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
302 * follower, and may intervene to help them out. 289 * follower, and may intervene to help them out.
303 */ 290 */
304 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */ 291 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
305 292
306 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0) 293 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
307 god_intervention (pl, pl_god, skill); 294 god_intervention (pl, pl_god, skill);
308
309 } 295 }
310 else 296 else
311 { /* praying to another god! */ 297 { /* praying to another god! */
312 uint64 loss = 0; 298 uint64 loss = 0;
313 int angry = 1; 299 int angry = 1;
317 * points to the god of this altar (which we have 303 * points to the god of this altar (which we have
318 * already verified is non null). pl_god->other_arch 304 * already verified is non null). pl_god->other_arch
319 * is the opposing god - we need to verify that exists before 305 * is the opposing god - we need to verify that exists before
320 * using its values. 306 * using its values.
321 */ 307 */
322 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))
323 { 309 {
324 angry = 2; 310 angry = 2;
325 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)
326 { 312 {
327 object *tmp; 313 object *tmp;
348 334
349 /* 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
350 * note it gets harder to swap gods the higher we get 336 * note it gets harder to swap gods the higher we get
351 */ 337 */
352 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW))) 338 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
353 {
354 become_follower (pl, &altar->other_arch->clone); 339 become_follower (pl, altar->other_arch);
355 }
356 else 340 else
357 { 341 {
358 /* toss this player off the altar. He can try again. */ 342 /* toss this player off the altar. He can try again. */
359 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;
360 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. */
361 } 347 }
362 } 348 }
363} 349}
364 350
401 { 387 {
402 object *item; 388 object *item;
403 389
404 if (!tr->item) 390 if (!tr->item)
405 continue; 391 continue;
392
406 item = &tr->item->clone; 393 item = tr->item;
407 394
408 /* Basically, see if the matching spell is granted by this god. */ 395 /* Basically, see if the matching spell is granted by this god. */
409 396
410 if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) 397 if (tr->item->type == SPELL && tr->item->object::name == tmp->name)
411 { 398 {
412 remove = 0; 399 remove = 0;
413 break; 400 break;
414 } 401 }
415 } 402 }
403
416 if (remove) 404 if (remove)
417 { 405 do_forget_spell (op, tmp->name);
418 /* just do the work of removing the spell ourselves - we already
419 * know that the player knows the spell
420 */
421 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &tmp->name);
422 player_unready_range_ob (op->contr, tmp);
423 tmp->destroy ();
424 }
425
426 } 406 }
427} 407}
428 408
429/** 409/**
430 * This function is called whenever a player has 410 * This function is called whenever a player has
438 object *old_god = NULL; /* old god */ 418 object *old_god = NULL; /* old god */
439 treasure *tr; 419 treasure *tr;
440 object *item, *skop, *next; 420 object *item, *skop, *next;
441 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. */
442 422
443
444 old_god = find_god (determine_god (op)); 423 old_god = find_god (determine_god (op));
445 424
446 /* take away any special god-characteristic items. */ 425 /* take away any special god-characteristic items. */
447 for (item = op->inv; item != NULL; item = next) 426 for (item = op->inv; item; item = next)
448 { 427 {
449 next = item->below; 428 next = item->below;
429
450 // 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
451 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 431 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible &&
452 (item->type != SKILL) && (item->type != FORCE)) 432 (item->type != SKILL) && (item->type != FORCE))
453 { 433 {
454
455 if (item->type == SPELL) 434 if (item->type == SPELL)
435 {
456 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 }
457 439
458 player_unready_range_ob (op->contr, item); 440 player_unready_range_ob (op->contr, item);
459 item->destroy (); 441 item->destroy ();
460 } 442 }
461 } 443 }
462 444
463 /* remove any godgiven items from the old god */ 445 /* remove any godgiven items from the old god */
464 if (old_god) 446 if (old_god)
465 {
466 for (tr = old_god->randomitems->items; tr != NULL; tr = tr->next) 447 for (tr = old_god->randomitems->items; tr; tr = tr->next)
467 {
468 if (tr->item && QUERY_FLAG (&tr->item->clone, FLAG_STARTEQUIP)) 448 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP))
469 follower_remove_similar_item (op, &tr->item->clone); 449 follower_remove_similar_item (op, tr->item);
470 }
471 }
472 450
473 if (!op || !new_god) 451 if (!op || !new_god)
474 return; 452 return;
475 453
476 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))
477 { 455 {
478 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
479 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)
480 { 459 {
481 object *tmp = get_archetype (LOOSE_MANA); 460 object *tmp = get_archetype (LOOSE_MANA);
482 461
483 cast_magic_storm (op, tmp, new_god->level + 10); 462 cast_magic_storm (op, tmp, new_god->level + 10);
484 } 463 }
464
485 return; 465 return;
486 } 466 }
487 467
488
489 /* give the player any special god-characteristic-items. */ 468 /* give the player any special god-characteristic-items. */
490 for (tr = new_god->randomitems->items; tr != NULL; tr = tr->next) 469 for (tr = new_god->randomitems->items; tr; tr = tr->next)
491 { 470 {
492 if (tr->item && tr->item->clone.invisible && tr->item->clone.type != SPELLBOOK && 471 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
493 tr->item->clone.type != BOOK && tr->item->clone.type != SPELL) 472 && tr->item->type != BOOK && tr->item->type != SPELL)
494 god_gives_present (op, new_god, tr); 473 god_gives_present (op, new_god, tr);
495 } 474 }
496 475
497
498 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);
499 477
500 for (skop = op->inv; skop != NULL; skop = skop->below) 478 for (skop = op->inv; skop; skop = skop->below)
501 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 479 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
502 break; 480 break;
503 481
504 /* Player has no skill - give them the skill */ 482 /* Player has no skill - give them the skill */
505 if (!skop) 483 if (!skop)
506 {
507 /* 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,
508 * things are really messed up anyways. 485 * things are really messed up anyways.
509 */ 486 */
510 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);
511 link_player_skills (op);
512 }
513 488
514 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 489 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
515 490
516 /* 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,
517 * so I set undeadified for that. 492 * so I set undeadified for that.
518 * - gros, 21th July 2006. 493 * - gros, 21th July 2006.
519 */ 494 */
520 if ((old_god) && (QUERY_FLAG (old_god, FLAG_UNDEAD))) 495 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD))
521 { 496 {
522 CLEAR_FLAG (skop, FLAG_UNDEAD); 497 CLEAR_FLAG (skop, FLAG_UNDEAD);
523 undeadified = 1; 498 undeadified = 1;
524 } 499 }
525 500
526 if (skop->title) 501 if (skop->title)
527 { /* get rid of old god */ 502 {
503 /* get rid of old god */
528 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
529 /* 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 */
530 if (sk_applied || undeadified) 507 if (sk_applied || undeadified)
531 { 508 {
532
533 CLEAR_FLAG (skop, FLAG_APPLIED); 509 CLEAR_FLAG (skop, FLAG_APPLIED);
534 (void) change_abil (op, skop); 510 change_abil (op, skop);
535 } 511 }
536 } 512 }
537 513
538 /* now change to the new gods attributes to exp_obj */ 514 /* now change to the new gods attributes to exp_obj */
539 skop->title = new_god->name; 515 skop->title = new_god->name;
574 * 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
575 * 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.
576 */ 552 */
577 if (!present_in_ob_by_name (FORCE, "no weapon force", op)) 553 if (!present_in_ob_by_name (FORCE, "no weapon force", op))
578 update_priest_flag (new_god, skop, FLAG_USE_WEAPON); 554 update_priest_flag (new_god, skop, FLAG_USE_WEAPON);
555
579 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR); 556 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR);
580 557
581 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons")) 558 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons"))
582 stop_using_item (op, WEAPON, 2); 559 stop_using_item (op, WEAPON, 2);
583 560
609 */ 586 */
610 587
611int 588int
612worship_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)
613{ 590{
614
615 if (QUERY_FLAG (&op->arch->clone, flag)) 591 if (QUERY_FLAG (op->arch, flag))
616 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag)) 592 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
617 { 593 {
618 update_priest_flag (exp_obj, op, flag); 594 update_priest_flag (exp_obj, op, flag);
619 if (QUERY_FLAG (op, flag)) 595 if (QUERY_FLAG (op, flag))
620 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);
622 { 598 {
623 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);
624 return 1; 600 return 1;
625 } 601 }
626 } 602 }
603
627 return 0; 604 return 0;
628} 605}
629 606
630/** 607/**
631 * Unapplies up to number worth of items of type 608 * Unapplies up to number worth of items of type
668/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/ 645/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
669 CLEAR_FLAG (exp_ob, flag); 646 CLEAR_FLAG (exp_ob, flag);
670 }; 647 };
671} 648}
672 649
673
674
675archetype * 650archetype *
676determine_holy_arch (object *god, const char *type) 651determine_holy_arch (object *god, const char *type)
677{ 652{
678 treasure *tr; 653 treasure *tr;
679 654
680 if (!god || !god->randomitems) 655 if (!god || !god->randomitems)
681 { 656 {
682 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");
683 return NULL; 658 return 0;
684 } 659 }
685 660
686 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) 661 for (tr = god->randomitems->items; tr; tr = tr->next)
687 { 662 {
688 object *item;
689
690 if (!tr->item) 663 if (!tr->item)
691 continue; 664 continue;
692 665
693 item = &tr->item->clone; 666 object *item = tr->item;
694 667
695 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 668 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0)
696 return item->other_arch; 669 return item->other_arch;
697 } 670 }
671
698 return NULL; 672 return 0;
699} 673}
700 674
701/** 675/**
702 * God helps player by removing curse and/or damnation. 676 * God helps player by removing curse and/or damnation.
703 */ 677 */
704static int 678static int
705god_removes_curse (object *op, int remove_damnation) 679god_removes_curse (object *op, int remove_damnation)
706{ 680{
707 object *tmp;
708 int success = 0; 681 int success = 0;
709 682
710 for (tmp = op->inv; tmp; tmp = tmp->below) 683 for (object *tmp = op->inv; tmp; tmp = tmp->below)
711 { 684 {
712 if (tmp->invisible) 685 if (tmp->invisible)
713 continue; 686 continue;
687
714 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 688 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation)
715 continue; 689 continue;
690
716 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 691 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
717 { 692 {
718 success = 1; 693 success = 1;
719 CLEAR_FLAG (tmp, FLAG_DAMNED); 694 CLEAR_FLAG (tmp, FLAG_DAMNED);
720 CLEAR_FLAG (tmp, FLAG_CURSED); 695 CLEAR_FLAG (tmp, FLAG_CURSED);
721 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 696 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED);
722 if (op->type == PLAYER) 697
698 if (object *pl = tmp->visible_to ())
723 esrv_send_item (op, tmp); 699 esrv_update_item (UPD_FLAGS, pl, tmp);
724 } 700 }
725 } 701 }
726 702
727 if (success) 703 if (success)
728 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
729 return success; 706 return success;
730} 707}
731 708
732static int 709static int
733follower_level_to_enchantments (int level, int difficulty) 710follower_level_to_enchantments (int level, int difficulty)
738 return 0; 715 return 0;
739 } 716 }
740 717
741 if (level <= 20) 718 if (level <= 20)
742 return level / difficulty; 719 return level / difficulty;
720
743 if (level <= 40) 721 if (level <= 40)
744 return (20 + (level - 20) / 2) / difficulty; 722 return (20 + (level - 20) / 2) / difficulty;
723
745 return (30 + (level - 40) / 4) / difficulty; 724 return (30 + (level - 40) / 4) / difficulty;
746} 725}
747 726
748/** 727/**
749 * God wants to enchant weapon. 728 * God wants to enchant weapon.
752 * attacktype, slaying and such. 731 * attacktype, slaying and such.
753 */ 732 */
754static int 733static int
755god_enchants_weapon (object *op, object *god, object *tr, object *skill) 734god_enchants_weapon (object *op, object *god, object *tr, object *skill)
756{ 735{
757 char buf[MAX_BUF];
758 object *weapon; 736 object *weapon;
759 uint32 attacktype; 737 uint32 attacktype;
760 int tmp; 738 int tmp;
761 739
762 for (weapon = op->inv; weapon; weapon = weapon->below) 740 for (weapon = op->inv; weapon; weapon = weapon->below)
763 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))
764 break; 742 break;
743
765 if (weapon == NULL || god_examines_item (god, weapon) <= 0) 744 if (!weapon || god_examines_item (god, weapon) <= 0)
766 return 0; 745 return 0;
767 746
768 /* 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 */
769 if (!weapon->title) 748 if (!weapon->title)
770 { 749 {
771 sprintf (buf, "of %s", &god->name); 750 weapon->title = format ("of %s", &god->name);
772 weapon->title = buf; 751
773 if (op->type == PLAYER) 752 if (object *pl = weapon->visible_to ())
774 esrv_update_item (UPD_NAME, op, weapon); 753 esrv_update_item (UPD_NAME, pl, weapon);
754
775 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!");
776 } 756 }
777 757
778 /* Allow the weapon to slay enemies */ 758 /* Allow the weapon to slay enemies */
779 if (!weapon->slaying && god->slaying) 759 if (!weapon->slaying && god->slaying)
796 tmp = follower_level_to_enchantments (skill->level, tr->level); 776 tmp = follower_level_to_enchantments (skill->level, tr->level);
797 if (weapon->magic < tmp) 777 if (weapon->magic < tmp)
798 { 778 {
799 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!");
800 weapon->magic++; 780 weapon->magic++;
801 if (op->type == PLAYER) 781
782 if (object *pl = weapon->visible_to ())
802 esrv_update_item (UPD_NAME, op, weapon); 783 esrv_update_item (UPD_NAME, pl, weapon);
784
803 return 1; 785 return 1;
804 } 786 }
805 787
806 return 0; 788 return 0;
807} 789}
808
809 790
810/** 791/**
811 * 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.
812 * 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
813 * priest. -b.t. 794 * priest. -b.t.
814 * called from pray_at_altar() currently. 795 * called from pray_at_altar() currently.
815 */ 796 */
816
817void 797void
818god_intervention (object *op, object *god, object *skill) 798god_intervention (object *op, object *god, object *skill)
819{ 799{
820 treasure *tr; 800 treasure *tr;
821 801
829 809
830 /* 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 */
831 if (god_examines_priest (op, god) < 0) 811 if (god_examines_priest (op, god) < 0)
832 return; 812 return;
833 813
814 op->play_sound (sound_find ("god_intervention"));
834 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!");
835 816
836 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) 817 for (tr = god->randomitems->items; tr; tr = tr->next)
837 { 818 {
838 object *item; 819 object *item;
839 820
840 if (tr->chance <= random_roll (0, 99, op, PREFER_HIGH)) 821 if (tr->chance <= random_roll (0, 99, op, PREFER_HIGH))
841 continue; 822 continue;
842 823
843 /* Treasurelist - generate some treasure for the follower */ 824 /* Treasurelist - generate some treasure for the follower */
844 if (tr->name) 825 if (tr->name)
845 { 826 {
846 treasurelist *tl = find_treasurelist (tr->name); 827 treasurelist *tl = treasurelist::find (tr->name);
847 828
848 if (tl == NULL) 829 if (tl == NULL)
849 continue; 830 continue;
850 831
851 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.");
852 833
853 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);
854 return; 835 return;
855 } 836 }
856 837
857 if (!tr->item) 838 if (!tr->item)
858 continue; 839 continue;
859 840
860 item = &tr->item->clone; 841 item = tr->item;
861 842
862 /* Grace limit */ 843 /* Grace limit */
863 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)
864 { 845 {
865 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)
872 tmp = get_archetype (HOLY_POSSESSION); 853 tmp = get_archetype (HOLY_POSSESSION);
873 cast_change_ability (op, op, tmp, 0, 1); 854 cast_change_ability (op, op, tmp, 0, 1);
874 tmp->destroy (); 855 tmp->destroy ();
875 return; 856 return;
876 } 857 }
858
877 continue; 859 continue;
878 } 860 }
879 861
880 /* Restore grace */ 862 /* Restore grace */
881 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)
905 /* Restore to 50 .. 100%, if sp < 50% */ 887 /* Restore to 50 .. 100%, if sp < 50% */
906 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);
907 889
908 if (op->stats.sp >= max / 2) 890 if (op->stats.sp >= max / 2)
909 continue; 891 continue;
892
910 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!");
911 op->stats.sp = new_sp; 894 op->stats.sp = new_sp;
912 } 895 }
913 896
914 /* Various heal spells */ 897 /* Various heal spells */
915 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)
916 { 899 {
917 object *tmp;
918 int success;
919
920 tmp = get_archetype_by_object_name (item->slaying); 900 object *tmp = archetype::get (item->slaying);
921
922 success = cast_heal (op, op, tmp, 0); 901 int success = cast_heal (op, op, tmp, 0);
923 tmp->destroy (); 902 tmp->destroy ();
903
924 if (success) 904 if (success)
925 return; 905 return;
926 else 906 else
927 continue; 907 continue;
928 } 908 }
963 continue; 943 continue;
964 944
965 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!");
966 946
967 for (i = 0; i < NUM_STATS; i++) 947 for (i = 0; i < NUM_STATS; i++)
968 if (get_attr_value (&depl->stats, i)) 948 if (depl->stats.stat (i))
969 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 949 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
970 950
971 depl->destroy (); 951 depl->destroy ();
972 op->update_stats (); 952 op->update_stats ();
973 return; 953 return;
974 } 954 }
975 955
976 /* Voices */ 956 /* Voices */
977 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)
978 { 958 {
979 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:");
980 new_draw_info (NDI_WHITE, 0, op, item->msg); 960 new_draw_info (NDI_WHITE, 0, op, item->msg);
981 return; 961 return;
982 } 962 }
983 963
984 /* Messages */ 964 /* Messages */
1035{ 1015{
1036 int reaction = 1; 1016 int reaction = 1;
1037 object *item = NULL, *skop; 1017 object *item = NULL, *skop;
1038 1018
1039 for (item = op->inv; item; item = item->below) 1019 for (item = op->inv; item; item = item->below)
1040 {
1041 if (QUERY_FLAG (item, FLAG_APPLIED)) 1020 if (QUERY_FLAG (item, FLAG_APPLIED))
1042 {
1043 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);
1044 }
1045 }
1046 1022
1047 /* 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 */
1048 if (reaction < 0) 1024 if (reaction < 0)
1049 { 1025 {
1050 int loss = 10000000; 1026 int loss = 10000000;
1051 int angry = abs (reaction); 1027 int angry = abs (reaction);
1052 1028
1053 for (skop = op->inv; skop != NULL; skop = skop->below) 1029 for (skop = op->inv; skop; skop = skop->below)
1054 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 1030 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1055 break; 1031 break;
1056 1032
1057 if (skop) 1033 if (skop)
1058 loss = (int) (0.05 * (float) skop->stats.exp); 1034 loss = 0.05f * skop->stats.exp;
1035
1059 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
1060 if (random_roll (0, angry, op, PREFER_LOW)) 1038 if (random_roll (0, angry, op, PREFER_LOW))
1061 { 1039 {
1062 object *tmp = get_archetype (LOOSE_MANA); 1040 object *tmp = get_archetype (LOOSE_MANA);
1063 1041
1064 cast_magic_storm (op, tmp, op->level + (angry * 3)); 1042 cast_magic_storm (op, tmp, op->level + (angry * 3));
1065 } 1043 }
1044
1066 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);
1067 } 1046 }
1047
1068 return reaction; 1048 return reaction;
1069} 1049}
1070 1050
1071/** 1051/**
1072 * God checks item the player is using. 1052 * God checks item the player is using.
1135 1115
1136 if (race == NULL) 1116 if (race == NULL)
1137 return NULL; 1117 return NULL;
1138 while (gl) 1118 while (gl)
1139 { 1119 {
1140 if (!strcasecmp (gl->arch->clone.race, race)) 1120 if (!strcasecmp (gl->arch->race, race))
1141 { 1121 {
1142 godname = gl->name; 1122 godname = gl->name;
1143 break; 1123 break;
1144 } 1124 }
1145 gl = gl->next; 1125 gl = gl->next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines