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.41 by root, Mon Sep 8 11:27:24 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
328 335
329 case '<': 336 case '<':
330 buf << "&lt;"; 337 buf << "&lt;";
331 break; 338 break;
332 339
340 case '\r':
341 buf << '\n';
342 break;
343
333 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
334 if (*cfpod == ' ') 353 if (*cfpod == '\n')
335 goto passthrough;
336 else if (*cfpod == '\n')
337 { 354 {
338 --cfpod; 355 --cfpod;
339 while (*cfpod == '\n') 356 do
340 buf << *cfpod++; 357 buf << *cfpod++;
341 358 while (*cfpod == '\n');
342 goto skip;
343 } 359 }
344 360 else if (*cfpod == ' ')
361 buf << '\n';
362 else
345 buf << ' '; 363 buf << ' ';
364
365 // verbatim block?
366 if (*cfpod == ' ')
367 goto verbatim;
368
346 break; 369 break;
347 370
348 case 'B': case 'C': case 'E': case 'G': 371 case 'B': case 'C': case 'E': case 'G':
349 case 'H': case 'I': case 'T': case 'U': 372 case 'H': case 'I': case 'T': case 'U':
350 case 'Z': 373 case 'Z':
351 { 374 {
352 int len = 0; 375 int end = 0;
353 376
354 while (cfpod [len] == '<') 377 while (cfpod [end] == '<')
355 ++len; 378 ++end;
356 379
357 if (!len) 380 if (!end)
358 goto passthrough; 381 goto passthrough;
359 382
360 if (len == 1 || cfpod [len] != ' ') 383 if (end == 1 || cfpod [end] != ' ')
361 { 384 {
362 len = 0; 385 end = -1;
363 ++cfpod; 386 ++cfpod;
364 } 387 }
365 else 388 else
366 cfpod += len + 1; 389 cfpod += end + 1;
367 390
368 const char *pfx, *sfx; 391 const char *pfx, *sfx;
369 392
370 switch (ch) 393 switch (ch)
371 { 394 {
373 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 396 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
374 case 'E': pfx = "&" ; sfx = ";" ; break; 397 case 'E': pfx = "&" ; sfx = ";" ; break;
375 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 398 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
376 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 399 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
377 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;
378 402
379 case 'H': // hint 403 case 'H': // hint
380 { 404 {
381 if (pl->hintmode) 405 if (pl->hintmode)
382 { 406 {
383 cfpod = expand_cfpod (pl, nest, cfpod, len); 407 cfpod = expand_cfpod (pl, nest, cfpod, end);
384 nest.clear (); 408 nest.clear ();
385 409
386 if (pl->hintmode == 1) 410 if (pl->hintmode == 1)
387 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 411 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
388 else 412 else
399 } 423 }
400 break; 424 break;
401 425
402 case 'G': // gender 426 case 'G': // gender
403 { 427 {
404 expand_cfpod (pl, nest, cfpod, len); 428 cfpod = expand_cfpod (pl, nest, cfpod, end);
405 nest << '\0'; // zero-terminate 429 nest << '\0'; // zero-terminate
406 430
407 const char *str = nest.linearise (); 431 const char *str = nest.linearise ();
408 const char *sep = strchr (str, '|'); 432 const char *sep = strchr (str, '|');
409 433
410 if (sep) 434 if (sep)
411 { 435 {
412 if (pl->gender || 1) 436 if (pl->gender)
413 buf.add (sep + 1, nest.size () - (sep - str) - 2); 437 buf.add (sep + 1, nest.size () - (sep - str) - 2);
414 else 438 else
415 buf.add (str, sep - str); 439 buf.add (str, sep - str);
416 } 440 }
417 441
420 goto skip; 444 goto skip;
421 } 445 }
422 } 446 }
423 447
424 buf << pfx; 448 buf << pfx;
425 cfpod = expand_cfpod (pl, buf, cfpod, len); 449 cfpod = expand_cfpod (pl, buf, cfpod, end);
426 buf << sfx; 450 buf << sfx;
427 } 451 }
428 452
429 break; 453 break;
430 454
431 default: 455 default:
432 passthrough: 456 passthrough:
433 buf << ch; 457 buf << ch;
434 skip: 458 skip:
435 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;
436 } 475 }
437} 476}
438 477
439dynbuf_text * 478dynbuf_text *
440player::expand_cfpod (const char *cfpod) const 479player::expand_cfpod (const char *cfpod) const
441{ 480{
442 static dynbuf_text buf(1024, 1024); 481 static dynbuf_text buf(1024, 1024);
443 buf.clear (); 482 buf.clear ();
444 483
445 ::expand_cfpod (this, buf, cfpod, -1); 484 ::expand_cfpod (this, buf, cfpod);
446 485
447 return &buf; 486 return &buf;
448} 487}
449 488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines