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.43 by root, Mon Sep 8 18:34:35 2008 UTC vs.
Revision 1.55 by root, Mon Oct 12 14:00:57 2009 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 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>
46is_dragon_pl (const object *op) 47is_dragon_pl (const object *op)
47{ 48{
48 if (op 49 if (op
49 && op->type == PLAYER 50 && op->type == PLAYER
50 && op->arch 51 && op->arch
51 && op->arch->race 52 && op->arch->race == shstr_dragon)
52 && !strcmp (op->arch->race, "dragon"))
53 return 1; 53 return 1;
54 54
55 return 0; 55 return 0;
56} 56}
57 57
292// end == -2, till '\n' 292// end == -2, till '\n'
293// end == -1, till '>' 293// end == -1, till '>'
294// end == 0, till eos 294// end == 0, till eos
295// end >= 1, levels of " >>>" 295// end >= 1, levels of " >>>"
296static const char * 296static const char *
297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
298{ 298{
299 static dynbuf_text nest(128, 128); 299 static dynbuf_text nest(128, 128);
300 300
301 for (;;) 301 for (;;)
302 switch (char ch = *cfpod++) 302 switch (char ch = *cfpod++)
303 { 303 {
304 case 0: 304 case 0:
305 return cfpod - 1; 305 return cfpod - 1;
306 306
307 case ' ': 307 case ' ':
308 // verbatim block?
309 if (!buf.size () && !end)
310 {
311 --cfpod;
312 goto verbatim;
313 }
314
308 if (end < 1) 315 if (end < 1)
309 goto passthrough; 316 goto passthrough;
310 317
311 for (int i = 0; i < end; ++i) 318 for (int i = 0; i < end; ++i)
312 if (cfpod [i] != '>') 319 if (cfpod [i] != '>')
331 buf << "&lt;"; 338 buf << "&lt;";
332 break; 339 break;
333 340
334 case '\r': 341 case '\r':
335 buf << '\n'; 342 buf << '\n';
343 /* \r\n+ becomes one or more newlines */
344 while (*cfpod == '\n')
345 buf << *cfpod++;
336 break; 346 break;
337 347
338 case '\n': 348 case '\n':
339 if (end == -2) 349 if (end == -2)
340 return cfpod; 350 return cfpod;
349 --cfpod; 359 --cfpod;
350 do 360 do
351 buf << *cfpod++; 361 buf << *cfpod++;
352 while (*cfpod == '\n'); 362 while (*cfpod == '\n');
353 } 363 }
354 else if (*cfpod != ' ') 364 else if (*cfpod == ' ')
365 buf << '\n';
366 else
355 buf << ' '; 367 buf << ' ';
356 368
357 // start verbatim block's? 369 // verbatim block?
358 if (*cfpod == ' ') 370 if (*cfpod == ' ')
359 { 371 goto verbatim;
360 // elements cannot currently span multiple lines
361 do
362 {
363 buf << "<tt>";
364 cfpod = expand_cfpod (pl, buf, cfpod, -2);
365 buf << "</tt>\n";
366 }
367 while (*cfpod == ' ');
368
369 while (*cfpod == '\n')
370 buf << *cfpod++;
371 }
372 372
373 break; 373 break;
374 374
375 case 'B': case 'C': case 'E': case 'G': 375 case 'B': case 'C': case 'E': case 'G':
376 case 'H': case 'I': case 'T': case 'U': 376 case 'H': case 'I': case 'T': case 'U':
400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
401 case 'E': pfx = "&" ; sfx = ";" ; break; 401 case 'E': pfx = "&" ; sfx = ";" ; break;
402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
405 case 'Z': pfx = "" ; sfx = "" ; break;
405 406
406 case 'H': // hint 407 case 'H': // hint
407 { 408 {
408 if (pl->hintmode) 409 if (pl->hintmode)
409 { 410 {
410 cfpod = expand_cfpod (pl, nest, cfpod, end); 411 cfpod = expand_cfpod (pl, nest, cfpod, end);
411 nest.clear (); 412 nest.clear ();
412 413
413 if (pl->hintmode == 1) 414 if (pl->hintmode == 1)
414 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 415 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
415 else 416 else
416 while (*cfpod == ' ') // eat trailing whitespace 417 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
417 ++cfpod; 418 ++cfpod;
418 419
419 goto skip; 420 goto skip;
420 } 421 }
421 else 422 else
422 { 423 {
423 pfx = "<fg name=\"lightblue\">["; 424 pfx = "<fg name=\"lightblue\">[Hint: ";
424 sfx = " (Use hintmode to suppress hints)]</fg>"; 425 sfx = "]</fg>";
425 } 426 }
426 } 427 }
427 break; 428 break;
428 429
429 case 'G': // gender 430 case 'G': // gender
430 { 431 {
431 expand_cfpod (pl, nest, cfpod, end); 432 cfpod = expand_cfpod (pl, nest, cfpod, end);
432 nest << '\0'; // zero-terminate 433 nest << '\0'; // zero-terminate
433 434
434 const char *str = nest.linearise (); 435 const char *str = nest.linearise ();
435 const char *sep = strchr (str, '|'); 436 const char *sep = strchr (str, '|');
436 437
437 if (sep) 438 if (sep)
438 { 439 {
439 if (pl->gender || 1) 440 if (pl->gender)
440 buf.add (sep + 1, nest.size () - (sep - str) - 2); 441 buf.add (sep + 1, nest.size () - (sep - str) - 2);
441 else 442 else
442 buf.add (str, sep - str); 443 buf.add (str, sep - str);
443 } 444 }
444 445
458 default: 459 default:
459 passthrough: 460 passthrough:
460 buf << ch; 461 buf << ch;
461 skip: 462 skip:
462 break; 463 break;
464
465 verbatim:
466 // elements cannot currently span multiple lines
467 do
468 {
469 buf << "<tt>";
470 cfpod = expand_cfpod (pl, buf, cfpod, -2);
471 buf << "</tt>\n";
472
473 while (*cfpod == '\n')
474 buf << *cfpod++;
475 }
476 while (*cfpod == ' ');
477
478 break;
463 } 479 }
464} 480}
465 481
466dynbuf_text * 482dynbuf_text *
467player::expand_cfpod (const char *cfpod) const 483player::expand_cfpod (const char *cfpod) const
468{ 484{
469 static dynbuf_text buf(1024, 1024); 485 static dynbuf_text buf(1024, 1024);
470 buf.clear (); 486 buf.clear ();
471 487
472 ::expand_cfpod (this, buf, cfpod, 0); 488 ::expand_cfpod (this, buf, cfpod);
473 489
474 return &buf; 490 return &buf;
475} 491}
476 492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines