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.6 by root, Thu Sep 14 21:16:13 2006 UTC

1
1/* 2/*
2 * static char *rcsid_resurrection_c = 3 * static char *rcsid_resurrection_c =
3 * "$Id: resurrection.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; 4 * "$Id: resurrection.C,v 1.6 2006/09/14 21:16:13 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 */
40extern char * sys_errlist[]; 42extern char *sys_errlist[];
41extern int sys_nerr; 43extern int sys_nerr;
42#endif 44#endif
43extern char **classname; 45extern char **classname;
44extern object *objects; 46extern 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 */
53static int
51static int resurrect_player(object *op,char *playername,object *spell) 54resurrect_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;
70 if (!tl) { 74
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)
78 } 85 break;
79 if (!t) { 86 }
87 if (!t)
88 {
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,
98 "The soul of %s cannot be reached.",playername);
99 return 0;
100 } 105 {
101 106 new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be reached.", playername);
102 if(!access(newname,0)) { 107 return 0;
103 new_draw_info_format(NDI_UNIQUE, 0, op,
104 "The soul of %s has already been reborn!",playername);
105 fclose(deadplayer);
106 return 0;
107 }
108
109 if(! (liveplayer=fopen(newname,"w"))) {
110 new_draw_info_format(NDI_UNIQUE, 0, op,
111 "The soul of %s cannot be re-embodied at the moment.",playername);
112 LOG(llevError,"Cannot write player in resurrect_player!\n");
113 fclose(deadplayer);
114 return 0;
115 }
116
117 while (!feof(deadplayer)) {
118 fgets(buf,255,deadplayer);
119 sscanf(buf,"%s",buf2);
120 if( ! (strcmp(buf2,"exp"))) {
121#ifndef WIN32
122 sscanf(buf,"%s %lld",buf2,&exp);
123#else
124 sscanf(buf,"%s %I64d",buf2,&exp);
125#endif
126 if (spell->stats.exp) {
127 exp-=exp/spell->stats.exp;
128#ifndef WIN32
129 sprintf(buf,"exp %lld\n",exp);
130#else
131 sprintf(buf,"exp %I64d\n",exp);
132#endif
133 } 108 }
134 } 109
135 if(! (strcmp(buf2,"Con"))) { 110 if (!access (newname, 0))
136 sscanf(buf,"%s %d",buf2,&Con);
137 Con -= spell->stats.Con;
138 if (Con < 1) Con = 1;
139 sprintf(buf,"Con %d\n",Con);
140 }
141 if(race && !strcmp(buf2,"race")) {
142 sprintf(buf,"race %s\n",race);
143 }
144 fputs(buf,liveplayer);
145 } 111 {
146 fclose(liveplayer); 112 new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s has already been reborn!", playername);
147 fclose(deadplayer); 113 fclose (deadplayer);
114 return 0;
115 }
116
117 if (!(liveplayer = fopen (newname, "w")))
118 {
119 new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be re-embodied at the moment.", playername);
120 LOG (llevError, "Cannot write player in resurrect_player!\n");
121 fclose (deadplayer);
122 return 0;
123 }
124
125 while (!feof (deadplayer))
126 {
127 fgets (buf, 255, deadplayer);
128 sscanf (buf, "%s", buf2);
129 if (!(strcmp (buf2, "exp")))
130 {
131 long long exp_;
132
133 sscanf (buf, "%s %lld", buf2, &exp_);
134 exp = exp_;
135 if (spell->stats.exp)
136 {
137 exp -= exp / spell->stats.exp;
138 sprintf (buf, "exp %lld\n", exp_);
139 exp = exp_;
140 }
141 }
142 if (!(strcmp (buf2, "Con")))
143 {
144 sscanf (buf, "%s %d", buf2, &Con);
145 Con -= spell->stats.Con;
146 if (Con < 1)
147 Con = 1;
148 sprintf (buf, "Con %d\n", Con);
149 }
150 if (race && !strcmp (buf2, "race"))
151 {
152 sprintf (buf, "race %s\n", race);
153 }
154 fputs (buf, liveplayer);
155 }
156 fclose (liveplayer);
157 fclose (deadplayer);
148 unlink(oldname); 158 unlink (oldname);
149 new_draw_info_format(NDI_UNIQUE, 0, op, 159 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername);
150 "%s lives again!",playername);
151 160
152 return 1; 161 return 1;
153} 162}
154 163
155 164
156/* raise_dead by peterm and mehlhaff@soda.berkeley.edu 165/* raise_dead by peterm and mehlhaff@soda.berkeley.edu
157 * op -- who is doing the resurrecting 166 * op -- who is doing the resurrecting
158 * spell - spell object 167 * spell - spell object
159 * dir -- direction the spell is cast 168 * dir -- direction the spell is cast
160 * 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
161 */ 170 */
171int
162int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg) 172cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg)
163{ 173{
164 object *temp, *newob; 174 object *temp, *newob;
165 char name_to_resurrect[MAX_BUF]; 175 char name_to_resurrect[MAX_BUF];
166 int leveldead=25, mflags, clevel; 176 int leveldead = 25, mflags, clevel;
167 sint16 sx, sy; 177 sint16 sx, sy;
168 mapstruct *m; 178 mapstruct *m;
169 179
170 clevel = caster_level(caster, spell); 180 clevel = caster_level (caster, spell);
171 181
172 if (spell->last_heal) { 182 if (spell->last_heal)
173 if (!arg) { 183 {
184 if (!arg)
185 {
174 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);
175 return 0; 187 return 0;
176 } 188 }
177 strcpy(name_to_resurrect, arg); 189 strcpy (name_to_resurrect, arg);
178 temp = NULL; 190 temp = NULL;
179 } else { 191 }
192 else
193 {
180 sx = op->x+freearr_x[dir]; 194 sx = op->x + freearr_x[dir];
181 sy = op->y+freearr_y[dir]; 195 sy = op->y + freearr_y[dir];
182 m = op->map; 196 m = op->map;
183 mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); 197 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
184 if (mflags & P_OUT_OF_MAP) 198 if (mflags & P_OUT_OF_MAP)
185 temp=NULL; 199 temp = NULL;
186 else { 200 else
201 {
187 /* First we need to find a corpse, if any. */ 202 /* First we need to find a corpse, if any. */
188 /* If no object, temp will be set to NULL */ 203 /* If no object, temp will be set to NULL */
189 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)
190 /* 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 */
191 if(temp->type == CORPSE) 206 if (temp->type == CORPSE)
192 break; 207 break;
193 } 208 }
194 209
195 if(temp == NULL) { 210 if (temp == NULL)
211 {
196 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.");
197 return 0; 213 return 0;
198 } 214 }
199 strcpy(name_to_resurrect, temp->name ); 215 strcpy (name_to_resurrect, temp->name);
200 } 216 }
201 217
202 /* no matter what, we fry the corpse. */ 218 /* no matter what, we fry the corpse. */
203 if( temp && temp->map){ 219 if (temp && temp->map)
220 {
204 /* replace corpse object with a burning object */ 221 /* replace corpse object with a burning object */
205 newob = arch_to_object(find_archetype("burnout")); 222 newob = arch_to_object (archetype::find ("burnout"));
206 if(newob != NULL){ 223 if (newob != NULL)
224 {
207 newob->x = temp->x; 225 newob->x = temp->x;
208 newob->y = temp->y; 226 newob->y = temp->y;
209 insert_ob_in_map( newob, temp->map, op,0); 227 insert_ob_in_map (newob, temp->map, op, 0);
210 } 228 }
211 leveldead=temp->level; 229 leveldead = temp->level;
212 remove_ob(temp); 230 remove_ob (temp);
213 free_object(temp); 231 free_object (temp);
214 } 232 }
215 233
216 if(resurrection_fails(clevel,leveldead)) { 234 if (resurrection_fails (clevel, leveldead))
235 {
217 if (spell->randomitems) { 236 if (spell->randomitems)
237 {
218 treasure *t; 238 treasure *t;
219 239
220 for (t=spell->randomitems->items; t; t=t->next) { 240 for (t = spell->randomitems->items; t; t = t->next)
241 {
221 summon_hostile_monsters(op, t->nrof, t->item->name); 242 summon_hostile_monsters (op, t->nrof, t->item->name);
243 }
244
245 }
246 return 1;
247
222 } 248 }
223 249 else
224 } 250 {
225 return 1;
226
227 } else {
228 return resurrect_player(op,name_to_resurrect,spell); 251 return resurrect_player (op, name_to_resurrect, spell);
229 } 252 }
230 253
231 return 1; 254 return 1;
232} 255}
233 256
234 257
258int
235int resurrection_fails(int levelcaster,int leveldead) 259resurrection_fails (int levelcaster, int leveldead)
236{ 260{
237 int chance=9; 261 int chance = 9;
262
238 /* scheme: equal in level, 50% success. 263 /* scheme: equal in level, 50% success.
239 * +5 % for each level below, -5% for each level above. 264 * +5 % for each level below, -5% for each level above.
240 * minimum 20% 265 * minimum 20%
241 */ 266 */
242 chance+=levelcaster-leveldead; 267 chance += levelcaster - leveldead;
243 if(chance<4) chance=4; 268 if (chance < 4)
244 if(chance>rndm(0, 19)) return 0; /* resurrection succeeds */ 269 chance = 4;
270 if (chance > rndm (0, 19))
271 return 0; /* resurrection succeeds */
245 return 1; 272 return 1;
246} 273}
247 274
275void
248void dead_player(object *op) 276dead_player (object *op)
249{ 277{
250 char filename[MAX_BUF]; 278 char filename[MAX_BUF];
251 char newname[MAX_BUF]; 279 char newname[MAX_BUF];
252 char path[MAX_BUF]; 280 char path[MAX_BUF];
253 281
254 /* set up our paths/strings... */ 282 /* set up our paths/strings... */
255 sprintf(path,"%s/%s/%s/%s",settings.localdir,settings.playerdir,op->name, 283 sprintf (path, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, &op->name);
256 op->name);
257 284
258 strcpy(filename,path); 285 strcpy (filename, path);
259 strcat(filename,".pl"); 286 strcat (filename, ".pl");
260 strcpy(newname,filename); 287 strcpy (newname, filename);
261 strcat(newname,".dead"); 288 strcat (newname, ".dead");
262 289
263 if(rename(filename,newname) != 0) { 290 if (rename (filename, newname) != 0)
291 {
264 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror_local(errno)); 292 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror (errno));
265 } 293 }
266} 294}
267 295
268 296
269 297
298void
270void dead_character(const char *name) { 299dead_character (const char *name)
300{
271 char buf[MAX_BUF]; 301 char buf[MAX_BUF];
272 char buf2[MAX_BUF]; 302 char buf2[MAX_BUF];
273 303
274 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);
275 /* peterm: create a .dead filename.... ***.pl.dead */ 305 /* peterm: create a .dead filename.... ***.pl.dead */
276 strcpy(buf2,buf); 306 strcpy (buf2, buf);
277 strcat(buf,".dead"); 307 strcat (buf, ".dead");
278 if(rename(buf2,buf)== -1){ 308 if (rename (buf2, buf) == -1)
309 {
279 LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror_local(errno)); 310 LOG (llevError, "Cannot rename dead player's file %s into %s: %s\n", buf2, buf, strerror (errno));
280 } 311 }
281} 312}
282 313
283 314
315int
284int dead_player_exists(const char *name) { 316dead_player_exists (const char *name)
317{
285 char buf[MAX_BUF]; 318 char buf[MAX_BUF];
286 319
287 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);
288 strcat(buf,".pl.dead"); 321 strcat (buf, ".pl.dead");
289 return !(access(buf,0)); 322 return !(access (buf, 0));
290} 323}
291
292

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines