1 | /* |
1 | /* |
2 | * static char *rcsid_resurrection_c = |
2 | * static char *rcsid_resurrection_c = |
3 | * "$Id: resurrection.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; |
3 | * "$Id: resurrection.C,v 1.2 2006/08/29 08:01:38 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
62 | int Con; |
62 | int Con; |
63 | |
63 | |
64 | |
64 | |
65 | /* reincarnation, which changes the race */ |
65 | /* reincarnation, which changes the race */ |
66 | if (spell->race) { |
66 | if (spell->race) { |
67 | treasurelist *tl = find_treasurelist(spell->race); |
67 | treasurelist *tl = find_treasurelist(spell->race); |
68 | treasure *t; |
68 | treasure *t; |
69 | int value; |
69 | int value; |
70 | if (!tl) { |
70 | if (!tl) { |
71 | LOG(llevError,"resurrect_player: race set to %s, but no treasurelist of that name!\n", spell->race); |
71 | LOG(llevError,"resurrect_player: race set to %s, but no treasurelist of that name!\n", spell->race); |
72 | return 0; |
72 | return 0; |
73 | } |
73 | } |
74 | value = RANDOM() % tl->total_chance; |
74 | value = RANDOM() % tl->total_chance; |
75 | for (t=tl->items; t; t=t->next) { |
75 | for (t=tl->items; t; t=t->next) { |
76 | value -= t->chance; |
76 | value -= t->chance; |
77 | if (value<0) break; |
77 | if (value<0) break; |
78 | } |
78 | } |
79 | if (!t) { |
79 | if (!t) { |
80 | LOG(llevError,"resurrect_player: got null treasure from treasurelist %s!\n", spell->race); |
80 | LOG(llevError,"resurrect_player: got null treasure from treasurelist %s!\n", spell->race); |
81 | return 0; |
81 | return 0; |
82 | } |
82 | } |
83 | race = t->item->name; |
83 | race = t->item->name; |
84 | } |
84 | } |
85 | |
85 | |
86 | /* set up our paths/strings... */ |
86 | /* set up our paths/strings... */ |
87 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,playername, |
87 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,playername, |
88 | playername); |
88 | playername); |
89 | |
89 | |
90 | strcpy(newname,path); |
90 | strcpy(newname,path); |
91 | strcat(newname,".pl"); |
91 | strcat(newname,".pl"); |
92 | |
92 | |
93 | strcpy(oldname,newname); |
93 | strcpy(oldname,newname); |
94 | strcat(oldname,".dead"); |
94 | strcat(oldname,".dead"); |
95 | |
95 | |
96 | if(! (deadplayer=fopen(oldname,"r"))) { |
96 | if(! (deadplayer=fopen(oldname,"r"))) { |
97 | new_draw_info_format(NDI_UNIQUE, 0, op, |
97 | new_draw_info_format(NDI_UNIQUE, 0, op, |
98 | "The soul of %s cannot be reached.",playername); |
98 | "The soul of %s cannot be reached.",playername); |
99 | return 0; |
99 | return 0; |
100 | } |
100 | } |
101 | |
101 | |
102 | if(!access(newname,0)) { |
102 | if(!access(newname,0)) { |
103 | new_draw_info_format(NDI_UNIQUE, 0, op, |
103 | new_draw_info_format(NDI_UNIQUE, 0, op, |
104 | "The soul of %s has already been reborn!",playername); |
104 | "The soul of %s has already been reborn!",playername); |
105 | fclose(deadplayer); |
105 | fclose(deadplayer); |
106 | return 0; |
106 | return 0; |
107 | } |
107 | } |
108 | |
108 | |
109 | if(! (liveplayer=fopen(newname,"w"))) { |
109 | if(! (liveplayer=fopen(newname,"w"))) { |
110 | new_draw_info_format(NDI_UNIQUE, 0, op, |
110 | new_draw_info_format(NDI_UNIQUE, 0, op, |
111 | "The soul of %s cannot be re-embodied at the moment.",playername); |
111 | "The soul of %s cannot be re-embodied at the moment.",playername); |
112 | LOG(llevError,"Cannot write player in resurrect_player!\n"); |
112 | LOG(llevError,"Cannot write player in resurrect_player!\n"); |
113 | fclose(deadplayer); |
113 | fclose(deadplayer); |
114 | return 0; |
114 | return 0; |
115 | } |
115 | } |
116 | |
116 | |
117 | while (!feof(deadplayer)) { |
117 | while (!feof(deadplayer)) { |
118 | fgets(buf,255,deadplayer); |
118 | fgets(buf,255,deadplayer); |
119 | sscanf(buf,"%s",buf2); |
119 | sscanf(buf,"%s",buf2); |
120 | if( ! (strcmp(buf2,"exp"))) { |
120 | if( ! (strcmp(buf2,"exp"))) { |
121 | #ifndef WIN32 |
121 | #ifndef WIN32 |
122 | sscanf(buf,"%s %lld",buf2,&exp); |
122 | sscanf(buf,"%s %lld",buf2,&exp); |
123 | #else |
123 | #else |
124 | sscanf(buf,"%s %I64d",buf2,&exp); |
124 | sscanf(buf,"%s %I64d",buf2,&exp); |
125 | #endif |
125 | #endif |
126 | if (spell->stats.exp) { |
126 | if (spell->stats.exp) { |
127 | exp-=exp/spell->stats.exp; |
127 | exp-=exp/spell->stats.exp; |
128 | #ifndef WIN32 |
128 | #ifndef WIN32 |
129 | sprintf(buf,"exp %lld\n",exp); |
129 | sprintf(buf,"exp %lld\n",exp); |
130 | #else |
130 | #else |
131 | sprintf(buf,"exp %I64d\n",exp); |
131 | sprintf(buf,"exp %I64d\n",exp); |
132 | #endif |
132 | #endif |
133 | } |
133 | } |
134 | } |
134 | } |
135 | if(! (strcmp(buf2,"Con"))) { |
135 | if(! (strcmp(buf2,"Con"))) { |
136 | sscanf(buf,"%s %d",buf2,&Con); |
136 | sscanf(buf,"%s %d",buf2,&Con); |
137 | Con -= spell->stats.Con; |
137 | Con -= spell->stats.Con; |
138 | if (Con < 1) Con = 1; |
138 | if (Con < 1) Con = 1; |
139 | sprintf(buf,"Con %d\n",Con); |
139 | sprintf(buf,"Con %d\n",Con); |
140 | } |
140 | } |
141 | if(race && !strcmp(buf2,"race")) { |
141 | if(race && !strcmp(buf2,"race")) { |
142 | sprintf(buf,"race %s\n",race); |
142 | sprintf(buf,"race %s\n",race); |
143 | } |
143 | } |
144 | fputs(buf,liveplayer); |
144 | fputs(buf,liveplayer); |
145 | } |
145 | } |
146 | fclose(liveplayer); |
146 | fclose(liveplayer); |
147 | fclose(deadplayer); |
147 | fclose(deadplayer); |
148 | unlink(oldname); |
148 | unlink(oldname); |
149 | new_draw_info_format(NDI_UNIQUE, 0, op, |
149 | new_draw_info_format(NDI_UNIQUE, 0, op, |
150 | "%s lives again!",playername); |
150 | "%s lives again!",playername); |
151 | |
151 | |
152 | return 1; |
152 | return 1; |
153 | } |
153 | } |
154 | |
154 | |
155 | |
155 | |
… | |
… | |
168 | mapstruct *m; |
168 | mapstruct *m; |
169 | |
169 | |
170 | clevel = caster_level(caster, spell); |
170 | clevel = caster_level(caster, spell); |
171 | |
171 | |
172 | if (spell->last_heal) { |
172 | if (spell->last_heal) { |
173 | if (!arg) { |
173 | if (!arg) { |
174 | new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", spell->name); |
174 | new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", spell->name); |
175 | return 0; |
175 | return 0; |
176 | } |
176 | } |
177 | strcpy(name_to_resurrect, arg); |
177 | strcpy(name_to_resurrect, arg); |
178 | temp = NULL; |
178 | temp = NULL; |
179 | } else { |
179 | } else { |
180 | sx = op->x+freearr_x[dir]; |
180 | sx = op->x+freearr_x[dir]; |
181 | sy = op->y+freearr_y[dir]; |
181 | sy = op->y+freearr_y[dir]; |
182 | m = op->map; |
182 | m = op->map; |
183 | mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
183 | mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
184 | if (mflags & P_OUT_OF_MAP) |
184 | if (mflags & P_OUT_OF_MAP) |
185 | temp=NULL; |
185 | temp=NULL; |
186 | else { |
186 | else { |
187 | /* First we need to find a corpse, if any. */ |
187 | /* First we need to find a corpse, if any. */ |
188 | /* If no object, temp will be set to NULL */ |
188 | /* If no object, temp will be set to NULL */ |
189 | for(temp=get_map_ob(m, sx, sy); temp!=NULL; temp=temp->above) |
189 | for(temp=get_map_ob(m, sx, sy); temp!=NULL; temp=temp->above) |
190 | /* If it is corpse, this must be what we want to raise */ |
190 | /* If it is corpse, this must be what we want to raise */ |
191 | if(temp->type == CORPSE) |
191 | if(temp->type == CORPSE) |
192 | break; |
192 | break; |
193 | } |
193 | } |
194 | |
194 | |
195 | if(temp == NULL) { |
195 | if(temp == NULL) { |
196 | new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell."); |
196 | new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell."); |
197 | return 0; |
197 | return 0; |
198 | } |
198 | } |
199 | strcpy(name_to_resurrect, temp->name ); |
199 | strcpy(name_to_resurrect, temp->name ); |
200 | } |
200 | } |
201 | |
201 | |
202 | /* no matter what, we fry the corpse. */ |
202 | /* no matter what, we fry the corpse. */ |
203 | if( temp && temp->map){ |
203 | if( temp && temp->map){ |
204 | /* replace corpse object with a burning object */ |
204 | /* replace corpse object with a burning object */ |
205 | newob = arch_to_object(find_archetype("burnout")); |
205 | newob = arch_to_object(find_archetype("burnout")); |
206 | if(newob != NULL){ |
206 | if(newob != NULL){ |
207 | newob->x = temp->x; |
207 | newob->x = temp->x; |
208 | newob->y = temp->y; |
208 | newob->y = temp->y; |
209 | insert_ob_in_map( newob, temp->map, op,0); |
209 | insert_ob_in_map( newob, temp->map, op,0); |
210 | } |
210 | } |
211 | leveldead=temp->level; |
211 | leveldead=temp->level; |
212 | remove_ob(temp); |
212 | remove_ob(temp); |
213 | free_object(temp); |
213 | free_object(temp); |
214 | } |
214 | } |
215 | |
215 | |
216 | if(resurrection_fails(clevel,leveldead)) { |
216 | if(resurrection_fails(clevel,leveldead)) { |
217 | if (spell->randomitems) { |
217 | if (spell->randomitems) { |
218 | treasure *t; |
218 | treasure *t; |
219 | |
219 | |
220 | for (t=spell->randomitems->items; t; t=t->next) { |
220 | for (t=spell->randomitems->items; t; t=t->next) { |
221 | summon_hostile_monsters(op, t->nrof, t->item->name); |
221 | summon_hostile_monsters(op, t->nrof, t->item->name); |
222 | } |
222 | } |
223 | |
223 | |
224 | } |
224 | } |
225 | return 1; |
225 | return 1; |
226 | |
226 | |
227 | } else { |
227 | } else { |
228 | return resurrect_player(op,name_to_resurrect,spell); |
228 | return resurrect_player(op,name_to_resurrect,spell); |
229 | } |
229 | } |
230 | |
230 | |
231 | return 1; |
231 | return 1; |
232 | } |
232 | } |
233 | |
233 | |
… | |
… | |
251 | char newname[MAX_BUF]; |
251 | char newname[MAX_BUF]; |
252 | char path[MAX_BUF]; |
252 | char path[MAX_BUF]; |
253 | |
253 | |
254 | /* set up our paths/strings... */ |
254 | /* set up our paths/strings... */ |
255 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,op->name, |
255 | sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,op->name, |
256 | op->name); |
256 | op->name); |
257 | |
257 | |
258 | strcpy(filename,path); |
258 | strcpy(filename,path); |
259 | strcat(filename,".pl"); |
259 | strcat(filename,".pl"); |
260 | strcpy(newname,filename); |
260 | strcpy(newname,filename); |
261 | strcat(newname,".dead"); |
261 | strcat(newname,".dead"); |
262 | |
262 | |
263 | if(rename(filename,newname) != 0) { |
263 | if(rename(filename,newname) != 0) { |
264 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror_local(errno)); |
264 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror_local(errno)); |
265 | } |
265 | } |
266 | } |
266 | } |
267 | |
267 | |
268 | |
268 | |
269 | |
269 | |
… | |
… | |
274 | sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name); |
274 | sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name); |
275 | /* peterm: create a .dead filename.... ***.pl.dead */ |
275 | /* peterm: create a .dead filename.... ***.pl.dead */ |
276 | strcpy(buf2,buf); |
276 | strcpy(buf2,buf); |
277 | strcat(buf,".dead"); |
277 | strcat(buf,".dead"); |
278 | if(rename(buf2,buf)== -1){ |
278 | if(rename(buf2,buf)== -1){ |
279 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror_local(errno)); |
279 | LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror_local(errno)); |
280 | } |
280 | } |
281 | } |
281 | } |
282 | |
282 | |
283 | |
283 | |
284 | int dead_player_exists(const char *name) { |
284 | int dead_player_exists(const char *name) { |