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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines