1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
21 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <funcpoint.h> |
|
|
27 | |
25 | |
28 | /* Determine if the attacktype represented by the |
26 | /* Determine if the attacktype represented by the |
29 | * specified attack-number is enabled for dragon players. |
27 | * specified attack-number is enabled for dragon players. |
30 | * A dragon player (quetzal) can gain resistances for |
28 | * A dragon player (quetzal) can gain resistances for |
31 | * all enabled attacktypes. |
29 | * all enabled attacktypes. |
… | |
… | |
45 | * of the dragon race. |
43 | * of the dragon race. |
46 | */ |
44 | */ |
47 | int |
45 | int |
48 | is_dragon_pl (const object *op) |
46 | is_dragon_pl (const object *op) |
49 | { |
47 | { |
50 | if (op != NULL && op->type == PLAYER && op->arch != NULL && op->arch->clone.race != NULL && strcmp (op->arch->clone.race, "dragon") == 0) |
48 | if (op |
|
|
49 | && op->type == PLAYER |
|
|
50 | && op->arch |
|
|
51 | && op->arch->race |
|
|
52 | && !strcmp (op->arch->race, "dragon")) |
51 | return 1; |
53 | return 1; |
|
|
54 | |
52 | return 0; |
55 | return 0; |
53 | } |
56 | } |
|
|
57 | |
|
|
58 | /* |
|
|
59 | * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory |
|
|
60 | */ |
|
|
61 | bool |
|
|
62 | player::save_pl (object_freezer &freezer) |
|
|
63 | { |
|
|
64 | INVOKE_PLAYER (SAVE, ob->contr); |
|
|
65 | |
|
|
66 | int wiz = ob->flag [FLAG_WIZ]; |
|
|
67 | |
|
|
68 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
|
|
69 | object *container = ob->container; |
|
|
70 | ob->container = 0; |
|
|
71 | |
|
|
72 | if (ob->map) |
|
|
73 | maplevel = ob->map->path; |
|
|
74 | |
|
|
75 | #define PL_OUT(k) freezer.put (KW_ ## k, k) |
|
|
76 | #define PL_OUT2(k,v) freezer.put (KW_ ## k, v) |
|
|
77 | |
|
|
78 | PL_OUT (password); |
|
|
79 | PL_OUT2 (title, own_title); |
|
|
80 | PL_OUT (gender); |
|
|
81 | PL_OUT (hintmode); |
|
|
82 | PL_OUT (gen_hp); |
|
|
83 | PL_OUT (gen_sp); |
|
|
84 | PL_OUT (gen_grace); |
|
|
85 | PL_OUT (bowtype); |
|
|
86 | PL_OUT (petmode); |
|
|
87 | PL_OUT (peaceful); |
|
|
88 | PL_OUT (digestion); |
|
|
89 | PL_OUT2 (pickup, mode); |
|
|
90 | PL_OUT (outputs_sync); |
|
|
91 | PL_OUT (outputs_count); |
|
|
92 | |
|
|
93 | freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers")); |
|
|
94 | freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
|
|
95 | |
|
|
96 | PL_OUT2 (map, maplevel); |
|
|
97 | PL_OUT (savebed_map); |
|
|
98 | PL_OUT (bed_x); |
|
|
99 | PL_OUT (bed_y); |
|
|
100 | PL_OUT (weapon_sp); |
|
|
101 | PL_OUT (weapon_sp_left); |
|
|
102 | PL_OUT2 (Str, orig_stats.Str); |
|
|
103 | PL_OUT2 (Dex, orig_stats.Dex); |
|
|
104 | PL_OUT2 (Con, orig_stats.Con); |
|
|
105 | PL_OUT2 (Int, orig_stats.Int); |
|
|
106 | PL_OUT2 (Pow, orig_stats.Pow); |
|
|
107 | PL_OUT2 (Wis, orig_stats.Wis); |
|
|
108 | PL_OUT2 (Cha, orig_stats.Cha); |
|
|
109 | |
|
|
110 | PL_OUT2 (lev_array, 10); |
|
|
111 | |
|
|
112 | for (int i = 1; i <= 10; i++) |
|
|
113 | { |
|
|
114 | freezer.add (levhp [i]); freezer.add ('\n'); |
|
|
115 | freezer.add (levsp [i]); freezer.add ('\n'); |
|
|
116 | freezer.add (levgrace[i]); freezer.add ('\n'); |
|
|
117 | } |
|
|
118 | |
|
|
119 | freezer.put (ob->contr); |
|
|
120 | freezer.put (KW_endplst); |
|
|
121 | |
|
|
122 | SET_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
123 | CLEAR_FLAG (ob, FLAG_WIZ); |
|
|
124 | ob->write (freezer); |
|
|
125 | |
|
|
126 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
127 | |
|
|
128 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
|
|
129 | ob->container = container; |
|
|
130 | |
|
|
131 | ob->flag [FLAG_WIZ] = wiz; |
|
|
132 | |
|
|
133 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
|
|
134 | |
|
|
135 | return true; |
|
|
136 | } |
|
|
137 | |
|
|
138 | bool |
|
|
139 | player::save_pl (const char *path) |
|
|
140 | { |
|
|
141 | object_freezer freezer; |
|
|
142 | |
|
|
143 | if (!save_pl (freezer)) |
|
|
144 | return false; |
|
|
145 | |
|
|
146 | return freezer.save (path); |
|
|
147 | } |
|
|
148 | |
|
|
149 | player * |
|
|
150 | player::load_pl (object_thawer &f) |
|
|
151 | { |
|
|
152 | int maxerrs = 20; |
|
|
153 | |
|
|
154 | player *pl = new player; |
|
|
155 | |
|
|
156 | pl->savebed_map = first_map_path; |
|
|
157 | |
|
|
158 | /* Loop through the file, loading the rest of the values */ |
|
|
159 | for (;;) |
|
|
160 | { |
|
|
161 | switch (f.kw) |
|
|
162 | { |
|
|
163 | case KW_EOF: |
|
|
164 | LOG (llevError, "%s: unexpected EOF while reading player header\n", f.name); |
|
|
165 | goto failure; |
|
|
166 | |
|
|
167 | default: |
|
|
168 | LOG (llevError, "%s: skipping unknown key in player header: %s\n", f.name, f.kw_str); |
|
|
169 | if (!--maxerrs) goto failure; |
|
|
170 | break; |
|
|
171 | |
|
|
172 | case KW_ERROR: |
|
|
173 | LOG (llevError, "%s: parse error while reading player header, skipping (%s,%s).\n", f.name, f.kw_str, f.value); |
|
|
174 | if (!--maxerrs) goto failure; |
|
|
175 | break; |
|
|
176 | |
|
|
177 | case KW_endplst: |
|
|
178 | f.next (); |
|
|
179 | |
|
|
180 | if (object *op = pl->ob->read (f)) |
|
|
181 | pl->set_object (op); |
|
|
182 | else |
|
|
183 | goto failure; |
|
|
184 | |
|
|
185 | INVOKE_PLAYER (LOAD, pl); |
|
|
186 | |
|
|
187 | return pl; |
|
|
188 | |
|
|
189 | case KW_oid: f.get (pl, f.get_sint32 ()); break; |
|
|
190 | case KW_password: assign (pl->password , f.get_str ()); break; |
|
|
191 | case KW_title: assign (pl->own_title, f.get_str ()); break; |
|
|
192 | case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; |
|
|
193 | case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; |
|
|
194 | case KW_gender: f.get (pl->gender); break; |
|
|
195 | case KW_hintmode: f.get (pl->hintmode); break; |
|
|
196 | case KW_listening: /*TODO*/; break; |
|
|
197 | case KW_peaceful: f.get (pl->peaceful); break; |
|
|
198 | case KW_digestion: f.get (pl->digestion); break; |
|
|
199 | case KW_pickup: f.get (pl->mode); break; |
|
|
200 | case KW_outputs_sync: f.get (pl->outputs_sync); break; |
|
|
201 | case KW_outputs_count: f.get (pl->outputs_count); break; |
|
|
202 | case KW_map: f.get (pl->maplevel); break; |
|
|
203 | case KW_savebed_map: f.get (pl->savebed_map); break; |
|
|
204 | case KW_bed_x: f.get (pl->bed_x); break; |
|
|
205 | case KW_bed_y: f.get (pl->bed_y); break; |
|
|
206 | case KW_weapon_sp: f.get (pl->weapon_sp); break; |
|
|
207 | case KW_weapon_sp_left:f.get (pl->weapon_sp_left); break; |
|
|
208 | case KW_Str: f.get (pl->orig_stats.Str); break; |
|
|
209 | case KW_Dex: f.get (pl->orig_stats.Dex); break; |
|
|
210 | case KW_Con: f.get (pl->orig_stats.Con); break; |
|
|
211 | case KW_Int: f.get (pl->orig_stats.Int); break; |
|
|
212 | case KW_Pow: f.get (pl->orig_stats.Pow); break; |
|
|
213 | case KW_Wis: f.get (pl->orig_stats.Wis); break; |
|
|
214 | case KW_Cha: f.get (pl->orig_stats.Cha); break; |
|
|
215 | case KW_gen_hp: f.get (pl->gen_hp); break; |
|
|
216 | case KW_gen_sp: f.get (pl->gen_sp); break; |
|
|
217 | case KW_gen_grace: f.get (pl->gen_grace); break; |
|
|
218 | |
|
|
219 | case KW_usekeys: |
|
|
220 | if (!strcmp (f.get_str (), "key_inventory")) |
|
|
221 | pl->usekeys = key_inventory; |
|
|
222 | else if (!strcmp (f.get_str (), "keyrings")) |
|
|
223 | pl->usekeys = keyrings; |
|
|
224 | else if (!strcmp (f.get_str (), "containers")) |
|
|
225 | pl->usekeys = containers; |
|
|
226 | else |
|
|
227 | LOG (llevDebug, "load_player: got unknown usekeys type: %s\n", f.get_str ()); |
|
|
228 | break; |
|
|
229 | |
|
|
230 | case KW_unapply: |
|
|
231 | if (!strcmp (f.get_str (), "unapply_nochoice")) |
|
|
232 | pl->unapply = unapply_nochoice; |
|
|
233 | else if (!strcmp (f.get_str (), "unapply_never")) |
|
|
234 | pl->unapply = unapply_never; |
|
|
235 | else if (!strcmp (f.get_str (), "unapply_always")) |
|
|
236 | pl->unapply = unapply_always; |
|
|
237 | else |
|
|
238 | LOG (llevDebug, "load_player: got unknown unapply type: %s\n", f.get_str ()); |
|
|
239 | break; |
|
|
240 | |
|
|
241 | case KW_lev_array: |
|
|
242 | { |
|
|
243 | int count = f.get_sint32 (); |
|
|
244 | |
|
|
245 | for (int i = 1; i <= count; i++) |
|
|
246 | { |
|
|
247 | char line [32]; |
|
|
248 | |
|
|
249 | fgets (line, 32, f); pl->levhp [i] = atoi (line); |
|
|
250 | fgets (line, 32, f); pl->levsp [i] = atoi (line); |
|
|
251 | fgets (line, 32, f); pl->levgrace[i] = atoi (line); |
|
|
252 | } |
|
|
253 | } |
|
|
254 | break; |
|
|
255 | } |
|
|
256 | |
|
|
257 | f.next (); |
|
|
258 | } |
|
|
259 | |
|
|
260 | failure: |
|
|
261 | LOG (llevError, "%s: too many or too grave errors, aborting player load.\n", f.name); |
|
|
262 | |
|
|
263 | if (pl->ob) |
|
|
264 | pl->ob->destroy (); |
|
|
265 | |
|
|
266 | pl->destroy (); |
|
|
267 | |
|
|
268 | return 0; |
|
|
269 | } |
|
|
270 | |
|
|
271 | const char * |
|
|
272 | player::killer_name () const |
|
|
273 | { |
|
|
274 | static char buf [2048]; |
|
|
275 | |
|
|
276 | if (!killer) |
|
|
277 | return "a dungeon collapse"; |
|
|
278 | else if (killer->contr) |
|
|
279 | snprintf (buf, sizeof (buf), "%s the %s", &killer->name, |
|
|
280 | *killer->contr->own_title ? killer->contr->own_title : killer->contr->title); |
|
|
281 | else if (killer->type == DEEP_SWAMP) |
|
|
282 | snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name); |
|
|
283 | else if (killer->owner) |
|
|
284 | snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name); |
|
|
285 | else |
|
|
286 | return &killer->name; |
|
|
287 | |
|
|
288 | return buf; |
|
|
289 | } |
|
|
290 | |
|
|
291 | // expand one level of cfpod |
|
|
292 | // end == -1, till eos |
|
|
293 | // end == 0, one level of '>' |
|
|
294 | // end >= 1, this many levels of " >>>" |
|
|
295 | static const char * |
|
|
296 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) |
|
|
297 | { |
|
|
298 | static dynbuf_text nest(128, 128); |
|
|
299 | |
|
|
300 | for (;;) |
|
|
301 | switch (char ch = *cfpod++) |
|
|
302 | { |
|
|
303 | case 0: |
|
|
304 | return cfpod - 1; |
|
|
305 | |
|
|
306 | case ' ': |
|
|
307 | if (end <= 0) |
|
|
308 | goto passthrough; |
|
|
309 | |
|
|
310 | for (int i = 0; i < end; ++i) |
|
|
311 | if (cfpod [i] != '>') |
|
|
312 | goto passthrough; |
|
|
313 | |
|
|
314 | return cfpod + end; |
|
|
315 | |
|
|
316 | case '>': |
|
|
317 | if (end) |
|
|
318 | { |
|
|
319 | buf << ">"; |
|
|
320 | break; |
|
|
321 | } |
|
|
322 | |
|
|
323 | return cfpod; |
|
|
324 | |
|
|
325 | case '&': |
|
|
326 | buf << "&"; |
|
|
327 | break; |
|
|
328 | |
|
|
329 | case '<': |
|
|
330 | buf << "<"; |
|
|
331 | break; |
|
|
332 | |
|
|
333 | case '\n': |
|
|
334 | if (*cfpod == ' ') |
|
|
335 | goto passthrough; |
|
|
336 | else if (*cfpod == '\n') |
|
|
337 | { |
|
|
338 | --cfpod; |
|
|
339 | while (*cfpod == '\n') |
|
|
340 | buf << *cfpod++; |
|
|
341 | |
|
|
342 | goto skip; |
|
|
343 | } |
|
|
344 | |
|
|
345 | buf << ' '; |
|
|
346 | break; |
|
|
347 | |
|
|
348 | case 'B': case 'C': case 'E': case 'G': |
|
|
349 | case 'H': case 'I': case 'T': case 'U': |
|
|
350 | case 'Z': |
|
|
351 | { |
|
|
352 | int len = 0; |
|
|
353 | |
|
|
354 | while (cfpod [len] == '<') |
|
|
355 | ++len; |
|
|
356 | |
|
|
357 | if (!len) |
|
|
358 | goto passthrough; |
|
|
359 | |
|
|
360 | if (len == 1 || cfpod [len] != ' ') |
|
|
361 | { |
|
|
362 | len = 0; |
|
|
363 | ++cfpod; |
|
|
364 | } |
|
|
365 | else |
|
|
366 | cfpod += len + 1; |
|
|
367 | |
|
|
368 | const char *pfx, *sfx; |
|
|
369 | |
|
|
370 | switch (ch) |
|
|
371 | { |
|
|
372 | case 'B': pfx = "<b>" ; sfx = "</b>" ; break; |
|
|
373 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
|
|
374 | case 'E': pfx = "&" ; sfx = ";" ; break; |
|
|
375 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
|
|
376 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
|
|
377 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
|
|
378 | |
|
|
379 | case 'H': // hint |
|
|
380 | { |
|
|
381 | if (pl->hintmode) |
|
|
382 | { |
|
|
383 | cfpod = expand_cfpod (pl, nest, cfpod, len); |
|
|
384 | nest.clear (); |
|
|
385 | |
|
|
386 | if (pl->hintmode == 1) |
|
|
387 | buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; |
|
|
388 | else |
|
|
389 | while (*cfpod == ' ') // eat trailing whitespace |
|
|
390 | ++cfpod; |
|
|
391 | |
|
|
392 | goto skip; |
|
|
393 | } |
|
|
394 | else |
|
|
395 | { |
|
|
396 | pfx = "<fg name=\"lightblue\">["; |
|
|
397 | sfx = " (Use hintmode to suppress hints)]</fg>"; |
|
|
398 | } |
|
|
399 | } |
|
|
400 | break; |
|
|
401 | |
|
|
402 | case 'G': // gender |
|
|
403 | { |
|
|
404 | expand_cfpod (pl, nest, cfpod, len); |
|
|
405 | nest << '\0'; // zero-terminate |
|
|
406 | |
|
|
407 | const char *str = nest.linearise (); |
|
|
408 | const char *sep = strchr (str, '|'); |
|
|
409 | |
|
|
410 | if (sep) |
|
|
411 | { |
|
|
412 | if (pl->gender || 1) |
|
|
413 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
|
|
414 | else |
|
|
415 | buf.add (str, sep - str); |
|
|
416 | } |
|
|
417 | |
|
|
418 | nest.clear (); |
|
|
419 | |
|
|
420 | goto skip; |
|
|
421 | } |
|
|
422 | } |
|
|
423 | |
|
|
424 | buf << pfx; |
|
|
425 | cfpod = expand_cfpod (pl, buf, cfpod, len); |
|
|
426 | buf << sfx; |
|
|
427 | } |
|
|
428 | |
|
|
429 | break; |
|
|
430 | |
|
|
431 | default: |
|
|
432 | passthrough: |
|
|
433 | buf << ch; |
|
|
434 | skip: |
|
|
435 | break; |
|
|
436 | } |
|
|
437 | } |
|
|
438 | |
|
|
439 | dynbuf_text * |
|
|
440 | player::expand_cfpod (const char *cfpod) const |
|
|
441 | { |
|
|
442 | static dynbuf_text buf(1024, 1024); |
|
|
443 | buf.clear (); |
|
|
444 | |
|
|
445 | ::expand_cfpod (this, buf, cfpod, -1); |
|
|
446 | |
|
|
447 | return &buf; |
|
|
448 | } |
|
|
449 | |