… | |
… | |
28 | #include <define.h> |
28 | #include <define.h> |
29 | |
29 | |
30 | extern void sub_weight (object *, signed long); |
30 | extern void sub_weight (object *, signed long); |
31 | extern void add_weight (object *, signed long); |
31 | extern void add_weight (object *, signed long); |
32 | extern long pticks; |
32 | extern long pticks; |
33 | |
|
|
34 | /* If flag is non zero, it means that we want to try and save everyone, but |
|
|
35 | * keep the game running. Thus, we don't want to free any information. |
|
|
36 | */ |
|
|
37 | void |
|
|
38 | emergency_save (int flag) |
|
|
39 | { |
|
|
40 | player *pl; |
|
|
41 | |
|
|
42 | trying_emergency_save = 1; |
|
|
43 | |
|
|
44 | LOG (llevError, "Emergency save: "); |
|
|
45 | for (pl = first_player; pl != NULL; pl = pl->next) |
|
|
46 | { |
|
|
47 | if (!pl->ob) |
|
|
48 | { |
|
|
49 | LOG (llevError, "No name, ignoring this.\n"); |
|
|
50 | continue; |
|
|
51 | } |
|
|
52 | |
|
|
53 | LOG (llevError, "%s ", &pl->ob->name); |
|
|
54 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Emergency save..."); |
|
|
55 | |
|
|
56 | /* If we are not exiting the game (ie, this is sort of a backup save), then |
|
|
57 | * don't change the location back to the village. Note that there are other |
|
|
58 | * options to have backup saves be done at the starting village |
|
|
59 | */ |
|
|
60 | if (!flag) |
|
|
61 | { |
|
|
62 | strcpy (pl->maplevel, first_map_path); |
|
|
63 | |
|
|
64 | if (pl->ob->map != NULL) |
|
|
65 | pl->ob->map = NULL; |
|
|
66 | |
|
|
67 | pl->ob->x = -1; |
|
|
68 | pl->ob->y = -1; |
|
|
69 | } |
|
|
70 | |
|
|
71 | pl->save (1); |
|
|
72 | } |
|
|
73 | |
|
|
74 | LOG (llevError, "\n"); |
|
|
75 | } |
|
|
76 | |
33 | |
77 | /* Delete character with name. if new is set, also delete the new |
34 | /* Delete character with name. if new is set, also delete the new |
78 | * style directory, otherwise, just delete the old style playfile |
35 | * style directory, otherwise, just delete the old style playfile |
79 | * (needed for transition) |
36 | * (needed for transition) |
80 | */ |
37 | */ |
… | |
… | |
135 | |
92 | |
136 | INVOKE_PLAYER (SAVE, ob->contr); |
93 | INVOKE_PLAYER (SAVE, ob->contr); |
137 | |
94 | |
138 | object_freezer freezer; |
95 | object_freezer freezer; |
139 | |
96 | |
140 | int wiz = ob->flags [FLAG_WIZ]; |
97 | int wiz = ob->flag [FLAG_WIZ]; |
141 | |
98 | |
142 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
99 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
143 | container = ob->container; |
100 | container = ob->container; |
144 | ob->container = 0; |
101 | ob->container = 0; |
145 | |
102 | |
… | |
… | |
166 | /* Match the enumerations but in string form */ |
123 | /* Match the enumerations but in string form */ |
167 | fprintf (freezer, "unapply %s\n", unapply == unapply_nochoice ? "unapply_nochoice" : |
124 | fprintf (freezer, "unapply %s\n", unapply == unapply_nochoice ? "unapply_nochoice" : |
168 | (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
125 | (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
169 | |
126 | |
170 | if (ob->map) |
127 | if (ob->map) |
171 | fprintf (freezer, "map %s\n", ob->map->path); |
128 | fprintf (freezer, "map %s\n", &ob->map->path); |
172 | else |
|
|
173 | fprintf (freezer, "map %s\n", settings.emergency_mapname); |
|
|
174 | |
129 | |
175 | fprintf (freezer, "savebed_map %s\n", savebed_map); |
130 | fprintf (freezer, "savebed_map %s\n", savebed_map); |
176 | fprintf (freezer, "bed_x %d\nbed_y %d\n", bed_x, bed_y); |
131 | fprintf (freezer, "bed_x %d\nbed_y %d\n", bed_x, bed_y); |
177 | fprintf (freezer, "weapon_sp %f\n", weapon_sp); |
132 | fprintf (freezer, "weapon_sp %f\n", weapon_sp); |
178 | fprintf (freezer, "Str %d\n", orig_stats.Str); |
133 | fprintf (freezer, "Str %d\n", orig_stats.Str); |
… | |
… | |
196 | |
151 | |
197 | fprintf (freezer, "endplst\n"); |
152 | fprintf (freezer, "endplst\n"); |
198 | |
153 | |
199 | SET_FLAG (ob, FLAG_NO_FIX_PLAYER); |
154 | SET_FLAG (ob, FLAG_NO_FIX_PLAYER); |
200 | CLEAR_FLAG (ob, FLAG_WIZ); |
155 | CLEAR_FLAG (ob, FLAG_WIZ); |
201 | save_object (freezer, ob, 3); /* don't check and don't remove */ |
156 | save_object (freezer, ob, 1); /* don't check and don't remove */ |
202 | |
157 | |
203 | char filename[MAX_BUF]; |
158 | char filename[MAX_BUF]; |
204 | |
159 | |
205 | sprintf (filename, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, &ob->name, &ob->name); |
160 | sprintf (filename, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, &ob->name, &ob->name); |
206 | make_path_to_file (filename); |
161 | make_path_to_file (filename); |
… | |
… | |
209 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
164 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
210 | |
165 | |
211 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
166 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
212 | ob->container = container; |
167 | ob->container = container; |
213 | |
168 | |
214 | ob->flags [FLAG_WIZ] = wiz; |
169 | ob->flag [FLAG_WIZ] = wiz; |
215 | |
170 | |
216 | enable_save = !final; |
171 | enable_save = !final; |
217 | } |
172 | } |
218 | |
173 | |
219 | player * |
174 | player * |
… | |
… | |
232 | |
187 | |
233 | char buf[MAX_BUF], bufall[MAX_BUF]; |
188 | char buf[MAX_BUF], bufall[MAX_BUF]; |
234 | |
189 | |
235 | pl->set_object (object::create ()); |
190 | pl->set_object (object::create ()); |
236 | pl->last_save_time = time (0); |
191 | pl->last_save_time = time (0); |
237 | pl->name_changed = 1; |
|
|
238 | |
192 | |
239 | assign (pl->savebed_map, first_map_path); |
193 | assign (pl->savebed_map, first_map_path); |
240 | |
194 | |
241 | /* Loop through the file, loading the rest of the values */ |
195 | /* Loop through the file, loading the rest of the values */ |
242 | while (fgets (bufall, MAX_BUF, thawer)) |
196 | while (fgets (bufall, MAX_BUF, thawer)) |
… | |
… | |
347 | } |
301 | } |
348 | |
302 | |
349 | /* this loads the standard objects values. */ |
303 | /* this loads the standard objects values. */ |
350 | load_object (thawer, pl->ob, 0); |
304 | load_object (thawer, pl->ob, 0); |
351 | |
305 | |
352 | /* If the map where the person was last saved does not exist, |
|
|
353 | * restart them on their home-savebed. This is good for when |
|
|
354 | * maps change between versions |
|
|
355 | * First, we check for partial path, then check to see if the full |
|
|
356 | * path (for unique player maps) |
|
|
357 | */ |
|
|
358 | if (!has_been_loaded (pl->maplevel) |
|
|
359 | && check_path (pl->maplevel, 1) == -1 |
|
|
360 | && check_path (pl->maplevel, 0) == -1) |
|
|
361 | { |
|
|
362 | strcpy (pl->maplevel, pl->savebed_map); |
|
|
363 | pl->ob->x = pl->bed_x, pl->ob->y = pl->bed_y; |
|
|
364 | } |
|
|
365 | |
|
|
366 | /* make sure he's a player -- needed because of class change. */ |
|
|
367 | pl->name_changed = 1; |
|
|
368 | pl->last_save_tick = pticks; |
306 | pl->last_save_tick = pticks; |
369 | |
307 | |
370 | INVOKE_PLAYER (LOAD, pl, ARG_STRING (path)); |
308 | INVOKE_PLAYER (LOAD, pl, ARG_STRING (path)); |
371 | |
309 | |
372 | return pl; |
310 | return pl; |