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, 10 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

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * 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 *
14 * 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 *
19 * 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 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
24 */
25
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 #include <sproto.h>
31 #include <spells.h>
32 #include <errno.h>
33
34 /* name of the person to resurrect and which spell was used
35 * to resurrect
36 */
37 static int
38 resurrect_player (object *op, char *playername, object *spell)
39 {
40 FILE *deadplayer, *liveplayer;
41
42 char oldname[MAX_BUF];
43 char newname[MAX_BUF];
44 char path[8192];
45 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 treasurelist *tl = treasurelist::find (spell->race);
55 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
64 value = rndm (tl->total_chance);
65
66 for (t = tl->items; t; t = t->next)
67 {
68 value -= t->chance;
69 if (value < 0)
70 break;
71 }
72
73 if (!t || !t->item)
74 {
75 LOG (llevError, "resurrect_player: got null treasure from treasurelist %s!\n", &spell->race);
76 return 0;
77 }
78
79 race = t->item->archname;
80 }
81
82 /* set up our paths/strings... */
83 snprintf (path, sizeof (path), "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername);
84
85 strcpy (newname, path);
86 strcat (newname, ".pl");
87
88 strcpy (oldname, newname);
89 strcat (oldname, ".dead");
90
91 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 sscanf (buf, "%255s", buf2);
116 if (!(strcmp (buf2, "exp")))
117 {
118 sscanf (buf, "%255s %" SCNd64, buf2, &exp);
119 if (spell->stats.exp)
120 {
121 exp -= exp / spell->stats.exp;
122 sprintf (buf, "exp %" PRId64 "\n", exp);
123 }
124 }
125 if (!(strcmp (buf2, "Con")))
126 {
127 sscanf (buf, "%255s %d", buf2, &Con);
128 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
144 return 1;
145 }
146
147 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
165 /* raise_dead by peterm and mehlhaff@soda.berkeley.edu
166 * op -- who is doing the resurrecting
167 * spell - spell object
168 * dir -- direction the spell is cast
169 * corpseobj - corpse to raise - can be null, in which case this function will find it
170 */
171 int
172 cast_raise_dead_spell (object *op, object *caster, object *spell, int dir, const char *arg)
173 {
174 object *temp, *newob;
175 char name_to_resurrect[MAX_BUF];
176 int leveldead = 25, mflags, clevel;
177 sint16 sx, sy;
178 maptile *m;
179
180 clevel = casting_level (caster, spell);
181
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 }
189 strcpy (name_to_resurrect, arg);
190 temp = NULL;
191 }
192 else
193 {
194 sx = op->x + DIRX (dir);
195 sy = op->y + DIRY (dir);
196 m = op->map;
197 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
198 if (mflags & P_OUT_OF_MAP)
199 temp = NULL;
200 else
201 {
202 /* First we need to find a corpse, if any. */
203 /* If no object, temp will be set to NULL */
204 for (temp = GET_MAP_OB (m, sx, sy); temp != NULL; temp = temp->above)
205 /* 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
218 /* no matter what, we fry the corpse. */
219 if (temp && temp->map)
220 {
221 /* replace corpse object with a burning object */
222 newob = archetype::get (shstr_burnout);
223 if (newob)
224 newob->insert_at (temp, op);
225
226 leveldead = temp->level;
227 temp->destroy ();
228 }
229
230 if (resurrection_fails (clevel, leveldead))
231 {
232 if (spell->randomitems)
233 for (treasure *t = spell->randomitems->items; t; t = t->next)
234 if (t->item)
235 summon_hostile_monsters (op, t->nrof, t->item->archname);
236
237 return 1;
238
239 }
240 else
241 return resurrect_player (op, name_to_resurrect, spell);
242 }
243