1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 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 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * 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 Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | |
|
|
27 | //+GPL |
25 | |
28 | |
26 | /* Determine if the attacktype represented by the |
29 | /* Determine if the attacktype represented by the |
27 | * specified attack-number is enabled for dragon players. |
30 | * specified attack-number is enabled for dragon players. |
28 | * A dragon player (quetzal) can gain resistances for |
31 | * A dragon player (quetzal) can gain resistances for |
29 | * all enabled attacktypes. |
32 | * all enabled attacktypes. |
… | |
… | |
46 | is_dragon_pl (const object *op) |
49 | is_dragon_pl (const object *op) |
47 | { |
50 | { |
48 | if (op |
51 | if (op |
49 | && op->type == PLAYER |
52 | && op->type == PLAYER |
50 | && op->arch |
53 | && op->arch |
51 | && op->arch->race |
54 | && op->arch->race == shstr_dragon) |
52 | && !strcmp (op->arch->race, "dragon")) |
|
|
53 | return 1; |
55 | return 1; |
54 | |
56 | |
55 | return 0; |
57 | return 0; |
56 | } |
58 | } |
57 | |
59 | |
… | |
… | |
64 | INVOKE_PLAYER (SAVE, ob->contr); |
66 | INVOKE_PLAYER (SAVE, ob->contr); |
65 | |
67 | |
66 | int wiz = ob->flag [FLAG_WIZ]; |
68 | int wiz = ob->flag [FLAG_WIZ]; |
67 | |
69 | |
68 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
70 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
69 | object *container = ob->container; |
71 | object *container = ob->container_ (); |
70 | ob->container = 0; |
72 | ob->container = 0; |
71 | |
73 | |
72 | if (ob->map) |
74 | if (ob->map) |
73 | maplevel = ob->map->path; |
75 | maplevel = ob->map->path; |
74 | |
76 | |
… | |
… | |
117 | } |
119 | } |
118 | |
120 | |
119 | freezer.put (ob->contr); |
121 | freezer.put (ob->contr); |
120 | freezer.put (KW_endplst); |
122 | freezer.put (KW_endplst); |
121 | |
123 | |
122 | SET_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
123 | CLEAR_FLAG (ob, FLAG_WIZ); |
124 | CLEAR_FLAG (ob, FLAG_WIZ); |
124 | ob->write (freezer); |
125 | ob->write (freezer); |
125 | |
126 | |
126 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
127 | |
|
|
128 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
127 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
129 | ob->container = container; |
128 | ob->container = container; |
130 | |
129 | |
131 | ob->flag [FLAG_WIZ] = wiz; |
130 | ob->flag [FLAG_WIZ] = wiz; |
132 | |
131 | |
133 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
132 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
134 | |
133 | |
135 | return true; |
134 | return true; |
136 | } |
135 | } |
|
|
136 | |
|
|
137 | //-GPL |
137 | |
138 | |
138 | bool |
139 | bool |
139 | player::save_pl (const char *path) |
140 | player::save_pl (const char *path) |
140 | { |
141 | { |
141 | object_freezer freezer; |
142 | object_freezer freezer; |
… | |
… | |
287 | |
288 | |
288 | return buf; |
289 | return buf; |
289 | } |
290 | } |
290 | |
291 | |
291 | // expand one level of cfpod |
292 | // expand one level of cfpod |
|
|
293 | // end == -2, till '\n' |
|
|
294 | // end == -1, till '>' |
292 | // end == -1, till eos |
295 | // end == 0, till eos |
293 | // end == 0, one level of '>' |
|
|
294 | // end >= 1, this many levels of " >>>" |
296 | // end >= 1, levels of " >>>" |
295 | static const char * |
297 | static const char * |
296 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) |
298 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) |
297 | { |
299 | { |
298 | static dynbuf_text nest(128, 128); |
300 | static dynbuf_text nest(128, 128); |
299 | |
301 | |
300 | for (;;) |
302 | for (;;) |
301 | switch (char ch = *cfpod++) |
303 | switch (char ch = *cfpod++) |
302 | { |
304 | { |
303 | case 0: |
305 | case 0: |
304 | return cfpod - 1; |
306 | return cfpod - 1; |
305 | |
307 | |
306 | case ' ': |
308 | case ' ': |
|
|
309 | // verbatim block? |
|
|
310 | if (!buf.size () && !end) |
|
|
311 | { |
|
|
312 | --cfpod; |
|
|
313 | goto verbatim; |
|
|
314 | } |
|
|
315 | |
307 | if (end <= 0) |
316 | if (end < 1) |
308 | goto passthrough; |
317 | goto passthrough; |
309 | |
318 | |
310 | for (int i = 0; i < end; ++i) |
319 | for (int i = 0; i < end; ++i) |
311 | if (cfpod [i] != '>') |
320 | if (cfpod [i] != '>') |
312 | goto passthrough; |
321 | goto passthrough; |
313 | |
322 | |
314 | return cfpod + end; |
323 | return cfpod + end; |
315 | |
324 | |
316 | case '>': |
325 | case '>': |
317 | if (end) |
326 | if (end != -1) |
318 | { |
327 | { |
319 | buf << ">"; |
328 | buf << ">"; |
320 | break; |
329 | break; |
321 | } |
330 | } |
322 | |
331 | |
… | |
… | |
328 | |
337 | |
329 | case '<': |
338 | case '<': |
330 | buf << "<"; |
339 | buf << "<"; |
331 | break; |
340 | break; |
332 | |
341 | |
|
|
342 | case '\r': |
|
|
343 | buf << '\n'; |
|
|
344 | /* \r\n+ becomes one or more newlines */ |
|
|
345 | while (*cfpod == '\n') |
|
|
346 | buf << *cfpod++; |
|
|
347 | break; |
|
|
348 | |
333 | case '\n': |
349 | case '\n': |
|
|
350 | if (end == -2) |
|
|
351 | return cfpod; |
|
|
352 | |
|
|
353 | // \n\ => newline, tt |
|
|
354 | // \n\n => \n\n |
|
|
355 | // \n => single space |
|
|
356 | |
|
|
357 | // two or more newlines will be copied verbatim, one is replaced by space |
334 | if (*cfpod == ' ') |
358 | if (*cfpod == '\n') |
335 | goto passthrough; |
|
|
336 | else if (*cfpod == '\n') |
|
|
337 | { |
359 | { |
338 | --cfpod; |
360 | --cfpod; |
339 | while (*cfpod == '\n') |
361 | do |
340 | buf << *cfpod++; |
362 | buf << *cfpod++; |
341 | |
363 | while (*cfpod == '\n'); |
342 | goto skip; |
|
|
343 | } |
364 | } |
344 | |
365 | else if (*cfpod == ' ') |
|
|
366 | buf << '\n'; |
|
|
367 | else |
345 | buf << ' '; |
368 | buf << ' '; |
|
|
369 | |
|
|
370 | // verbatim block? |
|
|
371 | if (*cfpod == ' ') |
|
|
372 | goto verbatim; |
|
|
373 | |
346 | break; |
374 | break; |
347 | |
375 | |
348 | case 'B': case 'C': case 'E': case 'G': |
376 | case 'B': case 'C': case 'E': case 'G': |
349 | case 'H': case 'I': case 'T': case 'U': |
377 | case 'H': case 'I': case 'T': case 'U': |
350 | case 'Z': |
378 | case 'Z': |
351 | { |
379 | { |
352 | int len = 0; |
380 | int end = 0; |
353 | |
381 | |
354 | while (cfpod [len] == '<') |
382 | while (cfpod [end] == '<') |
355 | ++len; |
383 | ++end; |
356 | |
384 | |
357 | if (!len) |
385 | if (!end) |
358 | goto passthrough; |
386 | goto passthrough; |
359 | |
387 | |
360 | if (len == 1 || cfpod [len] != ' ') |
388 | if (end == 1 || cfpod [end] != ' ') |
361 | { |
389 | { |
362 | len = 0; |
390 | end = -1; |
363 | ++cfpod; |
391 | ++cfpod; |
364 | } |
392 | } |
365 | else |
393 | else |
366 | cfpod += len + 1; |
394 | cfpod += end + 1; |
367 | |
395 | |
368 | const char *pfx, *sfx; |
396 | const char *pfx, *sfx; |
369 | |
397 | |
370 | switch (ch) |
398 | switch (ch) |
371 | { |
399 | { |
… | |
… | |
373 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
401 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
374 | case 'E': pfx = "&" ; sfx = ";" ; break; |
402 | case 'E': pfx = "&" ; sfx = ";" ; break; |
375 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
403 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
376 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
404 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
377 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
405 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
|
|
406 | case 'Z': pfx = "" ; sfx = "" ; break; |
378 | |
407 | |
379 | case 'H': // hint |
408 | case 'H': // hint |
380 | { |
409 | { |
381 | if (pl->hintmode) |
410 | if (pl->hintmode) |
382 | { |
411 | { |
383 | cfpod = expand_cfpod (pl, nest, cfpod, len); |
412 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
384 | nest.clear (); |
413 | nest.clear (); |
385 | |
414 | |
386 | if (pl->hintmode == 1) |
415 | if (pl->hintmode == 1) |
387 | buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; |
416 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
388 | else |
417 | else |
389 | while (*cfpod == ' ') // eat trailing whitespace |
418 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
390 | ++cfpod; |
419 | ++cfpod; |
391 | |
420 | |
392 | goto skip; |
421 | goto skip; |
393 | } |
422 | } |
394 | else |
423 | else |
395 | { |
424 | { |
396 | pfx = "<fg name=\"lightblue\">["; |
425 | pfx = "<fg name=\"lightblue\">[Hint: "; |
397 | sfx = " (Use hintmode to suppress hints)]</fg>"; |
426 | sfx = "]</fg>"; |
398 | } |
427 | } |
399 | } |
428 | } |
400 | break; |
429 | break; |
401 | |
430 | |
402 | case 'G': // gender |
431 | case 'G': // gender |
403 | { |
432 | { |
404 | expand_cfpod (pl, nest, cfpod, len); |
433 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
405 | nest << '\0'; // zero-terminate |
434 | nest << '\0'; // zero-terminate |
406 | |
435 | |
407 | const char *str = nest.linearise (); |
436 | const char *str = nest.linearise (); |
408 | const char *sep = strchr (str, '|'); |
437 | const char *sep = strchr (str, '|'); |
409 | |
438 | |
410 | if (sep) |
439 | if (sep) |
411 | { |
440 | { |
412 | if (pl->gender || 1) |
441 | if (pl->gender) |
413 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
442 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
414 | else |
443 | else |
415 | buf.add (str, sep - str); |
444 | buf.add (str, sep - str); |
416 | } |
445 | } |
417 | |
446 | |
418 | nest.clear (); |
447 | nest.clear (); |
419 | |
448 | |
420 | goto skip; |
449 | goto skip; |
421 | } |
450 | } |
|
|
451 | |
|
|
452 | default: |
|
|
453 | pfx = "UNKNOWN_DIRECTIVE{"; |
|
|
454 | sfx = "}"; |
|
|
455 | break; |
422 | } |
456 | } |
423 | |
457 | |
424 | buf << pfx; |
458 | buf << pfx; |
425 | cfpod = expand_cfpod (pl, buf, cfpod, len); |
459 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
426 | buf << sfx; |
460 | buf << sfx; |
427 | } |
461 | } |
428 | |
462 | |
429 | break; |
463 | break; |
430 | |
464 | |
431 | default: |
465 | default: |
432 | passthrough: |
466 | passthrough: |
433 | buf << ch; |
467 | buf << ch; |
434 | skip: |
468 | skip: |
435 | break; |
469 | break; |
|
|
470 | |
|
|
471 | verbatim: |
|
|
472 | // elements cannot currently span multiple lines |
|
|
473 | do |
|
|
474 | { |
|
|
475 | buf << "<tt>"; |
|
|
476 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
|
|
477 | buf << "</tt>\n"; |
|
|
478 | |
|
|
479 | while (*cfpod == '\n') |
|
|
480 | buf << *cfpod++; |
|
|
481 | } |
|
|
482 | while (*cfpod == ' '); |
|
|
483 | |
|
|
484 | break; |
436 | } |
485 | } |
437 | } |
486 | } |
438 | |
487 | |
439 | dynbuf_text * |
488 | dynbuf_text * |
440 | player::expand_cfpod (const char *cfpod) const |
489 | player::expand_cfpod (const char *cfpod) const |
441 | { |
490 | { |
442 | static dynbuf_text buf(1024, 1024); |
491 | static dynbuf_text buf(1024, 1024); |
443 | buf.clear (); |
492 | buf.clear (); |
444 | |
493 | |
445 | ::expand_cfpod (this, buf, cfpod, -1); |
494 | ::expand_cfpod (this, buf, cfpod); |
446 | |
495 | |
447 | return &buf; |
496 | return &buf; |
448 | } |
497 | } |
449 | |
498 | |