ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/player.C
(Generate patch)

Comparing deliantra/server/common/player.C (file contents):
Revision 1.69 by root, Sat Apr 23 04:56:46 2011 UTC vs.
Revision 1.74 by root, Wed Nov 21 13:06:10 2012 UTC

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
283// expand one level of cfpod 283// expand one level of cfpod
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// pod sequences not handled: F, S, X
288static const char * 289static const char *
289expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) 290expand_cfpod (int hintmode, int gender, dynbuf_text &buf, const char *cfpod, int end = 0)
290{ 291{
291 static dynbuf_text nest(128, 128); 292 static dynbuf_text nest(128, 128);
292 293
293 for (;;) 294 for (;;)
294 switch (char ch = *cfpod++) 295 switch (char ch = *cfpod++)
362 if (*cfpod == ' ') 363 if (*cfpod == ' ')
363 goto verbatim; 364 goto verbatim;
364 365
365 break; 366 break;
366 367
367 case 'B': case 'C': case 'E': case 'G': 368 case 'B': case 'C': case 'E': case 'G': case 'H':
368 case 'H': case 'I': case 'T': case 'U': 369 case 'I': case 'L': case 'T': case 'U': case 'Z':
369 case 'Z':
370 { 370 {
371 int end = 0; 371 int end = 0;
372 372
373 while (cfpod [end] == '<') 373 while (cfpod [end] == '<')
374 ++end; 374 ++end;
394 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 394 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
395 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 395 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
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 'L': // link, not really supported - always use first (or only) component
400 {
401 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
402 nest << '\0'; // zero-terminate
403
404 const char *str = nest.linearise ();
405 const char *sep = strchr (str, '|');
406
407 buf.add (str, sep ? sep - str : nest.size ());
408
409 nest.clear ();
410
411 goto skip;
412 }
413
399 case 'H': // hint 414 case 'H': // hint
400 { 415 {
401 if (pl->hintmode) 416 if (hintmode)
402 { 417 {
403 cfpod = expand_cfpod (pl, nest, cfpod, end); 418 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
404 nest.clear (); 419 nest.clear ();
405 420
406 if (pl->hintmode == 1) 421 if (hintmode == 1)
407 buf << "<fg name=\"lightblue\">[Hint available]</fg>"; 422 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
408 else 423 else
409 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace 424 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
410 ++cfpod; 425 ++cfpod;
411 426
419 } 434 }
420 break; 435 break;
421 436
422 case 'G': // gender 437 case 'G': // gender
423 { 438 {
424 cfpod = expand_cfpod (pl, nest, cfpod, end); 439 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
425 nest << '\0'; // zero-terminate 440 nest << '\0'; // zero-terminate
426 441
427 const char *str = nest.linearise (); 442 const char *str = nest.linearise ();
428 const char *sep = strchr (str, '|'); 443 const char *sep = strchr (str, '|');
429 444
430 if (sep) 445 if (sep)
431 { 446 {
432 if (pl->gender) 447 if (gender)
433 buf.add (sep + 1, nest.size () - (sep - str) - 2); 448 buf.add (sep + 1, nest.size () - (sep - str) - 2);
434 else 449 else
435 buf.add (str, sep - str); 450 buf.add (str, sep - str);
436 } 451 }
437 452
445 sfx = "}"; 460 sfx = "}";
446 break; 461 break;
447 } 462 }
448 463
449 buf << pfx; 464 buf << pfx;
450 cfpod = expand_cfpod (pl, buf, cfpod, end); 465 cfpod = expand_cfpod (hintmode, gender, buf, cfpod, end);
451 buf << sfx; 466 buf << sfx;
452 } 467 }
453 468
454 break; 469 break;
455 470
462 verbatim: 477 verbatim:
463 // elements cannot currently span multiple lines 478 // elements cannot currently span multiple lines
464 do 479 do
465 { 480 {
466 buf << "<tt>"; 481 buf << "<tt>";
467 cfpod = expand_cfpod (pl, buf, cfpod, -2); 482 cfpod = expand_cfpod (hintmode, gender, buf, cfpod, -2);
468 buf << "</tt>\n"; 483 buf << "</tt>\n";
469 484
470 while (*cfpod == '\n') 485 while (*cfpod == '\n')
471 buf << *cfpod++; 486 buf << *cfpod++;
472 } 487 }
475 break; 490 break;
476 } 491 }
477} 492}
478 493
479dynbuf_text * 494dynbuf_text *
480player::expand_cfpod (const char *cfpod) const 495player::expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
481{ 496{
482 static dynbuf_text buf(1024, 1024); 497 static dynbuf_text buf(65536, 1024);
483 buf.clear (); 498 buf.clear ();
484 499
485 ::expand_cfpod (this, buf, cfpod); 500 ::expand_cfpod (hintmode, gender, buf, cfpod);
486 501
487 return &buf; 502 return &buf;
488} 503}
489 504
505dynbuf_text *
506player::expand_cfpod (const_utf8_string cfpod) const
507{
508 return expand_cfpod (hintmode, gender, cfpod);
509}
510

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines