1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * 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 along |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <funcpoint.h> |
26 | |
|
|
27 | //+GPL |
27 | |
28 | |
28 | /* Determine if the attacktype represented by the |
29 | /* Determine if the attacktype represented by the |
29 | * specified attack-number is enabled for dragon players. |
30 | * specified attack-number is enabled for dragon players. |
30 | * A dragon player (quetzal) can gain resistances for |
31 | * A dragon player (quetzal) can gain resistances for |
31 | * all enabled attacktypes. |
32 | * all enabled attacktypes. |
… | |
… | |
39 | |
40 | |
40 | return 0; |
41 | return 0; |
41 | } |
42 | } |
42 | |
43 | |
43 | /* |
44 | /* |
44 | * returns true if the adressed object 'ob' is a player |
|
|
45 | * of the dragon race. |
|
|
46 | */ |
|
|
47 | int |
|
|
48 | is_dragon_pl (const object *op) |
|
|
49 | { |
|
|
50 | if (op |
|
|
51 | && op->type == PLAYER |
|
|
52 | && op->arch |
|
|
53 | && op->arch->race |
|
|
54 | && !strcmp (op->arch->race, "dragon")) |
|
|
55 | return 1; |
|
|
56 | |
|
|
57 | return 0; |
|
|
58 | } |
|
|
59 | |
|
|
60 | /* |
|
|
61 | * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory |
45 | * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory |
62 | */ |
46 | */ |
63 | bool |
47 | bool |
64 | player::save_pl (object_freezer &freezer) |
48 | player::save_pl (object_freezer &freezer) |
65 | { |
49 | { |
66 | INVOKE_PLAYER (SAVE, ob->contr); |
50 | INVOKE_PLAYER (SAVE, ob->contr); |
67 | |
51 | |
68 | int wiz = ob->flag [FLAG_WIZ]; |
52 | int wiz = ob->flag [FLAG_WIZ]; |
69 | |
53 | |
70 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
54 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
71 | object *container = ob->container; |
55 | object *container = ob->container_ (); |
72 | ob->container = 0; |
56 | ob->container = 0; |
73 | |
57 | |
74 | if (ob->map) |
58 | if (ob->map) |
75 | maplevel = ob->map->path; |
59 | maplevel = ob->map->path; |
76 | |
60 | |
77 | #define PL_OUT(k) freezer.put (KW_ ## k, k) |
61 | #define PL_OUT(k) freezer.put (KW(k), k) |
78 | #define PL_OUT2(k,v) freezer.put (KW_ ## k, v) |
62 | #define PL_OUT2(k,v) freezer.put (KW(k), v) |
79 | |
63 | |
80 | PL_OUT (password); |
64 | PL_OUT (password); |
81 | PL_OUT2 (title, own_title); |
65 | PL_OUT2 (title, own_title); |
82 | PL_OUT (gender); |
66 | PL_OUT (gender); |
|
|
67 | PL_OUT (hintmode); |
83 | PL_OUT (gen_hp); |
68 | PL_OUT (gen_hp); |
84 | PL_OUT (gen_sp); |
69 | PL_OUT (gen_sp); |
85 | PL_OUT (gen_grace); |
70 | PL_OUT (gen_grace); |
86 | PL_OUT (listening); |
|
|
87 | PL_OUT (bowtype); |
71 | PL_OUT (bowtype); |
88 | PL_OUT (petmode); |
72 | PL_OUT (petmode); |
89 | PL_OUT (peaceful); |
73 | PL_OUT (peaceful); |
90 | PL_OUT (digestion); |
74 | PL_OUT (digestion); |
91 | PL_OUT2 (pickup, mode); |
75 | PL_OUT2 (pickup, mode); |
92 | PL_OUT (outputs_sync); |
76 | PL_OUT (outputs_sync); |
93 | PL_OUT (outputs_count); |
77 | PL_OUT (outputs_count); |
94 | |
78 | |
95 | freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers")); |
79 | freezer.put (KW(usekeys), usekeys == key_inventory ? CS(key_inventory) : (usekeys == keyrings ? CS(keyrings) : CS(containers))); |
96 | freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always")); |
80 | freezer.put (KW(unapply), unapply == unapply_nochoice ? CS(unapply_nochoice) : (unapply == unapply_never ? CS(unapply_never) : CS(unapply_always))); |
97 | |
81 | |
98 | PL_OUT2 (map, maplevel); |
82 | PL_OUT2 (map, maplevel); |
99 | PL_OUT (savebed_map); |
83 | PL_OUT (savebed_map); |
100 | PL_OUT (bed_x); |
84 | PL_OUT (bed_x); |
101 | PL_OUT (bed_y); |
85 | PL_OUT (bed_y); |
… | |
… | |
117 | freezer.add (levsp [i]); freezer.add ('\n'); |
101 | freezer.add (levsp [i]); freezer.add ('\n'); |
118 | freezer.add (levgrace[i]); freezer.add ('\n'); |
102 | freezer.add (levgrace[i]); freezer.add ('\n'); |
119 | } |
103 | } |
120 | |
104 | |
121 | freezer.put (ob->contr); |
105 | freezer.put (ob->contr); |
122 | freezer.put (KW_endplst); |
106 | freezer.put (KW(endplst)); |
123 | |
107 | |
124 | SET_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
125 | CLEAR_FLAG (ob, FLAG_WIZ); |
108 | CLEAR_FLAG (ob, FLAG_WIZ); |
126 | ob->write (freezer); |
109 | ob->write (freezer); |
127 | |
110 | |
128 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
129 | |
|
|
130 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
111 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
131 | ob->container = container; |
112 | ob->container = container; |
132 | |
113 | |
133 | ob->flag [FLAG_WIZ] = wiz; |
114 | ob->flag [FLAG_WIZ] = wiz; |
134 | |
115 | |
135 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
116 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
136 | |
117 | |
137 | return true; |
118 | return true; |
138 | } |
119 | } |
|
|
120 | |
|
|
121 | //-GPL |
139 | |
122 | |
140 | bool |
123 | bool |
141 | player::save_pl (const char *path) |
124 | player::save_pl (const char *path) |
142 | { |
125 | { |
143 | object_freezer freezer; |
126 | object_freezer freezer; |
… | |
… | |
192 | case KW_password: assign (pl->password , f.get_str ()); break; |
175 | case KW_password: assign (pl->password , f.get_str ()); break; |
193 | case KW_title: assign (pl->own_title, f.get_str ()); break; |
176 | case KW_title: assign (pl->own_title, f.get_str ()); break; |
194 | case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; |
177 | case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; |
195 | case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; |
178 | case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; |
196 | case KW_gender: f.get (pl->gender); break; |
179 | case KW_gender: f.get (pl->gender); break; |
197 | case KW_listening: f.get (pl->listening); break; |
180 | case KW_hintmode: f.get (pl->hintmode); break; |
|
|
181 | case KW_listening: /*TODO*/; break; |
198 | case KW_peaceful: f.get (pl->peaceful); break; |
182 | case KW_peaceful: f.get (pl->peaceful); break; |
199 | case KW_digestion: f.get (pl->digestion); break; |
183 | case KW_digestion: f.get (pl->digestion); break; |
200 | case KW_pickup: f.get (pl->mode); break; |
184 | case KW_pickup: f.get (pl->mode); break; |
201 | case KW_outputs_sync: f.get (pl->outputs_sync); break; |
185 | case KW_outputs_sync: f.get (pl->outputs_sync); break; |
202 | case KW_outputs_count: f.get (pl->outputs_count); break; |
186 | case KW_outputs_count: f.get (pl->outputs_count); break; |
… | |
… | |
267 | pl->destroy (); |
251 | pl->destroy (); |
268 | |
252 | |
269 | return 0; |
253 | return 0; |
270 | } |
254 | } |
271 | |
255 | |
272 | player * |
256 | const_utf8_string |
273 | player::load_pl (const char *path) |
257 | player::killer_name () const |
274 | { |
258 | { |
275 | object_thawer f (path); |
259 | static char buf [2048]; |
276 | |
260 | |
277 | if (!f) |
261 | if (!killer) |
|
|
262 | return "a dungeon collapse"; |
|
|
263 | else if (killer->contr) |
|
|
264 | snprintf (buf, sizeof (buf), "%s the %s", &killer->name, |
|
|
265 | *killer->contr->own_title ? killer->contr->own_title : killer->contr->title); |
|
|
266 | else if (killer->type == DEEP_SWAMP) |
|
|
267 | snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name); |
|
|
268 | else if (killer->owner) |
|
|
269 | snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name); |
|
|
270 | else |
|
|
271 | return &killer->name; |
|
|
272 | |
278 | return 0; |
273 | return buf; |
279 | |
|
|
280 | f.next (); |
|
|
281 | |
|
|
282 | return load_pl (f); |
|
|
283 | } |
274 | } |
284 | |
275 | |
|
|
276 | // expand one level of cfpod |
|
|
277 | // end == -2, till '\n' |
|
|
278 | // end == -1, till '>' |
|
|
279 | // end == 0, till eos |
|
|
280 | // end >= 1, levels of " >>>" |
|
|
281 | static const char * |
|
|
282 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) |
|
|
283 | { |
|
|
284 | static dynbuf_text nest(128, 128); |
|
|
285 | |
|
|
286 | for (;;) |
|
|
287 | switch (char ch = *cfpod++) |
|
|
288 | { |
|
|
289 | case 0: |
|
|
290 | return cfpod - 1; |
|
|
291 | |
|
|
292 | case ' ': |
|
|
293 | // verbatim block? |
|
|
294 | if (!buf.size () && !end) |
|
|
295 | { |
|
|
296 | --cfpod; |
|
|
297 | goto verbatim; |
|
|
298 | } |
|
|
299 | |
|
|
300 | if (end < 1) |
|
|
301 | goto passthrough; |
|
|
302 | |
|
|
303 | for (int i = 0; i < end; ++i) |
|
|
304 | if (cfpod [i] != '>') |
|
|
305 | goto passthrough; |
|
|
306 | |
|
|
307 | return cfpod + end; |
|
|
308 | |
|
|
309 | case '>': |
|
|
310 | if (end != -1) |
|
|
311 | { |
|
|
312 | buf << ">"; |
|
|
313 | break; |
|
|
314 | } |
|
|
315 | |
|
|
316 | return cfpod; |
|
|
317 | |
|
|
318 | case '&': |
|
|
319 | buf << "&"; |
|
|
320 | break; |
|
|
321 | |
|
|
322 | case '<': |
|
|
323 | buf << "<"; |
|
|
324 | break; |
|
|
325 | |
|
|
326 | case '\r': |
|
|
327 | buf << '\n'; |
|
|
328 | /* \r\n+ becomes one or more newlines */ |
|
|
329 | while (*cfpod == '\n') |
|
|
330 | buf << *cfpod++; |
|
|
331 | break; |
|
|
332 | |
|
|
333 | case '\n': |
|
|
334 | if (end == -2) |
|
|
335 | return cfpod; |
|
|
336 | |
|
|
337 | // \n\ => newline, tt |
|
|
338 | // \n\n => \n\n |
|
|
339 | // \n => single space |
|
|
340 | |
|
|
341 | // two or more newlines will be copied verbatim, one is replaced by space |
|
|
342 | if (*cfpod == '\n') |
|
|
343 | { |
|
|
344 | --cfpod; |
|
|
345 | do |
|
|
346 | buf << *cfpod++; |
|
|
347 | while (*cfpod == '\n'); |
|
|
348 | } |
|
|
349 | else if (*cfpod == ' ') |
|
|
350 | buf << '\n'; |
|
|
351 | else |
|
|
352 | buf << ' '; |
|
|
353 | |
|
|
354 | // verbatim block? |
|
|
355 | if (*cfpod == ' ') |
|
|
356 | goto verbatim; |
|
|
357 | |
|
|
358 | break; |
|
|
359 | |
|
|
360 | case 'B': case 'C': case 'E': case 'G': |
|
|
361 | case 'H': case 'I': case 'T': case 'U': |
|
|
362 | case 'Z': |
|
|
363 | { |
|
|
364 | int end = 0; |
|
|
365 | |
|
|
366 | while (cfpod [end] == '<') |
|
|
367 | ++end; |
|
|
368 | |
|
|
369 | if (!end) |
|
|
370 | goto passthrough; |
|
|
371 | |
|
|
372 | if (end == 1 || cfpod [end] != ' ') |
|
|
373 | { |
|
|
374 | end = -1; |
|
|
375 | ++cfpod; |
|
|
376 | } |
|
|
377 | else |
|
|
378 | cfpod += end + 1; |
|
|
379 | |
|
|
380 | const char *pfx, *sfx; |
|
|
381 | |
|
|
382 | switch (ch) |
|
|
383 | { |
|
|
384 | case 'B': pfx = "<b>" ; sfx = "</b>" ; break; |
|
|
385 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
|
|
386 | case 'E': pfx = "&" ; sfx = ";" ; break; |
|
|
387 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
|
|
388 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
|
|
389 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
|
|
390 | case 'Z': pfx = "" ; sfx = "" ; break; |
|
|
391 | |
|
|
392 | case 'H': // hint |
|
|
393 | { |
|
|
394 | if (pl->hintmode) |
|
|
395 | { |
|
|
396 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
|
|
397 | nest.clear (); |
|
|
398 | |
|
|
399 | if (pl->hintmode == 1) |
|
|
400 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
|
|
401 | else |
|
|
402 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
|
|
403 | ++cfpod; |
|
|
404 | |
|
|
405 | goto skip; |
|
|
406 | } |
|
|
407 | else |
|
|
408 | { |
|
|
409 | pfx = "<fg name=\"lightblue\">[Hint: "; |
|
|
410 | sfx = "]</fg>"; |
|
|
411 | } |
|
|
412 | } |
|
|
413 | break; |
|
|
414 | |
|
|
415 | case 'G': // gender |
|
|
416 | { |
|
|
417 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
|
|
418 | nest << '\0'; // zero-terminate |
|
|
419 | |
|
|
420 | const char *str = nest.linearise (); |
|
|
421 | const char *sep = strchr (str, '|'); |
|
|
422 | |
|
|
423 | if (sep) |
|
|
424 | { |
|
|
425 | if (pl->gender) |
|
|
426 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
|
|
427 | else |
|
|
428 | buf.add (str, sep - str); |
|
|
429 | } |
|
|
430 | |
|
|
431 | nest.clear (); |
|
|
432 | |
|
|
433 | goto skip; |
|
|
434 | } |
|
|
435 | |
|
|
436 | default: |
|
|
437 | pfx = "UNKNOWN_DIRECTIVE{"; |
|
|
438 | sfx = "}"; |
|
|
439 | break; |
|
|
440 | } |
|
|
441 | |
|
|
442 | buf << pfx; |
|
|
443 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
|
|
444 | buf << sfx; |
|
|
445 | } |
|
|
446 | |
|
|
447 | break; |
|
|
448 | |
|
|
449 | default: |
|
|
450 | passthrough: |
|
|
451 | buf << ch; |
|
|
452 | skip: |
|
|
453 | break; |
|
|
454 | |
|
|
455 | verbatim: |
|
|
456 | // elements cannot currently span multiple lines |
|
|
457 | do |
|
|
458 | { |
|
|
459 | buf << "<tt>"; |
|
|
460 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
|
|
461 | buf << "</tt>\n"; |
|
|
462 | |
|
|
463 | while (*cfpod == '\n') |
|
|
464 | buf << *cfpod++; |
|
|
465 | } |
|
|
466 | while (*cfpod == ' '); |
|
|
467 | |
|
|
468 | break; |
|
|
469 | } |
|
|
470 | } |
|
|
471 | |
|
|
472 | dynbuf_text * |
|
|
473 | player::expand_cfpod (const char *cfpod) const |
|
|
474 | { |
|
|
475 | static dynbuf_text buf(1024, 1024); |
|
|
476 | buf.clear (); |
|
|
477 | |
|
|
478 | ::expand_cfpod (this, buf, cfpod); |
|
|
479 | |
|
|
480 | return &buf; |
|
|
481 | } |
|
|
482 | |