1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_resurrection_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: resurrection.C,v 1.5 2006/09/10 15:59:57 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * 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 | * |
|
|
13 | * 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 | * |
|
|
18 | * 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 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
5 | */ |
23 | */ |
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
|
|
9 | |
|
|
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
11 | Copyright (C) 1992 Frank Tore Johansen |
|
|
12 | |
|
|
13 | This program is free software; you can redistribute it and/or modify |
|
|
14 | it under the terms of the GNU General Public License as published by |
|
|
15 | the Free Software Foundation; either version 2 of the License, or |
|
|
16 | (at your option) any later version. |
|
|
17 | |
|
|
18 | This program is distributed in the hope that it will be useful, |
|
|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
21 | GNU General Public License for more details. |
|
|
22 | |
|
|
23 | You should have received a copy of the GNU General Public License |
|
|
24 | along with this program; if not, write to the Free Software |
|
|
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
26 | |
|
|
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
28 | */ |
|
|
29 | |
24 | |
30 | /* 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 |
31 | all of the above disclaimers apply. */ |
26 | all of the above disclaimers apply. */ |
32 | |
27 | |
33 | #include <global.h> |
28 | #include <global.h> |
34 | #ifndef __CEXTRACT__ |
|
|
35 | # include <sproto.h> |
29 | #include <sproto.h> |
36 | #endif |
|
|
37 | #include <spells.h> |
30 | #include <spells.h> |
38 | #include <errno.h> |
31 | #include <errno.h> |
39 | #ifdef sequent |
|
|
40 | |
|
|
41 | /* stoopid sequent includes don't do this like they should */ |
|
|
42 | extern char *sys_errlist[]; |
|
|
43 | extern int sys_nerr; |
|
|
44 | #endif |
|
|
45 | extern char **classname; |
|
|
46 | extern object *objects; |
|
|
47 | |
|
|
48 | |
|
|
49 | |
32 | |
50 | /* name of the person to resurrect and which spell was used |
33 | /* name of the person to resurrect and which spell was used |
51 | * to resurrect |
34 | * to resurrect |
52 | */ |
35 | */ |
53 | static int |
36 | static int |
… | |
… | |
62 | char buf2[MAX_BUF]; |
45 | char buf2[MAX_BUF]; |
63 | const char *race = NULL; |
46 | const char *race = NULL; |
64 | sint64 exp; |
47 | sint64 exp; |
65 | int Con; |
48 | int Con; |
66 | |
49 | |
67 | |
|
|
68 | /* reincarnation, which changes the race */ |
50 | /* reincarnation, which changes the race */ |
69 | if (spell->race) |
51 | if (spell->race) |
70 | { |
52 | { |
71 | treasurelist *tl = find_treasurelist (spell->race); |
53 | treasurelist *tl = treasurelist::find (spell->race); |
72 | treasure *t; |
54 | treasure *t; |
73 | int value; |
55 | int value; |
74 | |
56 | |
75 | if (!tl) |
57 | if (!tl) |
76 | { |
58 | { |
77 | 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); |
78 | return 0; |
60 | return 0; |
79 | } |
61 | } |
|
|
62 | |
80 | value = RANDOM () % tl->total_chance; |
63 | value = rndm (tl->total_chance); |
|
|
64 | |
81 | for (t = tl->items; t; t = t->next) |
65 | for (t = tl->items; t; t = t->next) |
82 | { |
66 | { |
83 | value -= t->chance; |
67 | value -= t->chance; |
84 | if (value < 0) |
68 | if (value < 0) |
85 | break; |
69 | break; |
86 | } |
70 | } |
87 | if (!t) |
71 | |
|
|
72 | if (!t || !t->item) |
88 | { |
73 | { |
89 | 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); |
90 | return 0; |
75 | return 0; |
91 | } |
76 | } |
|
|
77 | |
92 | race = t->item->name; |
78 | race = t->item->archname; |
93 | } |
79 | } |
94 | |
80 | |
95 | /* set up our paths/strings... */ |
81 | /* set up our paths/strings... */ |
96 | 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); |
97 | |
83 | |
… | |
… | |
126 | { |
112 | { |
127 | fgets (buf, 255, deadplayer); |
113 | fgets (buf, 255, deadplayer); |
128 | sscanf (buf, "%s", buf2); |
114 | sscanf (buf, "%s", buf2); |
129 | if (!(strcmp (buf2, "exp"))) |
115 | if (!(strcmp (buf2, "exp"))) |
130 | { |
116 | { |
131 | long long exp_; |
|
|
132 | |
|
|
133 | sscanf (buf, "%s %lld", buf2, &exp_); |
117 | sscanf (buf, "%s %" SCNd64, buf2, &exp); |
134 | exp = exp_; |
|
|
135 | if (spell->stats.exp) |
118 | if (spell->stats.exp) |
136 | { |
119 | { |
137 | exp -= exp / spell->stats.exp; |
120 | exp -= exp / spell->stats.exp; |
138 | sprintf (buf, "exp %lld\n", exp_); |
121 | sprintf (buf, "exp %" PRId64 "\n", exp); |
139 | exp = exp_; |
|
|
140 | } |
122 | } |
141 | } |
123 | } |
142 | if (!(strcmp (buf2, "Con"))) |
124 | if (!(strcmp (buf2, "Con"))) |
143 | { |
125 | { |
144 | sscanf (buf, "%s %d", buf2, &Con); |
126 | sscanf (buf, "%s %d", buf2, &Con); |
… | |
… | |
156 | fclose (liveplayer); |
138 | fclose (liveplayer); |
157 | fclose (deadplayer); |
139 | fclose (deadplayer); |
158 | unlink (oldname); |
140 | unlink (oldname); |
159 | 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); |
160 | |
142 | |
|
|
143 | return 1; |
|
|
144 | } |
|
|
145 | |
|
|
146 | 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 */ |
161 | return 1; |
160 | return 1; |
162 | } |
161 | } |
163 | |
162 | |
164 | |
163 | |
165 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
164 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
… | |
… | |
173 | { |
172 | { |
174 | object *temp, *newob; |
173 | object *temp, *newob; |
175 | char name_to_resurrect[MAX_BUF]; |
174 | char name_to_resurrect[MAX_BUF]; |
176 | int leveldead = 25, mflags, clevel; |
175 | int leveldead = 25, mflags, clevel; |
177 | sint16 sx, sy; |
176 | sint16 sx, sy; |
178 | mapstruct *m; |
177 | maptile *m; |
179 | |
178 | |
180 | clevel = caster_level (caster, spell); |
179 | clevel = casting_level (caster, spell); |
181 | |
180 | |
182 | if (spell->last_heal) |
181 | if (spell->last_heal) |
183 | { |
182 | { |
184 | if (!arg) |
183 | if (!arg) |
185 | { |
184 | { |
… | |
… | |
199 | temp = NULL; |
198 | temp = NULL; |
200 | else |
199 | else |
201 | { |
200 | { |
202 | /* First we need to find a corpse, if any. */ |
201 | /* First we need to find a corpse, if any. */ |
203 | /* If no object, temp will be set to NULL */ |
202 | /* If no object, temp will be set to NULL */ |
204 | for (temp = get_map_ob (m, sx, sy); temp != NULL; temp = temp->above) |
203 | for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above) |
205 | /* If it is corpse, this must be what we want to raise */ |
204 | /* If it is corpse, this must be what we want to raise */ |
206 | if (temp->type == CORPSE) |
205 | if (temp->type == CORPSE) |
207 | break; |
206 | break; |
208 | } |
207 | } |
209 | |
208 | |
… | |
… | |
217 | |
216 | |
218 | /* no matter what, we fry the corpse. */ |
217 | /* no matter what, we fry the corpse. */ |
219 | if (temp && temp->map) |
218 | if (temp && temp->map) |
220 | { |
219 | { |
221 | /* replace corpse object with a burning object */ |
220 | /* replace corpse object with a burning object */ |
222 | newob = arch_to_object (find_archetype ("burnout")); |
221 | newob = archetype::get (shstr_burnout); |
223 | if (newob != NULL) |
222 | if (newob) |
224 | { |
223 | newob->insert_at (temp, op); |
225 | newob->x = temp->x; |
224 | |
226 | newob->y = temp->y; |
|
|
227 | insert_ob_in_map (newob, temp->map, op, 0); |
|
|
228 | } |
|
|
229 | leveldead = temp->level; |
225 | leveldead = temp->level; |
230 | remove_ob (temp); |
226 | temp->destroy (); |
231 | free_object (temp); |
|
|
232 | } |
227 | } |
233 | |
228 | |
234 | if (resurrection_fails (clevel, leveldead)) |
229 | if (resurrection_fails (clevel, leveldead)) |
235 | { |
230 | { |
236 | if (spell->randomitems) |
231 | if (spell->randomitems) |
237 | { |
|
|
238 | treasure *t; |
|
|
239 | |
|
|
240 | for (t = spell->randomitems->items; t; t = t->next) |
232 | for (treasure *t = spell->randomitems->items; t; t = t->next) |
241 | { |
233 | if (t->item) |
242 | summon_hostile_monsters (op, t->nrof, t->item->name); |
234 | summon_hostile_monsters (op, t->nrof, t->item->archname); |
243 | } |
|
|
244 | |
235 | |
245 | } |
|
|
246 | return 1; |
236 | return 1; |
247 | |
237 | |
248 | } |
238 | } |
249 | else |
239 | else |
250 | { |
|
|
251 | return resurrect_player (op, name_to_resurrect, spell); |
240 | return resurrect_player (op, name_to_resurrect, spell); |
252 | } |
|
|
253 | |
|
|
254 | return 1; |
|
|
255 | } |
241 | } |
256 | |
242 | |
257 | |
|
|
258 | int |
|
|
259 | resurrection_fails (int levelcaster, int leveldead) |
|
|
260 | { |
|
|
261 | int chance = 9; |
|
|
262 | |
|
|
263 | /* scheme: equal in level, 50% success. |
|
|
264 | * +5 % for each level below, -5% for each level above. |
|
|
265 | * minimum 20% |
|
|
266 | */ |
|
|
267 | chance += levelcaster - leveldead; |
|
|
268 | if (chance < 4) |
|
|
269 | chance = 4; |
|
|
270 | if (chance > rndm (0, 19)) |
|
|
271 | return 0; /* resurrection succeeds */ |
|
|
272 | return 1; |
|
|
273 | } |
|
|
274 | |
|
|
275 | void |
|
|
276 | dead_player (object *op) |
|
|
277 | { |
|
|
278 | char filename[MAX_BUF]; |
|
|
279 | char newname[MAX_BUF]; |
|
|
280 | char path[MAX_BUF]; |
|
|
281 | |
|
|
282 | /* set up our paths/strings... */ |
|
|
283 | sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name); |
|
|
284 | |
|
|
285 | strcpy (filename, path); |
|
|
286 | strcat (filename, ".pl"); |
|
|
287 | strcpy (newname, filename); |
|
|
288 | strcat (newname, ".dead"); |
|
|
289 | |
|
|
290 | if (rename (filename, newname) != 0) |
|
|
291 | { |
|
|
292 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno)); |
|
|
293 | } |
|
|
294 | } |
|
|
295 | |
|
|
296 | |
|
|
297 | |
|
|
298 | void |
|
|
299 | dead_character (const char *name) |
|
|
300 | { |
|
|
301 | char buf[MAX_BUF]; |
|
|
302 | char buf2[MAX_BUF]; |
|
|
303 | |
|
|
304 | sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name); |
|
|
305 | /* peterm: create a .dead filename.... ***.pl.dead */ |
|
|
306 | strcpy (buf2, buf); |
|
|
307 | strcat (buf, ".dead"); |
|
|
308 | if (rename (buf2, buf) == -1) |
|
|
309 | { |
|
|
310 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno)); |
|
|
311 | } |
|
|
312 | } |
|
|
313 | |
|
|
314 | |
|
|
315 | int |
|
|
316 | dead_player_exists (const char *name) |
|
|
317 | { |
|
|
318 | char buf[MAX_BUF]; |
|
|
319 | |
|
|
320 | sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name); |
|
|
321 | strcat (buf, ".pl.dead"); |
|
|
322 | return !(access (buf, 0)); |
|
|
323 | } |
|
|