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.4 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.10 by root, Mon Dec 11 21:32:18 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines