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.51 by elmex, Fri Jun 26 16:21:57 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
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
333 case '\r': 340 case '\r':
334 buf << '\n'; 341 buf << '\n';
335 break; 342 break;
336 343
337 case '\n': 344 case '\n':
345 if (end == -2)
346 return cfpod;
347
348 // \n\ => newline, tt
349 // \n\n => \n\n
350 // \n => single space
351
352 // two or more newlines will be copied verbatim, one is replaced by space
338 if (*cfpod == ' ') 353 if (*cfpod == '\n')
339 goto passthrough;
340 else if (*cfpod == '\n')
341 { 354 {
342 --cfpod; 355 --cfpod;
343 do 356 do
344 buf << *cfpod++; 357 buf << *cfpod++;
345 while (*cfpod == '\n'); 358 while (*cfpod == '\n');
346 } 359 }
360 else if (*cfpod == ' ')
361 buf << '\n';
347 else 362 else
348 buf << ' '; 363 buf << ' ';
364
365 // verbatim block?
366 if (*cfpod == ' ')
367 goto verbatim;
349 368
350 break; 369 break;
351 370
352 case 'B': case 'C': case 'E': case 'G': 371 case 'B': case 'C': case 'E': case 'G':
353 case 'H': case 'I': case 'T': case 'U': 372 case 'H': case 'I': case 'T': case 'U':
354 case 'Z': 373 case 'Z':
355 { 374 {
356 int len = 0; 375 int end = 0;
357 376
358 while (cfpod [len] == '<') 377 while (cfpod [end] == '<')
359 ++len; 378 ++end;
360 379
361 if (!len) 380 if (!end)
362 goto passthrough; 381 goto passthrough;
363 382
364 if (len == 1 || cfpod [len] != ' ') 383 if (end == 1 || cfpod [end] != ' ')
365 { 384 {
366 len = 0; 385 end = -1;
367 ++cfpod; 386 ++cfpod;
368 } 387 }
369 else 388 else
370 cfpod += len + 1; 389 cfpod += end + 1;
371 390
372 const char *pfx, *sfx; 391 const char *pfx, *sfx;
373 392
374 switch (ch) 393 switch (ch)
375 { 394 {
377 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 396 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
378 case 'E': pfx = "&" ; sfx = ";" ; break; 397 case 'E': pfx = "&" ; sfx = ";" ; break;
379 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 398 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
380 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 399 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
381 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 400 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
401 case 'Z': pfx = "" ; sfx = "" ; break;
382 402
383 case 'H': // hint 403 case 'H': // hint
384 { 404 {
385 if (pl->hintmode) 405 if (pl->hintmode)
386 { 406 {
387 cfpod = expand_cfpod (pl, nest, cfpod, len); 407 cfpod = expand_cfpod (pl, nest, cfpod, end);
388 nest.clear (); 408 nest.clear ();
389 409
390 if (pl->hintmode == 1) 410 if (pl->hintmode == 1)
391 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 411 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
392 else 412 else
403 } 423 }
404 break; 424 break;
405 425
406 case 'G': // gender 426 case 'G': // gender
407 { 427 {
408 expand_cfpod (pl, nest, cfpod, len); 428 cfpod = expand_cfpod (pl, nest, cfpod, end);
409 nest << '\0'; // zero-terminate 429 nest << '\0'; // zero-terminate
410 430
411 const char *str = nest.linearise (); 431 const char *str = nest.linearise ();
412 const char *sep = strchr (str, '|'); 432 const char *sep = strchr (str, '|');
413 433
414 if (sep) 434 if (sep)
415 { 435 {
416 if (pl->gender || 1) 436 if (pl->gender)
417 buf.add (sep + 1, nest.size () - (sep - str) - 2); 437 buf.add (sep + 1, nest.size () - (sep - str) - 2);
418 else 438 else
419 buf.add (str, sep - str); 439 buf.add (str, sep - str);
420 } 440 }
421 441
424 goto skip; 444 goto skip;
425 } 445 }
426 } 446 }
427 447
428 buf << pfx; 448 buf << pfx;
429 cfpod = expand_cfpod (pl, buf, cfpod, len); 449 cfpod = expand_cfpod (pl, buf, cfpod, end);
430 buf << sfx; 450 buf << sfx;
431 } 451 }
432 452
433 break; 453 break;
434 454
435 default: 455 default:
436 passthrough: 456 passthrough:
437 buf << ch; 457 buf << ch;
438 skip: 458 skip:
439 break; 459 break;
460
461 verbatim:
462 // elements cannot currently span multiple lines
463 do
464 {
465 buf << "<tt>";
466 cfpod = expand_cfpod (pl, buf, cfpod, -2);
467 buf << "</tt>\n";
468
469 while (*cfpod == '\n')
470 buf << *cfpod++;
471 }
472 while (*cfpod == ' ');
473
474 break;
440 } 475 }
441} 476}
442 477
443dynbuf_text * 478dynbuf_text *
444player::expand_cfpod (const char *cfpod) const 479player::expand_cfpod (const char *cfpod) const
445{ 480{
446 static dynbuf_text buf(1024, 1024); 481 static dynbuf_text buf(1024, 1024);
447 buf.clear (); 482 buf.clear ();
448 483
449 ::expand_cfpod (this, buf, cfpod, -1); 484 ::expand_cfpod (this, buf, cfpod);
450 485
451 return &buf; 486 return &buf;
452} 487}
453 488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines