ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/resurrection.C
(Generate patch)

Comparing deliantra/server/server/resurrection.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:04 2006 UTC vs.
Revision 1.4 by root, Sun Sep 3 00:18:42 2006 UTC

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.4 2006/09/03 00:18:42 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 long long exp_;
122 sscanf(buf,"%s %lld",buf2,&exp); 122 sscanf(buf,"%s %lld",buf2,&exp_); exp = exp_;
123#else
124 sscanf(buf,"%s %I64d",buf2,&exp);
125#endif
126 if (spell->stats.exp) { 123 if (spell->stats.exp) {
127 exp-=exp/spell->stats.exp; 124 exp-=exp/spell->stats.exp;
128#ifndef WIN32 125 sprintf(buf,"exp %lld\n",exp_); exp = exp_;
129 sprintf(buf,"exp %lld\n",exp); 126 }
130#else 127 }
131 sprintf(buf,"exp %I64d\n",exp);
132#endif
133 }
134 }
135 if(! (strcmp(buf2,"Con"))) { 128 if(! (strcmp(buf2,"Con"))) {
136 sscanf(buf,"%s %d",buf2,&Con); 129 sscanf(buf,"%s %d",buf2,&Con);
137 Con -= spell->stats.Con; 130 Con -= spell->stats.Con;
138 if (Con < 1) Con = 1; 131 if (Con < 1) Con = 1;
139 sprintf(buf,"Con %d\n",Con); 132 sprintf(buf,"Con %d\n",Con);
140 } 133 }
141 if(race && !strcmp(buf2,"race")) { 134 if(race && !strcmp(buf2,"race")) {
142 sprintf(buf,"race %s\n",race); 135 sprintf(buf,"race %s\n",race);
143 } 136 }
144 fputs(buf,liveplayer); 137 fputs(buf,liveplayer);
145 } 138 }
146 fclose(liveplayer); 139 fclose(liveplayer);
147 fclose(deadplayer); 140 fclose(deadplayer);
148 unlink(oldname); 141 unlink(oldname);
149 new_draw_info_format(NDI_UNIQUE, 0, op, 142 new_draw_info_format(NDI_UNIQUE, 0, op,
150 "%s lives again!",playername); 143 "%s lives again!",playername);
151 144
152 return 1; 145 return 1;
153} 146}
154 147
155 148
168 mapstruct *m; 161 mapstruct *m;
169 162
170 clevel = caster_level(caster, spell); 163 clevel = caster_level(caster, spell);
171 164
172 if (spell->last_heal) { 165 if (spell->last_heal) {
173 if (!arg) { 166 if (!arg) {
174 new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", spell->name); 167 new_draw_info_format(NDI_UNIQUE, 0,op,"Cast %s on who?", &spell->name);
175 return 0; 168 return 0;
176 } 169 }
177 strcpy(name_to_resurrect, arg); 170 strcpy(name_to_resurrect, arg);
178 temp = NULL; 171 temp = NULL;
179 } else { 172 } else {
180 sx = op->x+freearr_x[dir]; 173 sx = op->x+freearr_x[dir];
181 sy = op->y+freearr_y[dir]; 174 sy = op->y+freearr_y[dir];
182 m = op->map; 175 m = op->map;
183 mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); 176 mflags = get_map_flags(m, &m, sx, sy, &sx, &sy);
184 if (mflags & P_OUT_OF_MAP) 177 if (mflags & P_OUT_OF_MAP)
185 temp=NULL; 178 temp=NULL;
186 else { 179 else {
187 /* First we need to find a corpse, if any. */ 180 /* First we need to find a corpse, if any. */
188 /* If no object, temp will be set to NULL */ 181 /* If no object, temp will be set to NULL */
189 for(temp=get_map_ob(m, sx, sy); temp!=NULL; temp=temp->above) 182 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 */ 183 /* If it is corpse, this must be what we want to raise */
191 if(temp->type == CORPSE) 184 if(temp->type == CORPSE)
192 break; 185 break;
193 } 186 }
194 187
195 if(temp == NULL) { 188 if(temp == NULL) {
196 new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell."); 189 new_draw_info(NDI_UNIQUE, 0,op, "You need a body for this spell.");
197 return 0; 190 return 0;
198 } 191 }
199 strcpy(name_to_resurrect, temp->name ); 192 strcpy(name_to_resurrect, temp->name );
200 } 193 }
201 194
202 /* no matter what, we fry the corpse. */ 195 /* no matter what, we fry the corpse. */
203 if( temp && temp->map){ 196 if( temp && temp->map){
204 /* replace corpse object with a burning object */ 197 /* replace corpse object with a burning object */
205 newob = arch_to_object(find_archetype("burnout")); 198 newob = arch_to_object(find_archetype("burnout"));
206 if(newob != NULL){ 199 if(newob != NULL){
207 newob->x = temp->x; 200 newob->x = temp->x;
208 newob->y = temp->y; 201 newob->y = temp->y;
209 insert_ob_in_map( newob, temp->map, op,0); 202 insert_ob_in_map( newob, temp->map, op,0);
210 } 203 }
211 leveldead=temp->level; 204 leveldead=temp->level;
212 remove_ob(temp); 205 remove_ob(temp);
213 free_object(temp); 206 free_object(temp);
214 } 207 }
215 208
216 if(resurrection_fails(clevel,leveldead)) { 209 if(resurrection_fails(clevel,leveldead)) {
217 if (spell->randomitems) { 210 if (spell->randomitems) {
218 treasure *t; 211 treasure *t;
219 212
220 for (t=spell->randomitems->items; t; t=t->next) { 213 for (t=spell->randomitems->items; t; t=t->next) {
221 summon_hostile_monsters(op, t->nrof, t->item->name); 214 summon_hostile_monsters(op, t->nrof, t->item->name);
222 } 215 }
223 216
224 } 217 }
225 return 1; 218 return 1;
226 219
227 } else { 220 } else {
228 return resurrect_player(op,name_to_resurrect,spell); 221 return resurrect_player(op,name_to_resurrect,spell);
229 } 222 }
230 223
231 return 1; 224 return 1;
232} 225}
233 226
250 char filename[MAX_BUF]; 243 char filename[MAX_BUF];
251 char newname[MAX_BUF]; 244 char newname[MAX_BUF];
252 char path[MAX_BUF]; 245 char path[MAX_BUF];
253 246
254 /* set up our paths/strings... */ 247 /* set up our paths/strings... */
255 sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,op->name, 248 sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,&op->name, &op->name);
256 op->name);
257 249
258 strcpy(filename,path); 250 strcpy(filename,path);
259 strcat(filename,".pl"); 251 strcat(filename,".pl");
260 strcpy(newname,filename); 252 strcpy(newname,filename);
261 strcat(newname,".dead"); 253 strcat(newname,".dead");
262 254
263 if(rename(filename,newname) != 0) { 255 if(rename(filename,newname) != 0) {
264 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror_local(errno)); 256 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror(errno));
265 } 257 }
266} 258}
267 259
268 260
269 261
274 sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name); 266 sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,name, name);
275 /* peterm: create a .dead filename.... ***.pl.dead */ 267 /* peterm: create a .dead filename.... ***.pl.dead */
276 strcpy(buf2,buf); 268 strcpy(buf2,buf);
277 strcat(buf,".dead"); 269 strcat(buf,".dead");
278 if(rename(buf2,buf)== -1){ 270 if(rename(buf2,buf)== -1){
279 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror_local(errno)); 271 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror(errno));
280 } 272 }
281} 273}
282 274
283 275
284int dead_player_exists(const char *name) { 276int dead_player_exists(const char *name) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines