ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/resurrection.C
(Generate patch)

Comparing deliantra/server/server/resurrection.C (file contents):
Revision 1.17 by pippijn, Sat Jan 6 14:42:31 2007 UTC vs.
Revision 1.39 by root, Mon Oct 29 23:55:55 2012 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,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 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 it under
9 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 (at your option) any later version. 11 * 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 Affero GNU General Public License
19 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23*/ 23 */
24 24
25/* the contents of this file were create solely by peterm@soda.berkeley.edu 25/* the contents of this file were create solely by peterm@soda.berkeley.edu
26 all of the above disclaimers apply. */ 26 all of the above disclaimers apply. */
27 27
28#include <global.h> 28#include <global.h>
29#include <sproto.h> 29#include <sproto.h>
30#include <spells.h> 30#include <spells.h>
31#include <errno.h> 31#include <errno.h>
32
33extern char **classname;
34extern object *objects;
35 32
36/* name of the person to resurrect and which spell was used 33/* name of the person to resurrect and which spell was used
37 * to resurrect 34 * to resurrect
38 */ 35 */
39static int 36static int
51 int Con; 48 int Con;
52 49
53 /* reincarnation, which changes the race */ 50 /* reincarnation, which changes the race */
54 if (spell->race) 51 if (spell->race)
55 { 52 {
56 treasurelist *tl = find_treasurelist (spell->race); 53 treasurelist *tl = treasurelist::find (spell->race);
57 treasure *t; 54 treasure *t;
58 int value; 55 int value;
59 56
60 if (!tl) 57 if (!tl)
61 { 58 {
62 LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race); 59 LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race);
63 return 0; 60 return 0;
64 } 61 }
62
65 value = RANDOM () % tl->total_chance; 63 value = rndm (tl->total_chance);
64
66 for (t = tl->items; t; t = t->next) 65 for (t = tl->items; t; t = t->next)
67 { 66 {
68 value -= t->chance; 67 value -= t->chance;
69 if (value < 0) 68 if (value < 0)
70 break; 69 break;
71 } 70 }
71
72 if (!t || !t->item) 72 if (!t || !t->item)
73 { 73 {
74 LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race); 74 LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race);
75 return 0; 75 return 0;
76 } 76 }
77
77 race = t->item->name; 78 race = t->item->archname;
78 } 79 }
79 80
80 /* set up our paths/strings... */ 81 /* set up our paths/strings... */
81 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername); 82 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername);
82 83
137 fclose (liveplayer); 138 fclose (liveplayer);
138 fclose (deadplayer); 139 fclose (deadplayer);
139 unlink (oldname); 140 unlink (oldname);
140 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername); 141 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername);
141 142
143 return 1;
144}
145
146static int
147resurrection_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 */
142 return 1; 160 return 1;
143} 161}
144 162
145 163
146/* raise_dead by peterm and mehlhaff@soda.berkeley.edu 164/* raise_dead by peterm and mehlhaff@soda.berkeley.edu
156 char name_to_resurrect[MAX_BUF]; 174 char name_to_resurrect[MAX_BUF];
157 int leveldead = 25, mflags, clevel; 175 int leveldead = 25, mflags, clevel;
158 sint16 sx, sy; 176 sint16 sx, sy;
159 maptile *m; 177 maptile *m;
160 178
161 clevel = caster_level (caster, spell); 179 clevel = casting_level (caster, spell);
162 180
163 if (spell->last_heal) 181 if (spell->last_heal)
164 { 182 {
165 if (!arg) 183 if (!arg)
166 { 184 {
198 216
199 /* no matter what, we fry the corpse. */ 217 /* no matter what, we fry the corpse. */
200 if (temp && temp->map) 218 if (temp && temp->map)
201 { 219 {
202 /* replace corpse object with a burning object */ 220 /* replace corpse object with a burning object */
203 newob = arch_to_object (archetype::find ("burnout")); 221 newob = archetype::get (shstr_burnout);
204 if (newob) 222 if (newob)
205 newob->insert_at (temp, op); 223 newob->insert_at (temp, op);
206 224
207 leveldead = temp->level; 225 leveldead = temp->level;
208 temp->destroy (); 226 temp->destroy ();
211 if (resurrection_fails (clevel, leveldead)) 229 if (resurrection_fails (clevel, leveldead))
212 { 230 {
213 if (spell->randomitems) 231 if (spell->randomitems)
214 for (treasure *t = spell->randomitems->items; t; t = t->next) 232 for (treasure *t = spell->randomitems->items; t; t = t->next)
215 if (t->item) 233 if (t->item)
216 summon_hostile_monsters (op, t->nrof, t->item->name); 234 summon_hostile_monsters (op, t->nrof, t->item->archname);
217 235
218 return 1; 236 return 1;
219 237
220 } 238 }
221 else 239 else
222 return resurrect_player (op, name_to_resurrect, spell); 240 return resurrect_player (op, name_to_resurrect, spell);
223} 241}
224 242
225
226int
227resurrection_fails (int levelcaster, int leveldead)
228{
229 int chance = 9;
230
231 /* scheme: equal in level, 50% success.
232 * +5 % for each level below, -5% for each level above.
233 * minimum 20%
234 */
235 chance += levelcaster - leveldead;
236 if (chance < 4)
237 chance = 4;
238 if (chance > rndm (0, 19))
239 return 0; /* resurrection succeeds */
240 return 1;
241}
242
243void
244dead_player (object *op)
245{
246 char filename[MAX_BUF];
247 char newname[MAX_BUF];
248 char path[MAX_BUF];
249
250 /* set up our paths/strings... */
251 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name);
252
253 strcpy (filename, path);
254 strcat (filename, ".pl");
255 strcpy (newname, filename);
256 strcat (newname, ".dead");
257
258 if (rename (filename, newname) != 0)
259 {
260 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno));
261 }
262}
263
264
265
266void
267dead_character (const char *name)
268{
269 char buf[MAX_BUF];
270 char buf2[MAX_BUF];
271
272 sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name);
273 /* peterm: create a .dead filename.... ***.pl.dead */
274 strcpy (buf2, buf);
275 strcat (buf, ".dead");
276 if (rename (buf2, buf) == -1)
277 {
278 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno));
279 }
280}
281
282
283int
284dead_player_exists (const char *name)
285{
286 char buf[MAX_BUF];
287
288 sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name);
289 strcat (buf, ".pl.dead");
290 return !(access (buf, 0));
291}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines