ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/resurrection.C
Revision: 1.45
Committed: Wed Jun 26 06:52:41 2019 UTC (4 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.44: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.24 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.39 *
4 root 1.43 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.40 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.35 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.39 *
9 root 1.31 * Deliantra is free software: you can redistribute it and/or modify it under
10     * the terms of the Affero GNU General Public License as published by the
11     * Free Software Foundation, either version 3 of the License, or (at your
12     * option) any later version.
13 root 1.39 *
14 root 1.23 * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     * GNU General Public License for more details.
18 root 1.39 *
19 root 1.31 * You should have received a copy of the Affero GNU General Public License
20     * and the GNU General Public License along with this program. If not, see
21     * <http://www.gnu.org/licenses/>.
22 root 1.39 *
23 root 1.24 * The authors can be reached via e-mail to <support@deliantra.net>
24 pippijn 1.19 */
25 elmex 1.1
26     /* the contents of this file were create solely by peterm@soda.berkeley.edu
27     all of the above disclaimers apply. */
28    
29     #include <global.h>
30 root 1.14 #include <sproto.h>
31 elmex 1.1 #include <spells.h>
32     #include <errno.h>
33 root 1.5
34 elmex 1.1 /* name of the person to resurrect and which spell was used
35 root 1.41 * to resurrect
36 elmex 1.1 */
37 root 1.5 static int
38     resurrect_player (object *op, char *playername, object *spell)
39 elmex 1.1 {
40 root 1.5 FILE *deadplayer, *liveplayer;
41    
42     char oldname[MAX_BUF];
43     char newname[MAX_BUF];
44 root 1.45 char path[8192];
45 root 1.5 char buf[MAX_BUF];
46     char buf2[MAX_BUF];
47     const char *race = NULL;
48     sint64 exp;
49     int Con;
50    
51     /* reincarnation, which changes the race */
52     if (spell->race)
53     {
54 root 1.20 treasurelist *tl = treasurelist::find (spell->race);
55 root 1.5 treasure *t;
56     int value;
57    
58     if (!tl)
59     {
60     LOG (llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", &spell->race);
61     return 0;
62     }
63 root 1.20
64 root 1.30 value = rndm (tl->total_chance);
65 root 1.20
66 root 1.5 for (t = tl->items; t; t = t->next)
67     {
68     value -= t->chance;
69     if (value < 0)
70     break;
71     }
72 root 1.20
73 elmex 1.16 if (!t || !t->item)
74 root 1.5 {
75     LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race);
76     return 0;
77     }
78 root 1.20
79 root 1.22 race = t->item->archname;
80 root 1.5 }
81    
82     /* set up our paths/strings... */
83 root 1.45 snprintf (path, sizeof (path), "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername);
84 root 1.5
85     strcpy (newname, path);
86     strcat (newname, ".pl");
87    
88     strcpy (oldname, newname);
89     strcat (oldname, ".dead");
90 elmex 1.1
91 root 1.5 if (!(deadplayer = fopen (oldname, "r")))
92     {
93     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be reached.", playername);
94     return 0;
95     }
96    
97     if (!access (newname, 0))
98     {
99     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s has already been reborn!", playername);
100     fclose (deadplayer);
101     return 0;
102     }
103    
104     if (!(liveplayer = fopen (newname, "w")))
105     {
106     new_draw_info_format (NDI_UNIQUE, 0, op, "The soul of %s cannot be re-embodied at the moment.", playername);
107     LOG (llevError, "Cannot write player in resurrect_player!\n");
108     fclose (deadplayer);
109     return 0;
110     }
111    
112     while (!feof (deadplayer))
113     {
114     fgets (buf, 255, deadplayer);
115 root 1.44 sscanf (buf, "%255s", buf2);
116 root 1.5 if (!(strcmp (buf2, "exp")))
117     {
118 root 1.44 sscanf (buf, "%255s %" SCNd64, buf2, &exp);
119 root 1.5 if (spell->stats.exp)
120     {
121     exp -= exp / spell->stats.exp;
122 root 1.10 sprintf (buf, "exp %" PRId64 "\n", exp);
123 root 1.2 }
124     }
125 root 1.5 if (!(strcmp (buf2, "Con")))
126     {
127 root 1.44 sscanf (buf, "%255s %d", buf2, &Con);
128 root 1.5 Con -= spell->stats.Con;
129     if (Con < 1)
130     Con = 1;
131     sprintf (buf, "Con %d\n", Con);
132     }
133     if (race && !strcmp (buf2, "race"))
134     {
135     sprintf (buf, "race %s\n", race);
136     }
137     fputs (buf, liveplayer);
138     }
139     fclose (liveplayer);
140     fclose (deadplayer);
141     unlink (oldname);
142     new_draw_info_format (NDI_UNIQUE, 0, op, "%s lives again!", playername);
143 elmex 1.1
144 root 1.5 return 1;
145 elmex 1.1 }
146    
147 root 1.32 static int
148     resurrection_fails (int levelcaster, int leveldead)
149     {
150     int chance = 9;
151    
152     /* scheme: equal in level, 50% success.
153     * +5 % for each level below, -5% for each level above.
154     * minimum 20%
155     */
156     chance += levelcaster - leveldead;
157     if (chance < 4)
158     chance = 4;
159     if (chance > rndm (0, 19))
160     return 0; /* resurrection succeeds */
161     return 1;
162     }
163    
164 elmex 1.1
165     /* raise_dead by peterm and mehlhaff@soda.berkeley.edu
166     * op -- who is doing the resurrecting
167 root 1.41 * spell - spell object
168 elmex 1.1 * dir -- direction the spell is cast
169     * corpseobj - corpse to raise - can be null, in which case this function will find it
170     */
171 root 1.5 int
172     cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg)
173 elmex 1.1 {
174 root 1.5 object *temp, *newob;
175     char name_to_resurrect[MAX_BUF];
176     int leveldead = 25, mflags, clevel;
177     sint16 sx, sy;
178 root 1.8 maptile *m;
179 root 1.5
180 root 1.27 clevel = casting_level (caster, spell);
181 root 1.5
182     if (spell->last_heal)
183     {
184     if (!arg)
185     {
186     new_draw_info_format (NDI_UNIQUE, 0, op, "Cast %s on who?", &spell->name);
187     return 0;
188 root 1.2 }
189 root 1.5 strcpy (name_to_resurrect, arg);
190     temp = NULL;
191     }
192     else
193     {
194 root 1.42 sx = op->x + DIRX (dir);
195     sy = op->y + DIRY (dir);
196 root 1.5 m = op->map;
197     mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
198     if (mflags & P_OUT_OF_MAP)
199 root 1.2 temp = NULL;
200 root 1.5 else
201     {
202     /* First we need to find a corpse, if any. */
203     /* If no object, temp will be set to NULL */
204 root 1.13 for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above)
205 root 1.5 /* If it is corpse, this must be what we want to raise */
206     if (temp->type == CORPSE)
207     break;
208     }
209    
210     if (temp == NULL)
211     {
212     new_draw_info (NDI_UNIQUE, 0, op, "You need a body for this spell.");
213     return 0;
214     }
215     strcpy (name_to_resurrect, temp->name);
216     }
217 elmex 1.1
218 root 1.5 /* no matter what, we fry the corpse. */
219     if (temp && temp->map)
220     {
221     /* replace corpse object with a burning object */
222 root 1.25 newob = archetype::get (shstr_burnout);
223 root 1.15 if (newob)
224     newob->insert_at (temp, op);
225    
226 root 1.5 leveldead = temp->level;
227 root 1.29 temp->destroy ();
228 root 1.5 }
229    
230     if (resurrection_fails (clevel, leveldead))
231     {
232     if (spell->randomitems)
233 root 1.15 for (treasure *t = spell->randomitems->items; t; t = t->next)
234 elmex 1.16 if (t->item)
235 root 1.22 summon_hostile_monsters (op, t->nrof, t->item->archname);
236 elmex 1.1
237 root 1.5 return 1;
238 elmex 1.1
239 root 1.5 }
240     else
241 root 1.15 return resurrect_player (op, name_to_resurrect, spell);
242 elmex 1.1 }
243