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