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.22 by root, Mon Jun 4 12:19:09 2007 UTC vs.
Revision 1.43 by root, Sat Nov 17 23:40:04 2018 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 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
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * under the terms of the GNU General Public License as published by the Free 10 * the terms of the Affero GNU General Public License as published by the
10 * Software Foundation; either version 2 of the License, or (at your option) 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, but 14 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License along 19 * You should have received a copy of the Affero GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 20 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/* 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
26 all of the above disclaimers apply. */ 27 all of the above disclaimers apply. */
27 28
29#include <sproto.h> 30#include <sproto.h>
30#include <spells.h> 31#include <spells.h>
31#include <errno.h> 32#include <errno.h>
32 33
33/* name of the person to resurrect and which spell was used 34/* name of the person to resurrect and which spell was used
34 * to resurrect 35 * to resurrect
35 */ 36 */
36static int 37static int
37resurrect_player (object *op, char *playername, object *spell) 38resurrect_player (object *op, char *playername, object *spell)
38{ 39{
39 FILE *deadplayer, *liveplayer; 40 FILE *deadplayer, *liveplayer;
58 { 59 {
59 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);
60 return 0; 61 return 0;
61 } 62 }
62 63
63 value = RANDOM () % tl->total_chance; 64 value = rndm (tl->total_chance);
64 65
65 for (t = tl->items; t; t = t->next) 66 for (t = tl->items; t; t = t->next)
66 { 67 {
67 value -= t->chance; 68 value -= t->chance;
68 if (value < 0) 69 if (value < 0)
141 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);
142 143
143 return 1; 144 return 1;
144} 145}
145 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
146 164
147/* raise_dead by peterm and mehlhaff@soda.berkeley.edu 165/* raise_dead by peterm and mehlhaff@soda.berkeley.edu
148 * op -- who is doing the resurrecting 166 * op -- who is doing the resurrecting
149 * spell - spell object 167 * spell - spell object
150 * dir -- direction the spell is cast 168 * dir -- direction the spell is cast
151 * 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
152 */ 170 */
153int 171int
154cast_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)
157 char name_to_resurrect[MAX_BUF]; 175 char name_to_resurrect[MAX_BUF];
158 int leveldead = 25, mflags, clevel; 176 int leveldead = 25, mflags, clevel;
159 sint16 sx, sy; 177 sint16 sx, sy;
160 maptile *m; 178 maptile *m;
161 179
162 clevel = caster_level (caster, spell); 180 clevel = casting_level (caster, spell);
163 181
164 if (spell->last_heal) 182 if (spell->last_heal)
165 { 183 {
166 if (!arg) 184 if (!arg)
167 { 185 {
171 strcpy (name_to_resurrect, arg); 189 strcpy (name_to_resurrect, arg);
172 temp = NULL; 190 temp = NULL;
173 } 191 }
174 else 192 else
175 { 193 {
176 sx = op->x + freearr_x[dir]; 194 sx = op->x + DIRX (dir);
177 sy = op->y + freearr_y[dir]; 195 sy = op->y + DIRY (dir);
178 m = op->map; 196 m = op->map;
179 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); 197 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
180 if (mflags & P_OUT_OF_MAP) 198 if (mflags & P_OUT_OF_MAP)
181 temp = NULL; 199 temp = NULL;
182 else 200 else
199 217
200 /* no matter what, we fry the corpse. */ 218 /* no matter what, we fry the corpse. */
201 if (temp && temp->map) 219 if (temp && temp->map)
202 { 220 {
203 /* replace corpse object with a burning object */ 221 /* replace corpse object with a burning object */
204 newob = arch_to_object (archetype::find ("burnout")); 222 newob = archetype::get (shstr_burnout);
205 if (newob) 223 if (newob)
206 newob->insert_at (temp, op); 224 newob->insert_at (temp, op);
207 225
208 leveldead = temp->level; 226 leveldead = temp->level;
209 temp->destroy (); 227 temp->destroy ();
221 } 239 }
222 else 240 else
223 return resurrect_player (op, name_to_resurrect, spell); 241 return resurrect_player (op, name_to_resurrect, spell);
224} 242}
225 243
226
227int
228resurrection_fails (int levelcaster, int leveldead)
229{
230 int chance = 9;
231
232 /* scheme: equal in level, 50% success.
233 * +5 % for each level below, -5% for each level above.
234 * minimum 20%
235 */
236 chance += levelcaster - leveldead;
237 if (chance < 4)
238 chance = 4;
239 if (chance > rndm (0, 19))
240 return 0; /* resurrection succeeds */
241 return 1;
242}
243
244void
245dead_player (object *op)
246{
247 char filename[MAX_BUF];
248 char newname[MAX_BUF];
249 char path[MAX_BUF];
250
251 /* set up our paths/strings... */
252 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name);
253
254 strcpy (filename, path);
255 strcat (filename, ".pl");
256 strcpy (newname, filename);
257 strcat (newname, ".dead");
258
259 if (rename (filename, newname) != 0)
260 {
261 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno));
262 }
263}
264
265
266
267void
268dead_character (const char *name)
269{
270 char buf[MAX_BUF];
271 char buf2[MAX_BUF];
272
273 sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name);
274 /* peterm: create a .dead filename.... ***.pl.dead */
275 strcpy (buf2, buf);
276 strcat (buf, ".dead");
277 if (rename (buf2, buf) == -1)
278 {
279 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno));
280 }
281}
282
283
284int
285dead_player_exists (const char *name)
286{
287 char buf[MAX_BUF];
288
289 sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name);
290 strcat (buf, ".pl.dead");
291 return !(access (buf, 0));
292}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines