… | |
… | |
47 | int |
47 | int |
48 | is_dragon_pl (const object *op) |
48 | is_dragon_pl (const object *op) |
49 | { |
49 | { |
50 | if (op != NULL && op->type == PLAYER && op->arch != NULL && op->arch->clone.race != NULL && strcmp (op->arch->clone.race, "dragon") == 0) |
50 | if (op != NULL && op->type == PLAYER && op->arch != NULL && op->arch->clone.race != NULL && strcmp (op->arch->clone.race, "dragon") == 0) |
51 | return 1; |
51 | return 1; |
|
|
52 | |
52 | return 0; |
53 | return 0; |
53 | } |
54 | } |
54 | |
55 | |
55 | /* |
56 | /* |
56 | * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory |
57 | * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory |
… | |
… | |
82 | PL_OUT (digestion); |
83 | PL_OUT (digestion); |
83 | PL_OUT2 (pickup, mode); |
84 | PL_OUT2 (pickup, mode); |
84 | PL_OUT (outputs_sync); |
85 | PL_OUT (outputs_sync); |
85 | PL_OUT (outputs_count); |
86 | PL_OUT (outputs_count); |
86 | |
87 | |
87 | freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers")); |
88 | freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers")); |
88 | freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
89 | freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
89 | |
90 | |
90 | if (ob->map) PL_OUT2 (map, ob->map->path); |
91 | PL_OUT2 (map, maplevel); |
91 | |
|
|
92 | PL_OUT (savebed_map); |
92 | PL_OUT (savebed_map); |
93 | PL_OUT (bed_x); |
93 | PL_OUT (bed_x); |
94 | PL_OUT (bed_y); |
94 | PL_OUT (bed_y); |
95 | PL_OUT (weapon_sp); |
95 | PL_OUT (weapon_sp); |
96 | PL_OUT2 (Str, orig_stats.Str); |
96 | PL_OUT2 (Str, orig_stats.Str); |
… | |
… | |
141 | } |
141 | } |
142 | |
142 | |
143 | player * |
143 | player * |
144 | player::load_pl (object_thawer &thawer) |
144 | player::load_pl (object_thawer &thawer) |
145 | { |
145 | { |
|
|
146 | int maxerrs = 10; |
|
|
147 | |
146 | player *pl = new player; |
148 | player *pl = new player; |
147 | |
149 | |
148 | pl->savebed_map = first_map_path; |
150 | pl->savebed_map = first_map_path; |
|
|
151 | |
|
|
152 | /* this loads the standard objects values. */ |
|
|
153 | pl->set_object (object::create ()); |
149 | |
154 | |
150 | /* Loop through the file, loading the rest of the values */ |
155 | /* Loop through the file, loading the rest of the values */ |
151 | for (;;) |
156 | for (;;) |
152 | { |
157 | { |
153 | keyword kw = thawer.get_kv (); |
158 | keyword kw = thawer.get_kv (); |
154 | |
159 | |
155 | switch (kw) |
160 | switch (kw) |
156 | { |
161 | { |
157 | case KW_EOF: |
162 | case KW_EOF: |
158 | LOG (llevError, "%s: unexpected EOF while reading player header\n", thawer.name); |
163 | LOG (llevError, "%s: unexpected EOF while reading player header\n", thawer.name); |
159 | delete pl; |
164 | goto failure; |
|
|
165 | |
|
|
166 | default: |
|
|
167 | LOG (llevError, "%s: skipping unknown key in player header: %s\n", thawer.name, keyword_str [kw]); |
|
|
168 | if (!--maxerrs) goto failure; |
160 | return 0; |
169 | break; |
161 | |
170 | |
162 | case KW_ERROR: |
171 | case KW_ERROR: |
163 | LOG (llevError, "%s: error while reading player header, skipping (%s,%s)\n", thawer.name, thawer.last_keyword, thawer.last_value); |
172 | LOG (llevError, "%s: parse error while reading player header, skipping (%s,%s).\n", thawer.name, thawer.last_keyword, thawer.last_value); |
|
|
173 | if (!--maxerrs) goto failure; |
164 | break; |
174 | break; |
165 | |
175 | |
166 | case KW_endplst: |
176 | case KW_endplst: |
167 | goto done; |
177 | goto done; |
168 | |
178 | |
… | |
… | |
220 | { |
230 | { |
221 | int count = thawer.get_sint32 (); |
231 | int count = thawer.get_sint32 (); |
222 | |
232 | |
223 | for (int i = 1; i <= count; i++) |
233 | for (int i = 1; i <= count; i++) |
224 | { |
234 | { |
225 | char line[128]; |
235 | char line [32]; |
226 | |
236 | |
227 | fgets (line, 128, thawer); pl->levhp [i] = atoi (line); |
237 | fgets (line, 32, thawer); pl->levhp [i] = atoi (line); |
228 | fgets (line, 128, thawer); pl->levsp [i] = atoi (line); |
238 | fgets (line, 32, thawer); pl->levsp [i] = atoi (line); |
229 | fgets (line, 128, thawer); pl->levgrace[i] = atoi (line); |
239 | fgets (line, 32, thawer); pl->levgrace[i] = atoi (line); |
230 | } |
240 | } |
231 | } |
241 | } |
232 | break; |
242 | break; |
233 | |
|
|
234 | default: |
|
|
235 | LOG (llevError, "%s: skipping unknown key in player header: %s\n", thawer.name, keyword_str [kw]); |
|
|
236 | break; |
|
|
237 | } |
243 | } |
238 | } |
244 | } |
239 | |
245 | |
240 | done: |
246 | done: |
241 | /* this loads the standard objects values. */ |
|
|
242 | pl->set_object (object::create ()); |
|
|
243 | |
|
|
244 | if (!load_object (thawer, pl->ob, 0)) |
247 | if (!load_object (thawer, pl->ob, 0)) |
245 | { |
248 | { |
246 | pl->ob->destroy (); |
249 | pl->ob->destroy (); |
247 | delete pl; |
250 | pl->destroy (); |
248 | return 0; |
251 | return 0; |
249 | } |
252 | } |
250 | |
253 | |
251 | INVOKE_PLAYER (LOAD, pl); |
254 | INVOKE_PLAYER (LOAD, pl); |
252 | |
255 | |
253 | return pl; |
256 | return pl; |
|
|
257 | |
|
|
258 | failure: |
|
|
259 | LOG (llevError, "%s: too many or too grave errors, aborting player load.\n", thawer.name); |
|
|
260 | |
|
|
261 | pl->ob->destroy (); |
|
|
262 | pl->destroy (); |
|
|
263 | |
|
|
264 | return 0; |
254 | } |
265 | } |
255 | |
266 | |
256 | player * |
267 | player * |
257 | player::load_pl (const char *path) |
268 | player::load_pl (const char *path) |
258 | { |
269 | { |