|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_resurrection_c = |
3 | * static char *rcsid_resurrection_c = |
3 | * "$Id: resurrection.C,v 1.4 2006/09/03 00:18:42 root Exp $"; |
4 | * "$Id: resurrection.C,v 1.5 2006/09/10 15:59:57 root Exp $"; |
4 | */ |
5 | */ |
5 | |
6 | |
6 | /* |
7 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
8 | |
9 | |
… | |
… | |
29 | /* the contents of this file were create solely by peterm@soda.berkeley.edu |
30 | /* the contents of this file were create solely by peterm@soda.berkeley.edu |
30 | all of the above disclaimers apply. */ |
31 | all of the above disclaimers apply. */ |
31 | |
32 | |
32 | #include <global.h> |
33 | #include <global.h> |
33 | #ifndef __CEXTRACT__ |
34 | #ifndef __CEXTRACT__ |
34 | #include <sproto.h> |
35 | # include <sproto.h> |
35 | #endif |
36 | #endif |
36 | #include <spells.h> |
37 | #include <spells.h> |
37 | #include <errno.h> |
38 | #include <errno.h> |
38 | #ifdef sequent |
39 | #ifdef sequent |
|
|
40 | |
39 | /* stoopid sequent includes don't do this like they should */ |
41 | /* stoopid sequent includes don't do this like they should */ |
40 | extern char * sys_errlist[]; |
42 | extern char *sys_errlist[]; |
41 | extern int sys_nerr; |
43 | extern int sys_nerr; |
42 | #endif |
44 | #endif |
43 | extern char **classname; |
45 | extern char **classname; |
44 | extern object *objects; |
46 | extern object *objects; |
45 | |
47 | |
46 | |
48 | |
47 | |
49 | |
48 | /* name of the person to resurrect and which spell was used |
50 | /* name of the person to resurrect and which spell was used |
49 | * to resurrect |
51 | * to resurrect |
50 | */ |
52 | */ |
|
|
53 | static int |
51 | static int resurrect_player(object *op,char *playername,object *spell) |
54 | resurrect_player (object *op, char *playername, object *spell) |
52 | { |
55 | { |
53 | FILE *deadplayer,*liveplayer; |
56 | FILE *deadplayer, *liveplayer; |
54 | |
57 | |
55 | char oldname[MAX_BUF]; |
58 | char oldname[MAX_BUF]; |
56 | char newname[MAX_BUF]; |
59 | char newname[MAX_BUF]; |
57 | char path[MAX_BUF]; |
60 | char path[MAX_BUF]; |
58 | char buf[MAX_BUF]; |
61 | char buf[MAX_BUF]; |
59 | char buf2[MAX_BUF]; |
62 | char buf2[MAX_BUF]; |
60 | const char *race=NULL; |
63 | const char *race = NULL; |
61 | sint64 exp; |
64 | sint64 exp; |
62 | int Con; |
65 | int Con; |
63 | |
66 | |
64 | |
67 | |
65 | /* reincarnation, which changes the race */ |
68 | /* reincarnation, which changes the race */ |
66 | if (spell->race) { |
69 | if (spell->race) |
|
|
70 | { |
67 | treasurelist *tl = find_treasurelist(spell->race); |
71 | treasurelist *tl = find_treasurelist (spell->race); |
68 | treasure *t; |
72 | treasure *t; |
69 | int value; |
73 | int value; |
|
|
74 | |
70 | if (!tl) { |
75 | if (!tl) |
|
|
76 | { |
71 | LOG(llevError,"resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race); |
77 | LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race); |
72 | return 0; |
78 | return 0; |
73 | } |
79 | } |
74 | value = RANDOM() % tl->total_chance; |
80 | value = RANDOM () % tl->total_chance; |
75 | for (t=tl->items; t; t=t->next) { |
81 | for (t = tl->items; t; t = t->next) |
|
|
82 | { |
76 | value -= t->chance; |
83 | value -= t->chance; |
77 | if (value<0) break; |
84 | if (value < 0) |
|
|
85 | break; |
|
|
86 | } |
|
|
87 | if (!t) |
78 | } |
88 | { |
79 | if (!t) { |
|
|
80 | LOG(llevError,"resurrect_player: got null treasure from treasurelist %s!\n", &spell->race); |
89 | LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race); |
81 | return 0; |
90 | return 0; |
82 | } |
91 | } |
83 | race = t->item->name; |
92 | race = t->item->name; |
84 | } |
93 | } |
85 | |
94 | |
86 | /* set up our paths/strings... */ |
95 | /* set up our paths/strings... */ |
87 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,playername, |
96 | sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername); |
88 | playername); |
|
|
89 | |
97 | |
90 | strcpy(newname,path); |
98 | strcpy (newname, path); |
91 | strcat(newname,".pl"); |
99 | strcat (newname, ".pl"); |
92 | |
100 | |
93 | strcpy(oldname,newname); |
101 | strcpy (oldname, newname); |
94 | strcat(oldname,".dead"); |
102 | strcat (oldname, ".dead"); |
95 | |
103 | |
96 | if(! (deadplayer=fopen(oldname,"r"))) { |
104 | if (!(deadplayer = fopen (oldname, "r"))) |
97 | new_draw_info_format(NDI_UNIQUE, 0, op, |
105 | { |
98 | "The soul of %s cannot be reached.",playername); |
106 | new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be reached.", playername); |
99 | return 0; |
107 | return 0; |
100 | } |
108 | } |
101 | |
109 | |
102 | if(!access(newname,0)) { |
110 | if (!access (newname, 0)) |
103 | new_draw_info_format(NDI_UNIQUE, 0, op, |
111 | { |
104 | "The soul of %s has already been reborn!",playername); |
112 | new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s has already been reborn!", playername); |
105 | fclose(deadplayer); |
113 | fclose (deadplayer); |
106 | return 0; |
114 | return 0; |
107 | } |
115 | } |
108 | |
116 | |
109 | if(! (liveplayer=fopen(newname,"w"))) { |
117 | if (!(liveplayer = fopen (newname, "w"))) |
110 | new_draw_info_format(NDI_UNIQUE, 0, op, |
118 | { |
111 | "The soul of %s cannot be re-embodied at the moment.",playername); |
119 | 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"); |
120 | LOG (llevError, "Cannot write player in resurrect_player!\n"); |
113 | fclose(deadplayer); |
121 | fclose (deadplayer); |
114 | return 0; |
122 | return 0; |
115 | } |
123 | } |
116 | |
124 | |
117 | while (!feof(deadplayer)) { |
125 | while (!feof (deadplayer)) |
|
|
126 | { |
118 | fgets(buf,255,deadplayer); |
127 | fgets (buf, 255, deadplayer); |
119 | sscanf(buf,"%s",buf2); |
128 | sscanf (buf, "%s", buf2); |
120 | if( ! (strcmp(buf2,"exp"))) { |
129 | if (!(strcmp (buf2, "exp"))) |
|
|
130 | { |
121 | long long exp_; |
131 | long long exp_; |
|
|
132 | |
122 | sscanf(buf,"%s %lld",buf2,&exp_); exp = exp_; |
133 | sscanf (buf, "%s %lld", buf2, &exp_); |
|
|
134 | exp = exp_; |
123 | if (spell->stats.exp) { |
135 | if (spell->stats.exp) |
|
|
136 | { |
124 | exp-=exp/spell->stats.exp; |
137 | exp -= exp / spell->stats.exp; |
125 | sprintf(buf,"exp %lld\n",exp_); exp = exp_; |
138 | sprintf (buf, "exp %lld\n", exp_); |
|
|
139 | exp = exp_; |
126 | } |
140 | } |
127 | } |
141 | } |
128 | if(! (strcmp(buf2,"Con"))) { |
142 | if (!(strcmp (buf2, "Con"))) |
|
|
143 | { |
129 | sscanf(buf,"%s %d",buf2,&Con); |
144 | sscanf (buf, "%s %d", buf2, &Con); |
130 | Con -= spell->stats.Con; |
145 | Con -= spell->stats.Con; |
131 | if (Con < 1) Con = 1; |
146 | if (Con < 1) |
|
|
147 | Con = 1; |
132 | sprintf(buf,"Con %d\n",Con); |
148 | sprintf (buf, "Con %d\n", Con); |
133 | } |
149 | } |
134 | if(race && !strcmp(buf2,"race")) { |
150 | if (race && !strcmp (buf2, "race")) |
|
|
151 | { |
135 | sprintf(buf,"race %s\n",race); |
152 | sprintf (buf, "race %s\n", race); |
136 | } |
153 | } |
137 | fputs(buf,liveplayer); |
154 | fputs (buf, liveplayer); |
138 | } |
155 | } |
139 | fclose(liveplayer); |
156 | fclose (liveplayer); |
140 | fclose(deadplayer); |
157 | fclose (deadplayer); |
141 | unlink(oldname); |
158 | unlink (oldname); |
142 | new_draw_info_format(NDI_UNIQUE, 0, op, |
159 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername); |
143 | "%s lives again!",playername); |
|
|
144 | |
160 | |
145 | return 1; |
161 | return 1; |
146 | } |
162 | } |
147 | |
163 | |
148 | |
164 | |
149 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
165 | /* raise_dead by peterm and mehlhaff@soda.berkeley.edu |
150 | * op -- who is doing the resurrecting |
166 | * op -- who is doing the resurrecting |
151 | * spell - spell object |
167 | * spell - spell object |
152 | * dir -- direction the spell is cast |
168 | * dir -- direction the spell is cast |
153 | * 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 |
154 | */ |
170 | */ |
|
|
171 | int |
155 | int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg) |
172 | cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg) |
156 | { |
173 | { |
157 | object *temp, *newob; |
174 | object *temp, *newob; |
158 | char name_to_resurrect[MAX_BUF]; |
175 | char name_to_resurrect[MAX_BUF]; |
159 | int leveldead=25, mflags, clevel; |
176 | int leveldead = 25, mflags, clevel; |
160 | sint16 sx, sy; |
177 | sint16 sx, sy; |
161 | mapstruct *m; |
178 | mapstruct *m; |
162 | |
179 | |
163 | clevel = caster_level(caster, spell); |
180 | clevel = caster_level (caster, spell); |
164 | |
181 | |
165 | if (spell->last_heal) { |
182 | if (spell->last_heal) |
|
|
183 | { |
166 | if (!arg) { |
184 | if (!arg) |
|
|
185 | { |
167 | new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", &spell->name); |
186 | new_draw_info_format (NDI_UNIQUE, 0, op, "Cast %s on who?", &spell->name); |
168 | return 0; |
187 | return 0; |
169 | } |
188 | } |
170 | strcpy(name_to_resurrect, arg); |
189 | strcpy (name_to_resurrect, arg); |
|
|
190 | temp = NULL; |
|
|
191 | } |
|
|
192 | else |
|
|
193 | { |
|
|
194 | sx = op->x + freearr_x[dir]; |
|
|
195 | sy = op->y + freearr_y[dir]; |
|
|
196 | m = op->map; |
|
|
197 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
|
|
198 | if (mflags & P_OUT_OF_MAP) |
171 | temp = NULL; |
199 | 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 { |
200 | else |
|
|
201 | { |
180 | /* First we need to find a corpse, if any. */ |
202 | /* First we need to find a corpse, if any. */ |
181 | /* If no object, temp will be set to NULL */ |
203 | /* If no object, temp will be set to NULL */ |
182 | 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) |
183 | /* 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 */ |
184 | if(temp->type == CORPSE) |
206 | if (temp->type == CORPSE) |
185 | break; |
207 | break; |
186 | } |
208 | } |
187 | |
209 | |
188 | if(temp == NULL) { |
210 | if (temp == NULL) |
|
|
211 | { |
189 | new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell."); |
212 | new_draw_info (NDI_UNIQUE, 0, op, "You need a body for this spell."); |
190 | return 0; |
213 | return 0; |
191 | } |
214 | } |
192 | strcpy(name_to_resurrect, temp->name ); |
215 | strcpy (name_to_resurrect, temp->name); |
193 | } |
216 | } |
194 | |
217 | |
195 | /* no matter what, we fry the corpse. */ |
218 | /* no matter what, we fry the corpse. */ |
196 | if( temp && temp->map){ |
219 | if (temp && temp->map) |
|
|
220 | { |
197 | /* replace corpse object with a burning object */ |
221 | /* replace corpse object with a burning object */ |
198 | newob = arch_to_object(find_archetype("burnout")); |
222 | newob = arch_to_object (find_archetype ("burnout")); |
199 | if(newob != NULL){ |
223 | if (newob != NULL) |
|
|
224 | { |
200 | newob->x = temp->x; |
225 | newob->x = temp->x; |
201 | newob->y = temp->y; |
226 | newob->y = temp->y; |
202 | insert_ob_in_map( newob, temp->map, op,0); |
227 | insert_ob_in_map (newob, temp->map, op, 0); |
203 | } |
228 | } |
204 | leveldead=temp->level; |
229 | leveldead = temp->level; |
205 | remove_ob(temp); |
230 | remove_ob (temp); |
206 | free_object(temp); |
231 | free_object (temp); |
207 | } |
232 | } |
208 | |
233 | |
209 | if(resurrection_fails(clevel,leveldead)) { |
234 | if (resurrection_fails (clevel, leveldead)) |
|
|
235 | { |
210 | if (spell->randomitems) { |
236 | if (spell->randomitems) |
|
|
237 | { |
211 | treasure *t; |
238 | treasure *t; |
212 | |
239 | |
213 | for (t=spell->randomitems->items; t; t=t->next) { |
240 | for (t = spell->randomitems->items; t; t = t->next) |
|
|
241 | { |
214 | summon_hostile_monsters(op, t->nrof, t->item->name); |
242 | summon_hostile_monsters (op, t->nrof, t->item->name); |
215 | } |
243 | } |
216 | |
244 | |
217 | } |
245 | } |
218 | return 1; |
246 | return 1; |
219 | |
247 | |
220 | } else { |
248 | } |
|
|
249 | else |
|
|
250 | { |
221 | return resurrect_player(op,name_to_resurrect,spell); |
251 | return resurrect_player (op, name_to_resurrect, spell); |
222 | } |
252 | } |
223 | |
253 | |
224 | return 1; |
254 | return 1; |
225 | } |
255 | } |
226 | |
256 | |
227 | |
257 | |
|
|
258 | int |
228 | int resurrection_fails(int levelcaster,int leveldead) |
259 | resurrection_fails (int levelcaster, int leveldead) |
229 | { |
260 | { |
230 | int chance=9; |
261 | int chance = 9; |
|
|
262 | |
231 | /* scheme: equal in level, 50% success. |
263 | /* scheme: equal in level, 50% success. |
232 | * +5 % for each level below, -5% for each level above. |
264 | * +5 % for each level below, -5% for each level above. |
233 | * minimum 20% |
265 | * minimum 20% |
234 | */ |
266 | */ |
235 | chance+=levelcaster-leveldead; |
267 | chance += levelcaster - leveldead; |
236 | if(chance<4) chance=4; |
268 | if (chance < 4) |
237 | if(chance>rndm(0, 19)) return 0; /* resurrection succeeds */ |
269 | chance = 4; |
|
|
270 | if (chance > rndm (0, 19)) |
|
|
271 | return 0; /* resurrection succeeds */ |
238 | return 1; |
272 | return 1; |
239 | } |
273 | } |
240 | |
274 | |
|
|
275 | void |
241 | void dead_player(object *op) |
276 | dead_player (object *op) |
242 | { |
277 | { |
243 | char filename[MAX_BUF]; |
278 | char filename[MAX_BUF]; |
244 | char newname[MAX_BUF]; |
279 | char newname[MAX_BUF]; |
245 | char path[MAX_BUF]; |
280 | char path[MAX_BUF]; |
246 | |
281 | |
247 | /* set up our paths/strings... */ |
282 | /* set up our paths/strings... */ |
248 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,&op->name, &op->name); |
283 | sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name); |
249 | |
284 | |
250 | strcpy(filename,path); |
285 | strcpy (filename, path); |
251 | strcat(filename,".pl"); |
286 | strcat (filename, ".pl"); |
252 | strcpy(newname,filename); |
287 | strcpy (newname, filename); |
253 | strcat(newname,".dead"); |
288 | strcat (newname, ".dead"); |
254 | |
289 | |
255 | if(rename(filename,newname) != 0) { |
290 | if (rename (filename, newname) != 0) |
|
|
291 | { |
256 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror(errno)); |
292 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno)); |
257 | } |
293 | } |
258 | } |
294 | } |
259 | |
295 | |
260 | |
296 | |
261 | |
297 | |
|
|
298 | void |
262 | void dead_character(const char *name) { |
299 | dead_character (const char *name) |
|
|
300 | { |
263 | char buf[MAX_BUF]; |
301 | char buf[MAX_BUF]; |
264 | char buf2[MAX_BUF]; |
302 | char buf2[MAX_BUF]; |
265 | |
303 | |
266 | sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name); |
304 | sprintf (buf, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name); |
267 | /* peterm: create a .dead filename.... ***.pl.dead */ |
305 | /* peterm: create a .dead filename.... ***.pl.dead */ |
268 | strcpy(buf2,buf); |
306 | strcpy (buf2, buf); |
269 | strcat(buf,".dead"); |
307 | strcat (buf, ".dead"); |
270 | if(rename(buf2,buf)== -1){ |
308 | if (rename (buf2, buf) == -1) |
|
|
309 | { |
271 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror(errno)); |
310 | LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno)); |
272 | } |
311 | } |
273 | } |
312 | } |
274 | |
313 | |
275 | |
314 | |
|
|
315 | int |
276 | int dead_player_exists(const char *name) { |
316 | dead_player_exists (const char *name) |
|
|
317 | { |
277 | char buf[MAX_BUF]; |
318 | char buf[MAX_BUF]; |
278 | |
319 | |
279 | sprintf(buf,"%s/%s/%s/%s",settings.localdir,settings.playerdir,name, name); |
320 | sprintf (buf, "%s/%s/%s/%s", settings.localdir, settings.playerdir, name, name); |
280 | strcat(buf,".pl.dead"); |
321 | strcat (buf, ".pl.dead"); |
281 | return !(access(buf,0)); |
322 | return !(access (buf, 0)); |
282 | } |
323 | } |
283 | |
|
|
284 | |
|
|