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.10 by root, Mon Dec 11 21:32:18 2006 UTC vs.
Revision 1.43 by root, Sat Nov 17 23:40:04 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
6 8 *
7 This program is free software; you can redistribute it and/or modify 9 * Deliantra is free software: you can redistribute it and/or modify it under
8 it under the terms of the GNU General Public License as published by 10 * the terms of the Affero GNU General Public License as published by the
9 the Free Software Foundation; either version 2 of the License, or 11 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 12 * option) any later version.
11 13 *
12 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 17 * GNU General Public License for more details.
16 18 *
17 You should have received a copy of the GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
18 along with this program; if not, write to the Free Software 20 * and the GNU General Public License along with this program. If not, see
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * <http://www.gnu.org/licenses/>.
20 22 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22*/ 24 */
23 25
24/* the contents of this file were create solely by peterm@soda.berkeley.edu 26/* the contents of this file were create solely by peterm@soda.berkeley.edu
25 all of the above disclaimers apply. */ 27 all of the above disclaimers apply. */
26 28
27#include <global.h> 29#include <global.h>
28#ifndef __CEXTRACT__
29# include <sproto.h> 30#include <sproto.h>
30#endif
31#include <spells.h> 31#include <spells.h>
32#include <errno.h> 32#include <errno.h>
33#ifdef sequent
34
35/* stoopid sequent includes don't do this like they should */
36extern char *sys_errlist[];
37extern int sys_nerr;
38#endif
39extern char **classname;
40extern object *objects;
41
42
43 33
44/* name of the person to resurrect and which spell was used 34/* name of the person to resurrect and which spell was used
45 * to resurrect 35 * to resurrect
46 */ 36 */
47static int 37static int
48resurrect_player (object *op, char *playername, object *spell) 38resurrect_player (object *op, char *playername, object *spell)
49{ 39{
50 FILE *deadplayer, *liveplayer; 40 FILE *deadplayer, *liveplayer;
56 char buf2[MAX_BUF]; 46 char buf2[MAX_BUF];
57 const char *race = NULL; 47 const char *race = NULL;
58 sint64 exp; 48 sint64 exp;
59 int Con; 49 int Con;
60 50
61
62 /* reincarnation, which changes the race */ 51 /* reincarnation, which changes the race */
63 if (spell->race) 52 if (spell->race)
64 { 53 {
65 treasurelist *tl = find_treasurelist (spell->race); 54 treasurelist *tl = treasurelist::find (spell->race);
66 treasure *t; 55 treasure *t;
67 int value; 56 int value;
68 57
69 if (!tl) 58 if (!tl)
70 { 59 {
71 LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race); 60 LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race);
72 return 0; 61 return 0;
73 } 62 }
63
74 value = RANDOM () % tl->total_chance; 64 value = rndm (tl->total_chance);
65
75 for (t = tl->items; t; t = t->next) 66 for (t = tl->items; t; t = t->next)
76 { 67 {
77 value -= t->chance; 68 value -= t->chance;
78 if (value < 0) 69 if (value < 0)
79 break; 70 break;
80 } 71 }
81 if (!t) 72
73 if (!t || !t->item)
82 { 74 {
83 LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race); 75 LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race);
84 return 0; 76 return 0;
85 } 77 }
78
86 race = t->item->name; 79 race = t->item->archname;
87 } 80 }
88 81
89 /* set up our paths/strings... */ 82 /* set up our paths/strings... */
90 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername); 83 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername);
91 84
149 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername); 142 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername);
150 143
151 return 1; 144 return 1;
152} 145}
153 146
147static int
148resurrection_fails (int levelcaster, int leveldead)
149{
150 int chance = 9;
151
152 /* scheme: equal in level, 50% success.
153 * +5 % for each level below, -5% for each level above.
154 * minimum 20%
155 */
156 chance += levelcaster - leveldead;
157 if (chance < 4)
158 chance = 4;
159 if (chance > rndm (0, 19))
160 return 0; /* resurrection succeeds */
161 return 1;
162}
163
154 164
155/* raise_dead by peterm and mehlhaff@soda.berkeley.edu 165/* raise_dead by peterm and mehlhaff@soda.berkeley.edu
156 * op -- who is doing the resurrecting 166 * op -- who is doing the resurrecting
157 * spell - spell object 167 * spell - spell object
158 * dir -- direction the spell is cast 168 * dir -- direction the spell is cast
159 * corpseobj - corpse to raise - can be null, in which case this function will find it 169 * corpseobj - corpse to raise - can be null, in which case this function will find it
160 */ 170 */
161int 171int
162cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg) 172cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg)
165 char name_to_resurrect[MAX_BUF]; 175 char name_to_resurrect[MAX_BUF];
166 int leveldead = 25, mflags, clevel; 176 int leveldead = 25, mflags, clevel;
167 sint16 sx, sy; 177 sint16 sx, sy;
168 maptile *m; 178 maptile *m;
169 179
170 clevel = caster_level (caster, spell); 180 clevel = casting_level (caster, spell);
171 181
172 if (spell->last_heal) 182 if (spell->last_heal)
173 { 183 {
174 if (!arg) 184 if (!arg)
175 { 185 {
179 strcpy (name_to_resurrect, arg); 189 strcpy (name_to_resurrect, arg);
180 temp = NULL; 190 temp = NULL;
181 } 191 }
182 else 192 else
183 { 193 {
184 sx = op->x + freearr_x[dir]; 194 sx = op->x + DIRX (dir);
185 sy = op->y + freearr_y[dir]; 195 sy = op->y + DIRY (dir);
186 m = op->map; 196 m = op->map;
187 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); 197 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
188 if (mflags & P_OUT_OF_MAP) 198 if (mflags & P_OUT_OF_MAP)
189 temp = NULL; 199 temp = NULL;
190 else 200 else
191 { 201 {
192 /* First we need to find a corpse, if any. */ 202 /* First we need to find a corpse, if any. */
193 /* If no object, temp will be set to NULL */ 203 /* If no object, temp will be set to NULL */
194 for (temp = get_map_ob (m, sx, sy); temp != NULL; temp = temp->above) 204 for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above)
195 /* If it is corpse, this must be what we want to raise */ 205 /* If it is corpse, this must be what we want to raise */
196 if (temp->type == CORPSE) 206 if (temp->type == CORPSE)
197 break; 207 break;
198 } 208 }
199 209
207 217
208 /* no matter what, we fry the corpse. */ 218 /* no matter what, we fry the corpse. */
209 if (temp && temp->map) 219 if (temp && temp->map)
210 { 220 {
211 /* replace corpse object with a burning object */ 221 /* replace corpse object with a burning object */
212 newob = arch_to_object (archetype::find ("burnout")); 222 newob = archetype::get (shstr_burnout);
213 if (newob != NULL) 223 if (newob)
214 { 224 newob->insert_at (temp, op);
215 newob->x = temp->x; 225
216 newob->y = temp->y;
217 insert_ob_in_map (newob, temp->map, op, 0);
218 }
219 leveldead = temp->level; 226 leveldead = temp->level;
220 remove_ob (temp); 227 temp->destroy ();
221 free_object (temp);
222 } 228 }
223 229
224 if (resurrection_fails (clevel, leveldead)) 230 if (resurrection_fails (clevel, leveldead))
225 { 231 {
226 if (spell->randomitems) 232 if (spell->randomitems)
227 {
228 treasure *t;
229
230 for (t = spell->randomitems->items; t; t = t->next) 233 for (treasure *t = spell->randomitems->items; t; t = t->next)
231 { 234 if (t->item)
232 summon_hostile_monsters (op, t->nrof, t->item->name); 235 summon_hostile_monsters (op, t->nrof, t->item->archname);
233 }
234 236
235 }
236 return 1; 237 return 1;
237 238
238 } 239 }
239 else 240 else
240 {
241 return resurrect_player (op, name_to_resurrect, spell); 241 return resurrect_player (op, name_to_resurrect, spell);
242 }
243
244 return 1;
245} 242}
246 243
247
248int
249resurrection_fails (int levelcaster, int leveldead)
250{
251 int chance = 9;
252
253 /* scheme: equal in level, 50% success.
254 * +5 % for each level below, -5% for each level above.
255 * minimum 20%
256 */
257 chance += levelcaster - leveldead;
258 if (chance < 4)
259 chance = 4;
260 if (chance > rndm (0, 19))
261 return 0; /* resurrection succeeds */
262 return 1;
263}
264
265void
266dead_player (object *op)
267{
268 char filename[MAX_BUF];
269 char newname[MAX_BUF];
270 char path[MAX_BUF];
271
272 /* set up our paths/strings... */
273 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name);
274
275 strcpy (filename, path);
276 strcat (filename, ".pl");
277 strcpy (newname, filename);
278 strcat (newname, ".dead");
279
280 if (rename (filename, newname) != 0)
281 {
282 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno));
283 }
284}
285
286
287
288void
289dead_character (const char *name)
290{
291 char buf[MAX_BUF];
292 char buf2[MAX_BUF];
293
294 sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name);
295 /* peterm: create a .dead filename.... ***.pl.dead */
296 strcpy (buf2, buf);
297 strcat (buf, ".dead");
298 if (rename (buf2, buf) == -1)
299 {
300 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno));
301 }
302}
303
304
305int
306dead_player_exists (const char *name)
307{
308 char buf[MAX_BUF];
309
310 sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name);
311 strcat (buf, ".pl.dead");
312 return !(access (buf, 0));
313}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines