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.42 by root, Mon Sep 8 11:30:53 2008 UTC vs.
Revision 1.54 by root, Thu Sep 17 00:10:03 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
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
46is_dragon_pl (const object *op) 46is_dragon_pl (const object *op)
47{ 47{
48 if (op 48 if (op
49 && op->type == PLAYER 49 && op->type == PLAYER
50 && op->arch 50 && op->arch
51 && op->arch->race 51 && op->arch->race == shstr_dragon)
52 && !strcmp (op->arch->race, "dragon"))
53 return 1; 52 return 1;
54 53
55 return 0; 54 return 0;
56} 55}
57 56
287 286
288 return buf; 287 return buf;
289} 288}
290 289
291// expand one level of cfpod 290// expand one level of cfpod
291// end == -2, till '\n'
292// end == -1, till '>'
292// end == -1, till eos 293// end == 0, till eos
293// end == 0, one level of '>'
294// end >= 1, this many levels of " >>>" 294// end >= 1, levels of " >>>"
295static const char * 295static const char *
296expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 296expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
297{ 297{
298 static dynbuf_text nest(128, 128); 298 static dynbuf_text nest(128, 128);
299 299
300 for (;;) 300 for (;;)
301 switch (char ch = *cfpod++) 301 switch (char ch = *cfpod++)
302 { 302 {
303 case 0: 303 case 0:
304 return cfpod - 1; 304 return cfpod - 1;
305 305
306 case ' ': 306 case ' ':
307 // verbatim block?
308 if (!buf.size () && !end)
309 {
310 --cfpod;
311 goto verbatim;
312 }
313
307 if (end <= 0) 314 if (end < 1)
308 goto passthrough; 315 goto passthrough;
309 316
310 for (int i = 0; i < end; ++i) 317 for (int i = 0; i < end; ++i)
311 if (cfpod [i] != '>') 318 if (cfpod [i] != '>')
312 goto passthrough; 319 goto passthrough;
313 320
314 return cfpod + end; 321 return cfpod + end;
315 322
316 case '>': 323 case '>':
317 if (end) 324 if (end != -1)
318 { 325 {
319 buf << "&gt;"; 326 buf << "&gt;";
320 break; 327 break;
321 } 328 }
322 329
330 buf << "&lt;"; 337 buf << "&lt;";
331 break; 338 break;
332 339
333 case '\r': 340 case '\r':
334 buf << '\n'; 341 buf << '\n';
342 /* \r\n+ becomes one or more newlines */
343 while (*cfpod == '\n')
344 buf << *cfpod++;
335 break; 345 break;
336 346
337 case '\n': 347 case '\n':
348 if (end == -2)
349 return cfpod;
350
351 // \n\ => newline, tt
352 // \n\n => \n\n
353 // \n => single space
354
355 // two or more newlines will be copied verbatim, one is replaced by space
338 if (*cfpod == ' ') 356 if (*cfpod == '\n')
339 goto passthrough;
340 else if (*cfpod == '\n')
341 { 357 {
342 --cfpod; 358 --cfpod;
343 do 359 do
344 buf << *cfpod++; 360 buf << *cfpod++;
345 while (*cfpod == '\n'); 361 while (*cfpod == '\n');
346 } 362 }
363 else if (*cfpod == ' ')
364 buf << '\n';
347 else 365 else
348 buf << ' '; 366 buf << ' ';
367
368 // verbatim block?
369 if (*cfpod == ' ')
370 goto verbatim;
349 371
350 break; 372 break;
351 373
352 case 'B': case 'C': case 'E': case 'G': 374 case 'B': case 'C': case 'E': case 'G':
353 case 'H': case 'I': case 'T': case 'U': 375 case 'H': case 'I': case 'T': case 'U':
354 case 'Z': 376 case 'Z':
355 { 377 {
356 int len = 0; 378 int end = 0;
357 379
358 while (cfpod [len] == '<') 380 while (cfpod [end] == '<')
359 ++len; 381 ++end;
360 382
361 if (!len) 383 if (!end)
362 goto passthrough; 384 goto passthrough;
363 385
364 if (len == 1 || cfpod [len] != ' ') 386 if (end == 1 || cfpod [end] != ' ')
365 { 387 {
366 len = 0; 388 end = -1;
367 ++cfpod; 389 ++cfpod;
368 } 390 }
369 else 391 else
370 cfpod += len + 1; 392 cfpod += end + 1;
371 393
372 const char *pfx, *sfx; 394 const char *pfx, *sfx;
373 395
374 switch (ch) 396 switch (ch)
375 { 397 {
377 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 399 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
378 case 'E': pfx = "&" ; sfx = ";" ; break; 400 case 'E': pfx = "&" ; sfx = ";" ; break;
379 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 401 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
380 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 402 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
381 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 403 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
404 case 'Z': pfx = "" ; sfx = "" ; break;
382 405
383 case 'H': // hint 406 case 'H': // hint
384 { 407 {
385 if (pl->hintmode) 408 if (pl->hintmode)
386 { 409 {
387 cfpod = expand_cfpod (pl, nest, cfpod, len); 410 cfpod = expand_cfpod (pl, nest, cfpod, end);
388 nest.clear (); 411 nest.clear ();
389 412
390 if (pl->hintmode == 1) 413 if (pl->hintmode == 1)
391 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 414 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
392 else 415 else
393 while (*cfpod == ' ') // eat trailing whitespace 416 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
394 ++cfpod; 417 ++cfpod;
395 418
396 goto skip; 419 goto skip;
397 } 420 }
398 else 421 else
399 { 422 {
400 pfx = "<fg name=\"lightblue\">["; 423 pfx = "<fg name=\"lightblue\">[Hint: ";
401 sfx = " (Use hintmode to suppress hints)]</fg>"; 424 sfx = "]</fg>";
402 } 425 }
403 } 426 }
404 break; 427 break;
405 428
406 case 'G': // gender 429 case 'G': // gender
407 { 430 {
408 expand_cfpod (pl, nest, cfpod, len); 431 cfpod = expand_cfpod (pl, nest, cfpod, end);
409 nest << '\0'; // zero-terminate 432 nest << '\0'; // zero-terminate
410 433
411 const char *str = nest.linearise (); 434 const char *str = nest.linearise ();
412 const char *sep = strchr (str, '|'); 435 const char *sep = strchr (str, '|');
413 436
414 if (sep) 437 if (sep)
415 { 438 {
416 if (pl->gender || 1) 439 if (pl->gender)
417 buf.add (sep + 1, nest.size () - (sep - str) - 2); 440 buf.add (sep + 1, nest.size () - (sep - str) - 2);
418 else 441 else
419 buf.add (str, sep - str); 442 buf.add (str, sep - str);
420 } 443 }
421 444
424 goto skip; 447 goto skip;
425 } 448 }
426 } 449 }
427 450
428 buf << pfx; 451 buf << pfx;
429 cfpod = expand_cfpod (pl, buf, cfpod, len); 452 cfpod = expand_cfpod (pl, buf, cfpod, end);
430 buf << sfx; 453 buf << sfx;
431 } 454 }
432 455
433 break; 456 break;
434 457
435 default: 458 default:
436 passthrough: 459 passthrough:
437 buf << ch; 460 buf << ch;
438 skip: 461 skip:
439 break; 462 break;
463
464 verbatim:
465 // elements cannot currently span multiple lines
466 do
467 {
468 buf << "<tt>";
469 cfpod = expand_cfpod (pl, buf, cfpod, -2);
470 buf << "</tt>\n";
471
472 while (*cfpod == '\n')
473 buf << *cfpod++;
474 }
475 while (*cfpod == ' ');
476
477 break;
440 } 478 }
441} 479}
442 480
443dynbuf_text * 481dynbuf_text *
444player::expand_cfpod (const char *cfpod) const 482player::expand_cfpod (const char *cfpod) const
445{ 483{
446 static dynbuf_text buf(1024, 1024); 484 static dynbuf_text buf(1024, 1024);
447 buf.clear (); 485 buf.clear ();
448 486
449 ::expand_cfpod (this, buf, cfpod, -1); 487 ::expand_cfpod (this, buf, cfpod);
450 488
451 return &buf; 489 return &buf;
452} 490}
453 491

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines