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.55 by root, Mon Oct 12 14:00:57 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
46is_dragon_pl (const object *op) 47is_dragon_pl (const object *op)
47{ 48{
48 if (op 49 if (op
49 && op->type == PLAYER 50 && op->type == PLAYER
50 && op->arch 51 && op->arch
51 && op->arch->race 52 && op->arch->race == shstr_dragon)
52 && !strcmp (op->arch->race, "dragon"))
53 return 1; 53 return 1;
54 54
55 return 0; 55 return 0;
56} 56}
57 57
287 287
288 return buf; 288 return buf;
289} 289}
290 290
291// expand one level of cfpod 291// expand one level of cfpod
292// end == -2, till '\n'
293// end == -1, till '>'
292// end == -1, till eos 294// end == 0, till eos
293// end == 0, one level of '>'
294// end >= 1, this many levels of " >>>" 295// end >= 1, levels of " >>>"
295static const char * 296static const char *
296expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
297{ 298{
298 static dynbuf_text nest(128, 128); 299 static dynbuf_text nest(128, 128);
299 300
300 for (;;) 301 for (;;)
301 switch (char ch = *cfpod++) 302 switch (char ch = *cfpod++)
302 { 303 {
303 case 0: 304 case 0:
304 return cfpod - 1; 305 return cfpod - 1;
305 306
306 case ' ': 307 case ' ':
308 // verbatim block?
309 if (!buf.size () && !end)
310 {
311 --cfpod;
312 goto verbatim;
313 }
314
307 if (end <= 0) 315 if (end < 1)
308 goto passthrough; 316 goto passthrough;
309 317
310 for (int i = 0; i < end; ++i) 318 for (int i = 0; i < end; ++i)
311 if (cfpod [i] != '>') 319 if (cfpod [i] != '>')
312 goto passthrough; 320 goto passthrough;
313 321
314 return cfpod + end; 322 return cfpod + end;
315 323
316 case '>': 324 case '>':
317 if (end) 325 if (end != -1)
318 { 326 {
319 buf << "&gt;"; 327 buf << "&gt;";
320 break; 328 break;
321 } 329 }
322 330
328 336
329 case '<': 337 case '<':
330 buf << "&lt;"; 338 buf << "&lt;";
331 break; 339 break;
332 340
341 case '\r':
342 buf << '\n';
343 /* \r\n+ becomes one or more newlines */
344 while (*cfpod == '\n')
345 buf << *cfpod++;
346 break;
347
333 case '\n': 348 case '\n':
349 if (end == -2)
350 return cfpod;
351
352 // \n\ => newline, tt
353 // \n\n => \n\n
354 // \n => single space
355
356 // two or more newlines will be copied verbatim, one is replaced by space
334 if (*cfpod == ' ') 357 if (*cfpod == '\n')
335 goto passthrough;
336 else if (*cfpod == '\n')
337 { 358 {
338 --cfpod; 359 --cfpod;
339 while (*cfpod == '\n') 360 do
340 buf << *cfpod++; 361 buf << *cfpod++;
341 362 while (*cfpod == '\n');
342 goto skip;
343 } 363 }
344 364 else if (*cfpod == ' ')
365 buf << '\n';
366 else
345 buf << ' '; 367 buf << ' ';
368
369 // verbatim block?
370 if (*cfpod == ' ')
371 goto verbatim;
372
346 break; 373 break;
347 374
348 case 'B': case 'C': case 'E': case 'G': 375 case 'B': case 'C': case 'E': case 'G':
349 case 'H': case 'I': case 'T': case 'U': 376 case 'H': case 'I': case 'T': case 'U':
350 case 'Z': 377 case 'Z':
351 { 378 {
352 int len = 0; 379 int end = 0;
353 380
354 while (cfpod [len] == '<') 381 while (cfpod [end] == '<')
355 ++len; 382 ++end;
356 383
357 if (!len) 384 if (!end)
358 goto passthrough; 385 goto passthrough;
359 386
360 if (len == 1 || cfpod [len] != ' ') 387 if (end == 1 || cfpod [end] != ' ')
361 { 388 {
362 len = 0; 389 end = -1;
363 ++cfpod; 390 ++cfpod;
364 } 391 }
365 else 392 else
366 cfpod += len + 1; 393 cfpod += end + 1;
367 394
368 const char *pfx, *sfx; 395 const char *pfx, *sfx;
369 396
370 switch (ch) 397 switch (ch)
371 { 398 {
373 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
374 case 'E': pfx = "&" ; sfx = ";" ; break; 401 case 'E': pfx = "&" ; sfx = ";" ; break;
375 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
376 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
377 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
405 case 'Z': pfx = "" ; sfx = "" ; break;
378 406
379 case 'H': // hint 407 case 'H': // hint
380 { 408 {
381 if (pl->hintmode) 409 if (pl->hintmode)
382 { 410 {
383 cfpod = expand_cfpod (pl, nest, cfpod, len); 411 cfpod = expand_cfpod (pl, nest, cfpod, end);
384 nest.clear (); 412 nest.clear ();
385 413
386 if (pl->hintmode == 1) 414 if (pl->hintmode == 1)
387 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 415 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
388 else 416 else
389 while (*cfpod == ' ') // eat trailing whitespace 417 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
390 ++cfpod; 418 ++cfpod;
391 419
392 goto skip; 420 goto skip;
393 } 421 }
394 else 422 else
395 { 423 {
396 pfx = "<fg name=\"lightblue\">["; 424 pfx = "<fg name=\"lightblue\">[Hint: ";
397 sfx = " (Use hintmode to suppress hints)]</fg>"; 425 sfx = "]</fg>";
398 } 426 }
399 } 427 }
400 break; 428 break;
401 429
402 case 'G': // gender 430 case 'G': // gender
403 { 431 {
404 expand_cfpod (pl, nest, cfpod, len); 432 cfpod = expand_cfpod (pl, nest, cfpod, end);
405 nest << '\0'; // zero-terminate 433 nest << '\0'; // zero-terminate
406 434
407 const char *str = nest.linearise (); 435 const char *str = nest.linearise ();
408 const char *sep = strchr (str, '|'); 436 const char *sep = strchr (str, '|');
409 437
410 if (sep) 438 if (sep)
411 { 439 {
412 if (pl->gender || 1) 440 if (pl->gender)
413 buf.add (sep + 1, nest.size () - (sep - str) - 2); 441 buf.add (sep + 1, nest.size () - (sep - str) - 2);
414 else 442 else
415 buf.add (str, sep - str); 443 buf.add (str, sep - str);
416 } 444 }
417 445
420 goto skip; 448 goto skip;
421 } 449 }
422 } 450 }
423 451
424 buf << pfx; 452 buf << pfx;
425 cfpod = expand_cfpod (pl, buf, cfpod, len); 453 cfpod = expand_cfpod (pl, buf, cfpod, end);
426 buf << sfx; 454 buf << sfx;
427 } 455 }
428 456
429 break; 457 break;
430 458
431 default: 459 default:
432 passthrough: 460 passthrough:
433 buf << ch; 461 buf << ch;
434 skip: 462 skip:
435 break; 463 break;
464
465 verbatim:
466 // elements cannot currently span multiple lines
467 do
468 {
469 buf << "<tt>";
470 cfpod = expand_cfpod (pl, buf, cfpod, -2);
471 buf << "</tt>\n";
472
473 while (*cfpod == '\n')
474 buf << *cfpod++;
475 }
476 while (*cfpod == ' ');
477
478 break;
436 } 479 }
437} 480}
438 481
439dynbuf_text * 482dynbuf_text *
440player::expand_cfpod (const char *cfpod) const 483player::expand_cfpod (const char *cfpod) const
441{ 484{
442 static dynbuf_text buf(1024, 1024); 485 static dynbuf_text buf(1024, 1024);
443 buf.clear (); 486 buf.clear ();
444 487
445 ::expand_cfpod (this, buf, cfpod, -1); 488 ::expand_cfpod (this, buf, cfpod);
446 489
447 return &buf; 490 return &buf;
448} 491}
449 492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines