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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines