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.21 by root, Sat May 12 18:14:48 2007 UTC vs.
Revision 1.32 by root, Tue Apr 22 02:46:18 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 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 */
200 if (tmp->nrof > 1) 199 if (tmp->nrof > 1)
201 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumble to dust!", query_short_name (tmp)); 200 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumble to dust!", query_short_name (tmp));
202 else 201 else
203 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp)); 202 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp));
204 203
205 tmp->remove (); /* remove obj from players inv. */ 204 tmp->destroy ();
206 esrv_del_item (op->contr, tmp->count); /* notify client */
207 tmp->destroy (); /* free object */
208 } 205 }
209 206
210 if (tmp->inv) 207 if (tmp->inv)
211 follower_remove_similar_item (tmp, item); 208 follower_remove_similar_item (tmp, item);
212 } 209 }
243 object *tmp; 240 object *tmp;
244 241
245 if (!tr->item) 242 if (!tr->item)
246 return 0; 243 return 0;
247 244
248 if (follower_has_similar_item (op, &tr->item->clone)) 245 if (follower_has_similar_item (op, tr->item))
249 return 0; 246 return 0;
250 247
251 tmp = arch_to_object (tr->item); 248 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)); 249 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); 250 tmp = insert_ob_in_ob (tmp, op);
274 return; 271 return;
275 272
276 /* hmm. what happend depends on pl's current god, level, etc */ 273 /* hmm. what happend depends on pl's current god, level, etc */
277 if (!pl_god) 274 if (!pl_god)
278 { /*new convert */ 275 { /*new convert */
279 become_follower (pl, &altar->other_arch->clone); 276 become_follower (pl, altar->other_arch);
280 return; 277 return;
281
282 } 278 }
283 else if (!strcmp (&pl_god->name, altar->other_arch->clone.name)) 279 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
284 { 280 {
285 /* pray at your gods altar */ 281 /* pray at your gods altar */
286 int bonus = (pl->stats.Wis + skill->level) / 10; 282 int bonus = (pl->stats.Wis + skill->level) / 10;
287 283
288 /* we can get neg grace up faster */ 284 /* we can get neg grace up faster */
289 if (pl->stats.grace < 0) 285 if (pl->stats.grace < 0)
290 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10)); 286 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
287
291 /* we can super-charge grace to 2x max */ 288 /* we can super-charge grace to 2x max */
292 if (pl->stats.grace < (2 * pl->stats.maxgrace)) 289 if (pl->stats.grace < 2 * pl->stats.maxgrace)
293 {
294 pl->stats.grace += bonus / 2; 290 pl->stats.grace += bonus / 2;
295 } 291 else
296 if (pl->stats.grace > (2 * pl->stats.maxgrace))
297 {
298 pl->stats.grace = (2 * pl->stats.maxgrace); 292 pl->stats.grace = 2 * pl->stats.maxgrace;
299 }
300 293
301 /* Every once in a while, the god decides to checkup on their 294 /* Every once in a while, the god decides to checkup on their
302 * follower, and may intervene to help them out. 295 * follower, and may intervene to help them out.
303 */ 296 */
304 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */ 297 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
305 298
306 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0) 299 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
307 god_intervention (pl, pl_god, skill); 300 god_intervention (pl, pl_god, skill);
308
309 } 301 }
310 else 302 else
311 { /* praying to another god! */ 303 { /* praying to another god! */
312 uint64 loss = 0; 304 uint64 loss = 0;
313 int angry = 1; 305 int angry = 1;
317 * points to the god of this altar (which we have 309 * points to the god of this altar (which we have
318 * already verified is non null). pl_god->other_arch 310 * already verified is non null). pl_god->other_arch
319 * is the opposing god - we need to verify that exists before 311 * is the opposing god - we need to verify that exists before
320 * using its values. 312 * using its values.
321 */ 313 */
322 if (pl_god->other_arch && (altar->other_arch->name == pl_god->other_arch->name)) 314 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
323 { 315 {
324 angry = 2; 316 angry = 2;
325 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0) 317 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
326 { 318 {
327 object *tmp; 319 object *tmp;
348 340
349 /* May switch Gods, but its random chance based on our current level 341 /* May switch Gods, but its random chance based on our current level
350 * note it gets harder to swap gods the higher we get 342 * note it gets harder to swap gods the higher we get
351 */ 343 */
352 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW))) 344 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
353 {
354 become_follower (pl, &altar->other_arch->clone); 345 become_follower (pl, altar->other_arch);
355 }
356 else 346 else
357 { 347 {
358 /* toss this player off the altar. He can try again. */ 348 /* 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."); 349 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
350 pl->contr->fire_on = 0;
351 pl->speed_left = 1.f;
360 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */ 352 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
361 } 353 }
362 } 354 }
363} 355}
364 356
402 object *item; 394 object *item;
403 395
404 if (!tr->item) 396 if (!tr->item)
405 continue; 397 continue;
406 398
407 item = &tr->item->clone; 399 item = tr->item;
408 400
409 /* Basically, see if the matching spell is granted by this god. */ 401 /* Basically, see if the matching spell is granted by this god. */
410 402
411 if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) 403 if (tr->item->type == SPELL && tr->item->object::name == tmp->name)
412 { 404 {
413 remove = 0; 405 remove = 0;
414 break; 406 break;
415 } 407 }
416 } 408 }
462 } 454 }
463 455
464 /* remove any godgiven items from the old god */ 456 /* remove any godgiven items from the old god */
465 if (old_god) 457 if (old_god)
466 for (tr = old_god->randomitems->items; tr; tr = tr->next) 458 for (tr = old_god->randomitems->items; tr; tr = tr->next)
467 if (tr->item && QUERY_FLAG (&tr->item->clone, FLAG_STARTEQUIP)) 459 if (tr->item && QUERY_FLAG (tr->item, FLAG_STARTEQUIP))
468 follower_remove_similar_item (op, &tr->item->clone); 460 follower_remove_similar_item (op, tr->item);
469 461
470 if (!op || !new_god) 462 if (!op || !new_god)
471 return; 463 return;
472 464
473 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 465 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying))
486 478
487 479
488 /* give the player any special god-characteristic-items. */ 480 /* give the player any special god-characteristic-items. */
489 for (tr = new_god->randomitems->items; tr; tr = tr->next) 481 for (tr = new_god->randomitems->items; tr; tr = tr->next)
490 { 482 {
491 if (tr->item && tr->item->clone.invisible && tr->item->clone.type != SPELLBOOK 483 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
492 && tr->item->clone.type != BOOK && tr->item->clone.type != SPELL) 484 && tr->item->type != BOOK && tr->item->type != SPELL)
493 god_gives_present (op, new_god, tr); 485 god_gives_present (op, new_god, tr);
494 } 486 }
495 487
496 488
497 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name); 489 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name);
504 if (!skop) 496 if (!skop)
505 { 497 {
506 /* The arhetype should always be defined - if we crash here because it doesn't, 498 /* The arhetype should always be defined - if we crash here because it doesn't,
507 * things are really messed up anyways. 499 * things are really messed up anyways.
508 */ 500 */
509 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->clone.skill); 501 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill);
510 link_player_skills (op); 502 link_player_skills (op);
511 } 503 }
512 504
513 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 505 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
514 506
609 601
610int 602int
611worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string) 603worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
612{ 604{
613 605
614 if (QUERY_FLAG (&op->arch->clone, flag)) 606 if (QUERY_FLAG (op->arch, flag))
615 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag)) 607 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
616 { 608 {
617 update_priest_flag (exp_obj, op, flag); 609 update_priest_flag (exp_obj, op, flag);
618 if (QUERY_FLAG (op, flag)) 610 if (QUERY_FLAG (op, flag))
619 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string); 611 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
685 for (tr = god->randomitems->items; tr; tr = tr->next) 677 for (tr = god->randomitems->items; tr; tr = tr->next)
686 { 678 {
687 if (!tr->item) 679 if (!tr->item)
688 continue; 680 continue;
689 681
690 object *item = &tr->item->clone; 682 object *item = tr->item;
691 683
692 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 684 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0)
693 return item->other_arch; 685 return item->other_arch;
694 } 686 }
695 return NULL; 687 return NULL;
803 } 795 }
804 796
805 return 0; 797 return 0;
806} 798}
807 799
808
809/** 800/**
810 * Every once in a while the god will intervene to help the worshiper. 801 * Every once in a while the god will intervene to help the worshiper.
811 * Later, this fctn can be used to supply quests, etc for the 802 * Later, this fctn can be used to supply quests, etc for the
812 * priest. -b.t. 803 * priest. -b.t.
813 * called from pray_at_altar() currently. 804 * called from pray_at_altar() currently.
814 */ 805 */
815
816void 806void
817god_intervention (object *op, object *god, object *skill) 807god_intervention (object *op, object *god, object *skill)
818{ 808{
819 treasure *tr; 809 treasure *tr;
820 810
828 818
829 /* lets do some checks of whether we are kosher with our god */ 819 /* lets do some checks of whether we are kosher with our god */
830 if (god_examines_priest (op, god) < 0) 820 if (god_examines_priest (op, god) < 0)
831 return; 821 return;
832 822
823 op->play_sound (sound_find ("god_intervention"));
833 new_draw_info (NDI_UNIQUE, 0, op, "You feel a holy presence!"); 824 new_draw_info (NDI_UNIQUE, 0, op, "You feel a holy presence!");
834 825
835 for (tr = god->randomitems->items; tr; tr = tr->next) 826 for (tr = god->randomitems->items; tr; tr = tr->next)
836 { 827 {
837 object *item; 828 object *item;
845 treasurelist *tl = treasurelist::find (tr->name); 836 treasurelist *tl = treasurelist::find (tr->name);
846 837
847 if (tl == NULL) 838 if (tl == NULL)
848 continue; 839 continue;
849 840
850 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your " "eyes. You catch it before it falls to the ground."); 841 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your eyes. You catch it before it falls to the ground.");
851 842
852 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD | GT_UPDATE_INV, skill->level, 0); 843 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD | GT_UPDATE_INV, skill->level, 0);
853 return; 844 return;
854 } 845 }
855 846
856 if (!tr->item) 847 if (!tr->item)
857 continue; 848 continue;
858 849
859 item = &tr->item->clone; 850 item = tr->item;
860 851
861 /* Grace limit */ 852 /* Grace limit */
862 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 853 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0)
863 { 854 {
864 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 855 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
871 tmp = get_archetype (HOLY_POSSESSION); 862 tmp = get_archetype (HOLY_POSSESSION);
872 cast_change_ability (op, op, tmp, 0, 1); 863 cast_change_ability (op, op, tmp, 0, 1);
873 tmp->destroy (); 864 tmp->destroy ();
874 return; 865 return;
875 } 866 }
867
876 continue; 868 continue;
877 } 869 }
878 870
879 /* Restore grace */ 871 /* Restore grace */
880 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 872 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0)
973 } 965 }
974 966
975 /* Voices */ 967 /* Voices */
976 if (item->type == BOOK && item->invisible && strcmp (item->name, "voice_behind") == 0) 968 if (item->type == BOOK && item->invisible && strcmp (item->name, "voice_behind") == 0)
977 { 969 {
978 new_draw_info (NDI_UNIQUE, 0, op, "You hear a voice from behind you, but you don't dare to " "turn around:"); 970 new_draw_info (NDI_UNIQUE, 0, op, "You hear a voice from behind you, but you don't dare to turn around:");
979 new_draw_info (NDI_WHITE, 0, op, item->msg); 971 new_draw_info (NDI_WHITE, 0, op, item->msg);
980 return; 972 return;
981 } 973 }
982 974
983 /* Messages */ 975 /* Messages */
1134 1126
1135 if (race == NULL) 1127 if (race == NULL)
1136 return NULL; 1128 return NULL;
1137 while (gl) 1129 while (gl)
1138 { 1130 {
1139 if (!strcasecmp (gl->arch->clone.race, race)) 1131 if (!strcasecmp (gl->arch->race, race))
1140 { 1132 {
1141 godname = gl->name; 1133 godname = gl->name;
1142 break; 1134 break;
1143 } 1135 }
1144 gl = gl->next; 1136 gl = gl->next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines