1 | /* |
1 | /* |
2 | * static char *rcsid_resurrection_c = |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * "$Id: resurrection.C,v 1.4 2006/09/03 00:18:42 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
9 | * under the terms of the GNU General Public License as published by the Free |
|
|
10 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
11 | * any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
16 | * for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
4 | */ |
23 | */ |
5 | |
|
|
6 | /* |
|
|
7 | CrossFire, A Multiplayer game for X-windows |
|
|
8 | |
|
|
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
10 | Copyright (C) 1992 Frank Tore Johansen |
|
|
11 | |
|
|
12 | This program is free software; you can redistribute it and/or modify |
|
|
13 | it under the terms of the GNU General Public License as published by |
|
|
14 | the Free Software Foundation; either version 2 of the License, or |
|
|
15 | (at your option) any later version. |
|
|
16 | |
|
|
17 | This program is distributed in the hope that it will be useful, |
|
|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | GNU General Public License for more details. |
|
|
21 | |
|
|
22 | You should have received a copy of the GNU General Public License |
|
|
23 | along with this program; if not, write to the Free Software |
|
|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
25 | |
|
|
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
27 | */ |
|
|
28 | |
24 | |
29 | /* 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 |
30 | all of the above disclaimers apply. */ |
26 | all of the above disclaimers apply. */ |
31 | |
27 | |
32 | #include <global.h> |
28 | #include <global.h> |
33 | #ifndef __CEXTRACT__ |
|
|
34 | #include <sproto.h> |
29 | #include <sproto.h> |
35 | #endif |
|
|
36 | #include <spells.h> |
30 | #include <spells.h> |
37 | #include <errno.h> |
31 | #include <errno.h> |
38 | #ifdef sequent |
|
|
39 | /* stoopid sequent includes don't do this like they should */ |
|
|
40 | extern char * sys_errlist[]; |
|
|
41 | extern int sys_nerr; |
|
|
42 | #endif |
|
|
43 | extern char **classname; |
|
|
44 | extern object *objects; |
|
|
45 | |
|
|
46 | |
|
|
47 | |
32 | |
48 | /* name of the person to resurrect and which spell was used |
33 | /* name of the person to resurrect and which spell was used |
49 | * to resurrect |
34 | * to resurrect |
50 | */ |
35 | */ |
|
|
36 | static int |
51 | static int resurrect_player(object *op,char *playername,object *spell) |
37 | resurrect_player (object *op, char *playername, object *spell) |
52 | { |
38 | { |
53 | FILE *deadplayer,*liveplayer; |
39 | FILE *deadplayer, *liveplayer; |
54 | |
40 | |
55 | char oldname[MAX_BUF]; |
41 | char oldname[MAX_BUF]; |
56 | char newname[MAX_BUF]; |
42 | char newname[MAX_BUF]; |
57 | char path[MAX_BUF]; |
43 | char path[MAX_BUF]; |
58 | char buf[MAX_BUF]; |
44 | char buf[MAX_BUF]; |
59 | char buf2[MAX_BUF]; |
45 | char buf2[MAX_BUF]; |
60 | const char *race=NULL; |
46 | const char *race = NULL; |
61 | sint64 exp; |
47 | sint64 exp; |
62 | int Con; |
48 | int Con; |
63 | |
49 | |
64 | |
|
|
65 | /* reincarnation, which changes the race */ |
50 | /* reincarnation, which changes the race */ |
66 | if (spell->race) { |
51 | if (spell->race) |
|
|
52 | { |
67 | treasurelist *tl = find_treasurelist(spell->race); |
53 | treasurelist *tl = treasurelist::find (spell->race); |
68 | treasure *t; |
54 | treasure *t; |
69 | int value; |
55 | int value; |
|
|
56 | |
70 | if (!tl) { |
57 | if (!tl) |
|
|
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 = RANDOM () % tl->total_chance; |
|
|
64 | |
75 | for (t=tl->items; t; t=t->next) { |
65 | for (t = tl->items; t; t = t->next) |
|
|
66 | { |
76 | value -= t->chance; |
67 | value -= t->chance; |
77 | if (value<0) break; |
68 | if (value < 0) |
|
|
69 | break; |
|
|
70 | } |
|
|
71 | |
|
|
72 | if (!t || !t->item) |
78 | } |
73 | { |
79 | if (!t) { |
|
|
80 | 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); |
81 | return 0; |
75 | return 0; |
82 | } |
76 | } |
|
|
77 | |
83 | race = t->item->name; |
78 | race = t->item->archname; |
84 | } |
79 | } |
85 | |
80 | |
86 | /* set up our paths/strings... */ |
81 | /* set up our paths/strings... */ |
87 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,playername, |
82 | sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername); |
88 | playername); |
|
|
89 | |
83 | |
90 | strcpy(newname,path); |
84 | strcpy (newname, path); |
91 | strcat(newname,".pl"); |
85 | strcat (newname, ".pl"); |
92 | |
86 | |
93 | strcpy(oldname,newname); |
87 | strcpy (oldname, newname); |
94 | strcat(oldname,".dead"); |
88 | strcat (oldname, ".dead"); |
95 | |
89 | |
96 | if(! (deadplayer=fopen(oldname,"r"))) { |
90 | if (!(deadplayer = fopen (oldname, "r"))) |
97 | new_draw_info_format(NDI_UNIQUE, 0, op, |
91 | { |
98 | "The soul of %s cannot be reached.",playername); |
92 | new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be reached.", playername); |
99 | return 0; |
93 | return 0; |
100 | } |
94 | } |
101 | |
95 | |
102 | if(!access(newname,0)) { |
96 | if (!access (newname, 0)) |
103 | new_draw_info_format(NDI_UNIQUE, 0, op, |
97 | { |
104 | "The soul of %s has already been reborn!",playername); |
98 | new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s has already been reborn!", playername); |
105 | fclose(deadplayer); |
99 | fclose (deadplayer); |
106 | return 0; |
100 | return 0; |
107 | } |
101 | } |
108 | |
102 | |
109 | if(! (liveplayer=fopen(newname,"w"))) { |
103 | if (!(liveplayer = fopen (newname, "w"))) |
110 | new_draw_info_format(NDI_UNIQUE, 0, op, |
104 | { |
111 | "The soul of %s cannot be re-embodied at the moment.",playername); |
105 | new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be re-embodied at the moment.", playername); |
112 | LOG(llevError,"Cannot write player in resurrect_player!\n"); |
106 | LOG (llevError, "Cannot write player in resurrect_player!\n"); |
113 | fclose(deadplayer); |
107 | fclose (deadplayer); |
114 | return 0; |
108 | return 0; |
115 | } |
109 | } |
116 | |
110 | |
117 | while (!feof(deadplayer)) { |
111 | while (!feof (deadplayer)) |
|
|
112 | { |
118 | fgets(buf,255,deadplayer); |
113 | fgets (buf, 255, deadplayer); |
119 | sscanf(buf,"%s",buf2); |
114 | sscanf (buf, "%s", buf2); |
120 | if( ! (strcmp(buf2,"exp"))) { |
115 | if (!(strcmp (buf2, "exp"))) |
121 | long long exp_; |
116 | { |
122 | sscanf(buf,"%s %lld",buf2,&exp_); exp = exp_; |
117 | sscanf (buf, "%s %" SCNd64, buf2, &exp); |
123 | if (spell->stats.exp) { |
118 | if (spell->stats.exp) |
|
|
119 | { |
124 | exp-=exp/spell->stats.exp; |
120 | exp -= exp / spell->stats.exp; |
125 | sprintf(buf,"exp %lld\n",exp_); exp = exp_; |
121 | sprintf (buf, "exp %" PRId64 "\n", exp); |
126 | } |
122 | } |
127 | } |
123 | } |
128 | if(! (strcmp(buf2,"Con"))) { |
124 | if (!(strcmp (buf2, "Con"))) |
|
|
125 | { |
129 | sscanf(buf,"%s %d",buf2,&Con); |
126 | sscanf (buf, "%s %d", buf2, &Con); |
130 | Con -= spell->stats.Con; |
127 | Con -= spell->stats.Con; |
131 | if (Con < 1) Con = 1; |
128 | if (Con < 1) |
|
|
129 | Con = 1; |
132 | sprintf(buf,"Con %d\n",Con); |
130 | sprintf (buf, "Con %d\n", Con); |
133 | } |
131 | } |
134 | if(race && !strcmp(buf2,"race")) { |
132 | if (race && !strcmp (buf2, "race")) |
|
|
133 | { |
135 | sprintf(buf,"race %s\n",race); |
134 | sprintf (buf, "race %s\n", race); |
136 | } |
135 | } |
137 | fputs(buf,liveplayer); |
136 | fputs (buf, liveplayer); |
138 | } |
137 | } |
139 | fclose(liveplayer); |
138 | fclose (liveplayer); |
140 | fclose(deadplayer); |
139 | fclose (deadplayer); |
141 | unlink(oldname); |
140 | unlink (oldname); |
142 | new_draw_info_format(NDI_UNIQUE, 0, op, |
141 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername); |
143 | "%s lives again!",playername); |
|
|
144 | |
142 | |
145 | return 1; |
143 | return 1; |
146 | } |
144 | } |
147 | |
145 | |
148 | |
146 | |
149 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
147 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
150 | * op -- who is doing the resurrecting |
148 | * op -- who is doing the resurrecting |
151 | * spell - spell object |
149 | * spell - spell object |
152 | * dir -- direction the spell is cast |
150 | * dir -- direction the spell is cast |
153 | * corpseobj - corpse to raise - can be null, in which case this function will find it |
151 | * corpseobj - corpse to raise - can be null, in which case this function will find it |
154 | */ |
152 | */ |
|
|
153 | int |
155 | int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg) |
154 | cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg) |
156 | { |
155 | { |
157 | object *temp, *newob; |
156 | object *temp, *newob; |
158 | char name_to_resurrect[MAX_BUF]; |
157 | char name_to_resurrect[MAX_BUF]; |
159 | int leveldead=25, mflags, clevel; |
158 | int leveldead = 25, mflags, clevel; |
160 | sint16 sx, sy; |
159 | sint16 sx, sy; |
161 | mapstruct *m; |
160 | maptile *m; |
162 | |
161 | |
163 | clevel = caster_level(caster, spell); |
162 | clevel = caster_level (caster, spell); |
164 | |
163 | |
165 | if (spell->last_heal) { |
164 | if (spell->last_heal) |
|
|
165 | { |
166 | if (!arg) { |
166 | if (!arg) |
|
|
167 | { |
167 | new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", &spell->name); |
168 | new_draw_info_format (NDI_UNIQUE, 0, op, "Cast %s on who?", &spell->name); |
168 | return 0; |
169 | return 0; |
169 | } |
170 | } |
170 | strcpy(name_to_resurrect, arg); |
171 | strcpy (name_to_resurrect, arg); |
|
|
172 | temp = NULL; |
|
|
173 | } |
|
|
174 | else |
|
|
175 | { |
|
|
176 | sx = op->x + freearr_x[dir]; |
|
|
177 | sy = op->y + freearr_y[dir]; |
|
|
178 | m = op->map; |
|
|
179 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
|
|
180 | if (mflags & P_OUT_OF_MAP) |
171 | temp = NULL; |
181 | temp = NULL; |
172 | } else { |
|
|
173 | sx = op->x+freearr_x[dir]; |
|
|
174 | sy = op->y+freearr_y[dir]; |
|
|
175 | m = op->map; |
|
|
176 | mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
|
|
177 | if (mflags & P_OUT_OF_MAP) |
|
|
178 | temp=NULL; |
|
|
179 | else { |
182 | else |
|
|
183 | { |
180 | /* First we need to find a corpse, if any. */ |
184 | /* First we need to find a corpse, if any. */ |
181 | /* If no object, temp will be set to NULL */ |
185 | /* If no object, temp will be set to NULL */ |
182 | for(temp=get_map_ob(m, sx, sy); temp!=NULL; temp=temp->above) |
186 | for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above) |
183 | /* If it is corpse, this must be what we want to raise */ |
187 | /* If it is corpse, this must be what we want to raise */ |
184 | if(temp->type == CORPSE) |
188 | if (temp->type == CORPSE) |
185 | break; |
189 | break; |
186 | } |
190 | } |
187 | |
191 | |
188 | if(temp == NULL) { |
192 | if (temp == NULL) |
|
|
193 | { |
189 | new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell."); |
194 | new_draw_info (NDI_UNIQUE, 0, op, "You need a body for this spell."); |
190 | return 0; |
195 | return 0; |
191 | } |
196 | } |
192 | strcpy(name_to_resurrect, temp->name ); |
197 | strcpy (name_to_resurrect, temp->name); |
193 | } |
198 | } |
194 | |
199 | |
195 | /* no matter what, we fry the corpse. */ |
200 | /* no matter what, we fry the corpse. */ |
196 | if( temp && temp->map){ |
201 | if (temp && temp->map) |
|
|
202 | { |
197 | /* replace corpse object with a burning object */ |
203 | /* replace corpse object with a burning object */ |
198 | newob = arch_to_object(find_archetype("burnout")); |
204 | newob = arch_to_object (archetype::find ("burnout")); |
199 | if(newob != NULL){ |
205 | if (newob) |
200 | newob->x = temp->x; |
206 | newob->insert_at (temp, op); |
201 | newob->y = temp->y; |
207 | |
202 | insert_ob_in_map( newob, temp->map, op,0); |
|
|
203 | } |
|
|
204 | leveldead=temp->level; |
208 | leveldead = temp->level; |
205 | remove_ob(temp); |
209 | temp->destroy (); |
206 | free_object(temp); |
|
|
207 | } |
210 | } |
208 | |
211 | |
209 | if(resurrection_fails(clevel,leveldead)) { |
212 | if (resurrection_fails (clevel, leveldead)) |
|
|
213 | { |
210 | if (spell->randomitems) { |
214 | if (spell->randomitems) |
211 | treasure *t; |
|
|
212 | |
|
|
213 | for (t=spell->randomitems->items; t; t=t->next) { |
215 | for (treasure *t = spell->randomitems->items; t; t = t->next) |
|
|
216 | if (t->item) |
214 | summon_hostile_monsters(op, t->nrof, t->item->name); |
217 | summon_hostile_monsters (op, t->nrof, t->item->archname); |
215 | } |
|
|
216 | |
218 | |
217 | } |
|
|
218 | return 1; |
219 | return 1; |
219 | |
220 | |
220 | } else { |
221 | } |
|
|
222 | else |
221 | return resurrect_player(op,name_to_resurrect,spell); |
223 | return resurrect_player (op, name_to_resurrect, spell); |
222 | } |
|
|
223 | |
|
|
224 | return 1; |
|
|
225 | } |
224 | } |
226 | |
225 | |
227 | |
226 | |
|
|
227 | int |
228 | int resurrection_fails(int levelcaster,int leveldead) |
228 | resurrection_fails (int levelcaster, int leveldead) |
229 | { |
229 | { |
230 | int chance=9; |
230 | int chance = 9; |
|
|
231 | |
231 | /* scheme: equal in level, 50% success. |
232 | /* scheme: equal in level, 50% success. |
232 | * +5 % for each level below, -5% for each level above. |
233 | * +5 % for each level below, -5% for each level above. |
233 | * minimum 20% |
234 | * minimum 20% |
234 | */ |
235 | */ |
235 | chance+=levelcaster-leveldead; |
236 | chance += levelcaster - leveldead; |
236 | if(chance<4) chance=4; |
237 | if (chance < 4) |
237 | if(chance>rndm(0, 19)) return 0; /* resurrection succeeds */ |
238 | chance = 4; |
|
|
239 | if (chance > rndm (0, 19)) |
|
|
240 | return 0; /* resurrection succeeds */ |
238 | return 1; |
241 | return 1; |
239 | } |
242 | } |
240 | |
243 | |
|
|
244 | void |
241 | void dead_player(object *op) |
245 | dead_player (object *op) |
242 | { |
246 | { |
243 | char filename[MAX_BUF]; |
247 | char filename[MAX_BUF]; |
244 | char newname[MAX_BUF]; |
248 | char newname[MAX_BUF]; |
245 | char path[MAX_BUF]; |
249 | char path[MAX_BUF]; |
246 | |
250 | |
247 | /* set up our paths/strings... */ |
251 | /* set up our paths/strings... */ |
248 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,&op->name, &op->name); |
252 | sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name); |
249 | |
253 | |
250 | strcpy(filename,path); |
254 | strcpy (filename, path); |
251 | strcat(filename,".pl"); |
255 | strcat (filename, ".pl"); |
252 | strcpy(newname,filename); |
256 | strcpy (newname, filename); |
253 | strcat(newname,".dead"); |
257 | strcat (newname, ".dead"); |
254 | |
258 | |
255 | if(rename(filename,newname) != 0) { |
259 | if (rename (filename, newname) != 0) |
|
|
260 | { |
256 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror(errno)); |
261 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno)); |
257 | } |
262 | } |
258 | } |
263 | } |
259 | |
264 | |
260 | |
265 | |
261 | |
266 | |
|
|
267 | void |
262 | void dead_character(const char *name) { |
268 | dead_character (const char *name) |
|
|
269 | { |
263 | char buf[MAX_BUF]; |
270 | char buf[MAX_BUF]; |
264 | char buf2[MAX_BUF]; |
271 | char buf2[MAX_BUF]; |
265 | |
272 | |
266 | sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name); |
273 | sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name); |
267 | /* peterm: create a .dead filename.... ***.pl.dead */ |
274 | /* peterm: create a .dead filename.... ***.pl.dead */ |
268 | strcpy(buf2,buf); |
275 | strcpy (buf2, buf); |
269 | strcat(buf,".dead"); |
276 | strcat (buf, ".dead"); |
270 | if(rename(buf2,buf)== -1){ |
277 | if (rename (buf2, buf) == -1) |
|
|
278 | { |
271 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror(errno)); |
279 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno)); |
272 | } |
280 | } |
273 | } |
281 | } |
274 | |
282 | |
275 | |
283 | |
|
|
284 | int |
276 | int dead_player_exists(const char *name) { |
285 | dead_player_exists (const char *name) |
|
|
286 | { |
277 | char buf[MAX_BUF]; |
287 | char buf[MAX_BUF]; |
278 | |
288 | |
279 | sprintf(buf,"%s/%s/%s/%s",settings.localdir,settings.playerdir,name, name); |
289 | sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name); |
280 | strcat(buf,".pl.dead"); |
290 | strcat (buf, ".pl.dead"); |
281 | return !(access(buf,0)); |
291 | return !(access (buf, 0)); |
282 | } |
292 | } |
283 | |
|
|
284 | |
|
|