ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/resurrection.C
Revision: 1.37
Committed: Sat Apr 23 04:56:57 2011 UTC (13 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.36: +1 -1 lines
Log Message:
update copyright to 2011

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.24 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.19 *
4 root 1.37 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.35 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 pippijn 1.19 *
8 root 1.31 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 pippijn 1.19 *
13 root 1.23 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 pippijn 1.19 *
18 root 1.31 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.21 *
22 root 1.24 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.19 */
24 elmex 1.1
25     /* the contents of this file were create solely by peterm@soda.berkeley.edu
26     all of the above disclaimers apply. */
27    
28     #include <global.h>
29 root 1.14 #include <sproto.h>
30 elmex 1.1 #include <spells.h>
31     #include <errno.h>
32 root 1.5
33 elmex 1.1 /* name of the person to resurrect and which spell was used
34     * to resurrect
35     */
36 root 1.5 static int
37     resurrect_player (object *op, char *playername, object *spell)
38 elmex 1.1 {
39 root 1.5 FILE *deadplayer, *liveplayer;
40    
41     char oldname[MAX_BUF];
42     char newname[MAX_BUF];
43     char path[MAX_BUF];
44     char buf[MAX_BUF];
45     char buf2[MAX_BUF];
46     const char *race = NULL;
47     sint64 exp;
48     int Con;
49    
50     /* reincarnation, which changes the race */
51     if (spell->race)
52     {
53 root 1.20 treasurelist *tl = treasurelist::find (spell->race);
54 root 1.5 treasure *t;
55     int value;
56    
57     if (!tl)
58     {
59     LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race);
60     return 0;
61     }
62 root 1.20
63 root 1.30 value = rndm (tl->total_chance);
64 root 1.20
65 root 1.5 for (t = tl->items; t; t = t->next)
66     {
67     value -= t->chance;
68     if (value < 0)
69     break;
70     }
71 root 1.20
72 elmex 1.16 if (!t || !t->item)
73 root 1.5 {
74     LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race);
75     return 0;
76     }
77 root 1.20
78 root 1.22 race = t->item->archname;
79 root 1.5 }
80    
81     /* set up our paths/strings... */
82     sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername);
83    
84     strcpy (newname, path);
85     strcat (newname, ".pl");
86    
87     strcpy (oldname, newname);
88     strcat (oldname, ".dead");
89 elmex 1.1
90 root 1.5 if (!(deadplayer = fopen (oldname, "r")))
91     {
92     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be reached.", playername);
93     return 0;
94     }
95    
96     if (!access (newname, 0))
97     {
98     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s has already been reborn!", playername);
99     fclose (deadplayer);
100     return 0;
101     }
102    
103     if (!(liveplayer = fopen (newname, "w")))
104     {
105     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be re-embodied at the moment.", playername);
106     LOG (llevError, "Cannot write player in resurrect_player!\n");
107     fclose (deadplayer);
108     return 0;
109     }
110    
111     while (!feof (deadplayer))
112     {
113     fgets (buf, 255, deadplayer);
114     sscanf (buf, "%s", buf2);
115     if (!(strcmp (buf2, "exp")))
116     {
117 root 1.10 sscanf (buf, "%s %" SCNd64, buf2, &exp);
118 root 1.5 if (spell->stats.exp)
119     {
120     exp -= exp / spell->stats.exp;
121 root 1.10 sprintf (buf, "exp %" PRId64 "\n", exp);
122 root 1.2 }
123     }
124 root 1.5 if (!(strcmp (buf2, "Con")))
125     {
126     sscanf (buf, "%s %d", buf2, &Con);
127     Con -= spell->stats.Con;
128     if (Con < 1)
129     Con = 1;
130     sprintf (buf, "Con %d\n", Con);
131     }
132     if (race && !strcmp (buf2, "race"))
133     {
134     sprintf (buf, "race %s\n", race);
135     }
136     fputs (buf, liveplayer);
137     }
138     fclose (liveplayer);
139     fclose (deadplayer);
140     unlink (oldname);
141     new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername);
142 elmex 1.1
143 root 1.5 return 1;
144 elmex 1.1 }
145    
146 root 1.32 static int
147     resurrection_fails (int levelcaster, int leveldead)
148     {
149     int chance = 9;
150    
151     /* scheme: equal in level, 50% success.
152     * +5 % for each level below, -5% for each level above.
153     * minimum 20%
154     */
155     chance += levelcaster - leveldead;
156     if (chance < 4)
157     chance = 4;
158     if (chance > rndm (0, 19))
159     return 0; /* resurrection succeeds */
160     return 1;
161     }
162    
163 elmex 1.1
164     /* raise_dead by peterm and mehlhaff@soda.berkeley.edu
165     * op -- who is doing the resurrecting
166     * spell - spell object
167     * dir -- direction the spell is cast
168     * corpseobj - corpse to raise - can be null, in which case this function will find it
169     */
170 root 1.5 int
171     cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg)
172 elmex 1.1 {
173 root 1.5 object *temp, *newob;
174     char name_to_resurrect[MAX_BUF];
175     int leveldead = 25, mflags, clevel;
176     sint16 sx, sy;
177 root 1.8 maptile *m;
178 root 1.5
179 root 1.27 clevel = casting_level (caster, spell);
180 root 1.5
181     if (spell->last_heal)
182     {
183     if (!arg)
184     {
185     new_draw_info_format (NDI_UNIQUE, 0, op, "Cast %s on who?", &spell->name);
186     return 0;
187 root 1.2 }
188 root 1.5 strcpy (name_to_resurrect, arg);
189     temp = NULL;
190     }
191     else
192     {
193     sx = op->x + freearr_x[dir];
194     sy = op->y + freearr_y[dir];
195     m = op->map;
196     mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
197     if (mflags & P_OUT_OF_MAP)
198 root 1.2 temp = NULL;
199 root 1.5 else
200     {
201     /* First we need to find a corpse, if any. */
202     /* If no object, temp will be set to NULL */
203 root 1.13 for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above)
204 root 1.5 /* If it is corpse, this must be what we want to raise */
205     if (temp->type == CORPSE)
206     break;
207     }
208    
209     if (temp == NULL)
210     {
211     new_draw_info (NDI_UNIQUE, 0, op, "You need a body for this spell.");
212     return 0;
213     }
214     strcpy (name_to_resurrect, temp->name);
215     }
216 elmex 1.1
217 root 1.5 /* no matter what, we fry the corpse. */
218     if (temp && temp->map)
219     {
220     /* replace corpse object with a burning object */
221 root 1.25 newob = archetype::get (shstr_burnout);
222 root 1.15 if (newob)
223     newob->insert_at (temp, op);
224    
225 root 1.5 leveldead = temp->level;
226 root 1.29 temp->destroy ();
227 root 1.5 }
228    
229     if (resurrection_fails (clevel, leveldead))
230     {
231     if (spell->randomitems)
232 root 1.15 for (treasure *t = spell->randomitems->items; t; t = t->next)
233 elmex 1.16 if (t->item)
234 root 1.22 summon_hostile_monsters (op, t->nrof, t->item->archname);
235 elmex 1.1
236 root 1.5 return 1;
237 elmex 1.1
238 root 1.5 }
239     else
240 root 1.15 return resurrect_player (op, name_to_resurrect, spell);
241 elmex 1.1 }
242