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.53 by root, Thu Sep 17 00:07:04 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines