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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines