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.50 by root, Thu Jan 8 00:54:55 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 {
382 401
383 case 'H': // hint 402 case 'H': // hint
384 { 403 {
385 if (pl->hintmode) 404 if (pl->hintmode)
386 { 405 {
387 cfpod = expand_cfpod (pl, nest, cfpod, len); 406 cfpod = expand_cfpod (pl, nest, cfpod, end);
388 nest.clear (); 407 nest.clear ();
389 408
390 if (pl->hintmode == 1) 409 if (pl->hintmode == 1)
391 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 410 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
392 else 411 else
403 } 422 }
404 break; 423 break;
405 424
406 case 'G': // gender 425 case 'G': // gender
407 { 426 {
408 expand_cfpod (pl, nest, cfpod, len); 427 cfpod = expand_cfpod (pl, nest, cfpod, end);
409 nest << '\0'; // zero-terminate 428 nest << '\0'; // zero-terminate
410 429
411 const char *str = nest.linearise (); 430 const char *str = nest.linearise ();
412 const char *sep = strchr (str, '|'); 431 const char *sep = strchr (str, '|');
413 432
414 if (sep) 433 if (sep)
415 { 434 {
416 if (pl->gender || 1) 435 if (pl->gender)
417 buf.add (sep + 1, nest.size () - (sep - str) - 2); 436 buf.add (sep + 1, nest.size () - (sep - str) - 2);
418 else 437 else
419 buf.add (str, sep - str); 438 buf.add (str, sep - str);
420 } 439 }
421 440
424 goto skip; 443 goto skip;
425 } 444 }
426 } 445 }
427 446
428 buf << pfx; 447 buf << pfx;
429 cfpod = expand_cfpod (pl, buf, cfpod, len); 448 cfpod = expand_cfpod (pl, buf, cfpod, end);
430 buf << sfx; 449 buf << sfx;
431 } 450 }
432 451
433 break; 452 break;
434 453
435 default: 454 default:
436 passthrough: 455 passthrough:
437 buf << ch; 456 buf << ch;
438 skip: 457 skip:
439 break; 458 break;
459
460 verbatim:
461 // elements cannot currently span multiple lines
462 do
463 {
464 buf << "<tt>";
465 cfpod = expand_cfpod (pl, buf, cfpod, -2);
466 buf << "</tt>\n";
467
468 while (*cfpod == '\n')
469 buf << *cfpod++;
470 }
471 while (*cfpod == ' ');
472
473 break;
440 } 474 }
441} 475}
442 476
443dynbuf_text * 477dynbuf_text *
444player::expand_cfpod (const char *cfpod) const 478player::expand_cfpod (const char *cfpod) const
445{ 479{
446 static dynbuf_text buf(1024, 1024); 480 static dynbuf_text buf(1024, 1024);
447 buf.clear (); 481 buf.clear ();
448 482
449 ::expand_cfpod (this, buf, cfpod, -1); 483 ::expand_cfpod (this, buf, cfpod);
450 484
451 return &buf; 485 return &buf;
452} 486}
453 487

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines