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,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * 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 Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | |
26 | |
… | |
… | |
284 | // end == -2, till '\n' |
284 | // end == -2, till '\n' |
285 | // end == -1, till '>' |
285 | // end == -1, till '>' |
286 | // end == 0, till eos |
286 | // end == 0, till eos |
287 | // end >= 1, levels of " >>>" |
287 | // end >= 1, levels of " >>>" |
288 | static const char * |
288 | static const char * |
289 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) |
289 | expand_cfpod (int hintmode, int gender, dynbuf_text &buf, const char *cfpod, int end = 0) |
290 | { |
290 | { |
291 | static dynbuf_text nest(128, 128); |
291 | static dynbuf_text nest(128, 128); |
292 | |
292 | |
293 | for (;;) |
293 | for (;;) |
294 | switch (char ch = *cfpod++) |
294 | switch (char ch = *cfpod++) |
… | |
… | |
396 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
396 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
397 | case 'Z': pfx = "" ; sfx = "" ; break; |
397 | case 'Z': pfx = "" ; sfx = "" ; break; |
398 | |
398 | |
399 | case 'H': // hint |
399 | case 'H': // hint |
400 | { |
400 | { |
401 | if (pl->hintmode) |
401 | if (hintmode) |
402 | { |
402 | { |
403 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
403 | cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end); |
404 | nest.clear (); |
404 | nest.clear (); |
405 | |
405 | |
406 | if (pl->hintmode == 1) |
406 | if (hintmode == 1) |
407 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
407 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
408 | else |
408 | else |
409 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
409 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
410 | ++cfpod; |
410 | ++cfpod; |
411 | |
411 | |
… | |
… | |
419 | } |
419 | } |
420 | break; |
420 | break; |
421 | |
421 | |
422 | case 'G': // gender |
422 | case 'G': // gender |
423 | { |
423 | { |
424 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
424 | cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end); |
425 | nest << '\0'; // zero-terminate |
425 | nest << '\0'; // zero-terminate |
426 | |
426 | |
427 | const char *str = nest.linearise (); |
427 | const char *str = nest.linearise (); |
428 | const char *sep = strchr (str, '|'); |
428 | const char *sep = strchr (str, '|'); |
429 | |
429 | |
430 | if (sep) |
430 | if (sep) |
431 | { |
431 | { |
432 | if (pl->gender) |
432 | if (gender) |
433 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
433 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
434 | else |
434 | else |
435 | buf.add (str, sep - str); |
435 | buf.add (str, sep - str); |
436 | } |
436 | } |
437 | |
437 | |
… | |
… | |
445 | sfx = "}"; |
445 | sfx = "}"; |
446 | break; |
446 | break; |
447 | } |
447 | } |
448 | |
448 | |
449 | buf << pfx; |
449 | buf << pfx; |
450 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
450 | cfpod = expand_cfpod (hintmode, gender, buf, cfpod, end); |
451 | buf << sfx; |
451 | buf << sfx; |
452 | } |
452 | } |
453 | |
453 | |
454 | break; |
454 | break; |
455 | |
455 | |
… | |
… | |
462 | verbatim: |
462 | verbatim: |
463 | // elements cannot currently span multiple lines |
463 | // elements cannot currently span multiple lines |
464 | do |
464 | do |
465 | { |
465 | { |
466 | buf << "<tt>"; |
466 | buf << "<tt>"; |
467 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
467 | cfpod = expand_cfpod (hintmode, gender, buf, cfpod, -2); |
468 | buf << "</tt>\n"; |
468 | buf << "</tt>\n"; |
469 | |
469 | |
470 | while (*cfpod == '\n') |
470 | while (*cfpod == '\n') |
471 | buf << *cfpod++; |
471 | buf << *cfpod++; |
472 | } |
472 | } |
… | |
… | |
475 | break; |
475 | break; |
476 | } |
476 | } |
477 | } |
477 | } |
478 | |
478 | |
479 | dynbuf_text * |
479 | dynbuf_text * |
480 | player::expand_cfpod (const char *cfpod) const |
480 | player::expand_cfpod (int hintmode, int gender, const_utf8_string cfpod) |
481 | { |
481 | { |
482 | static dynbuf_text buf(1024, 1024); |
482 | static dynbuf_text buf(65536, 1024); |
483 | buf.clear (); |
483 | buf.clear (); |
484 | |
484 | |
485 | ::expand_cfpod (this, buf, cfpod); |
485 | ::expand_cfpod (hintmode, gender, buf, cfpod); |
486 | |
486 | |
487 | return &buf; |
487 | return &buf; |
488 | } |
488 | } |
489 | |
489 | |
|
|
490 | dynbuf_text * |
|
|
491 | player::expand_cfpod (const_utf8_string cfpod) const |
|
|
492 | { |
|
|
493 | return expand_cfpod (hintmode, gender, cfpod); |
|
|
494 | } |
|
|
495 | |