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.9 by pippijn, Mon Dec 11 21:06:59 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines