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.43 by root, Mon Sep 8 18:34:35 2008 UTC vs.
Revision 1.57 by root, Thu Nov 5 15:43:21 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>
26
27//+GPL
25 28
26/* Determine if the attacktype represented by the 29/* Determine if the attacktype represented by the
27 * specified attack-number is enabled for dragon players. 30 * specified attack-number is enabled for dragon players.
28 * A dragon player (quetzal) can gain resistances for 31 * A dragon player (quetzal) can gain resistances for
29 * all enabled attacktypes. 32 * all enabled attacktypes.
46is_dragon_pl (const object *op) 49is_dragon_pl (const object *op)
47{ 50{
48 if (op 51 if (op
49 && op->type == PLAYER 52 && op->type == PLAYER
50 && op->arch 53 && op->arch
51 && op->arch->race 54 && op->arch->race == shstr_dragon)
52 && !strcmp (op->arch->race, "dragon"))
53 return 1; 55 return 1;
54 56
55 return 0; 57 return 0;
56} 58}
57 59
64 INVOKE_PLAYER (SAVE, ob->contr); 66 INVOKE_PLAYER (SAVE, ob->contr);
65 67
66 int wiz = ob->flag [FLAG_WIZ]; 68 int wiz = ob->flag [FLAG_WIZ];
67 69
68 /* Eneq(@csd.uu.se): If we have an open container hide it. */ 70 /* Eneq(@csd.uu.se): If we have an open container hide it. */
69 object *container = ob->container; 71 object *container = ob->container_ ();
70 ob->container = 0; 72 ob->container = 0;
71 73
72 if (ob->map) 74 if (ob->map)
73 maplevel = ob->map->path; 75 maplevel = ob->map->path;
74 76
132 134
133 INVOKE_PLAYER (SAVE_DONE, ob->contr); 135 INVOKE_PLAYER (SAVE_DONE, ob->contr);
134 136
135 return true; 137 return true;
136} 138}
139
140//-GPL
137 141
138bool 142bool
139player::save_pl (const char *path) 143player::save_pl (const char *path)
140{ 144{
141 object_freezer freezer; 145 object_freezer freezer;
292// end == -2, till '\n' 296// end == -2, till '\n'
293// end == -1, till '>' 297// end == -1, till '>'
294// end == 0, till eos 298// end == 0, till eos
295// end >= 1, levels of " >>>" 299// end >= 1, levels of " >>>"
296static const char * 300static const char *
297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 301expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
298{ 302{
299 static dynbuf_text nest(128, 128); 303 static dynbuf_text nest(128, 128);
300 304
301 for (;;) 305 for (;;)
302 switch (char ch = *cfpod++) 306 switch (char ch = *cfpod++)
303 { 307 {
304 case 0: 308 case 0:
305 return cfpod - 1; 309 return cfpod - 1;
306 310
307 case ' ': 311 case ' ':
312 // verbatim block?
313 if (!buf.size () && !end)
314 {
315 --cfpod;
316 goto verbatim;
317 }
318
308 if (end < 1) 319 if (end < 1)
309 goto passthrough; 320 goto passthrough;
310 321
311 for (int i = 0; i < end; ++i) 322 for (int i = 0; i < end; ++i)
312 if (cfpod [i] != '>') 323 if (cfpod [i] != '>')
331 buf << "&lt;"; 342 buf << "&lt;";
332 break; 343 break;
333 344
334 case '\r': 345 case '\r':
335 buf << '\n'; 346 buf << '\n';
347 /* \r\n+ becomes one or more newlines */
348 while (*cfpod == '\n')
349 buf << *cfpod++;
336 break; 350 break;
337 351
338 case '\n': 352 case '\n':
339 if (end == -2) 353 if (end == -2)
340 return cfpod; 354 return cfpod;
349 --cfpod; 363 --cfpod;
350 do 364 do
351 buf << *cfpod++; 365 buf << *cfpod++;
352 while (*cfpod == '\n'); 366 while (*cfpod == '\n');
353 } 367 }
354 else if (*cfpod != ' ') 368 else if (*cfpod == ' ')
369 buf << '\n';
370 else
355 buf << ' '; 371 buf << ' ';
356 372
357 // start verbatim block's? 373 // verbatim block?
358 if (*cfpod == ' ') 374 if (*cfpod == ' ')
359 { 375 goto verbatim;
360 // elements cannot currently span multiple lines
361 do
362 {
363 buf << "<tt>";
364 cfpod = expand_cfpod (pl, buf, cfpod, -2);
365 buf << "</tt>\n";
366 }
367 while (*cfpod == ' ');
368
369 while (*cfpod == '\n')
370 buf << *cfpod++;
371 }
372 376
373 break; 377 break;
374 378
375 case 'B': case 'C': case 'E': case 'G': 379 case 'B': case 'C': case 'E': case 'G':
376 case 'H': case 'I': case 'T': case 'U': 380 case 'H': case 'I': case 'T': case 'U':
400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 404 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
401 case 'E': pfx = "&" ; sfx = ";" ; break; 405 case 'E': pfx = "&" ; sfx = ";" ; break;
402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 406 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 407 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 408 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
409 case 'Z': pfx = "" ; sfx = "" ; break;
405 410
406 case 'H': // hint 411 case 'H': // hint
407 { 412 {
408 if (pl->hintmode) 413 if (pl->hintmode)
409 { 414 {
410 cfpod = expand_cfpod (pl, nest, cfpod, end); 415 cfpod = expand_cfpod (pl, nest, cfpod, end);
411 nest.clear (); 416 nest.clear ();
412 417
413 if (pl->hintmode == 1) 418 if (pl->hintmode == 1)
414 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 419 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
415 else 420 else
416 while (*cfpod == ' ') // eat trailing whitespace 421 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
417 ++cfpod; 422 ++cfpod;
418 423
419 goto skip; 424 goto skip;
420 } 425 }
421 else 426 else
422 { 427 {
423 pfx = "<fg name=\"lightblue\">["; 428 pfx = "<fg name=\"lightblue\">[Hint: ";
424 sfx = " (Use hintmode to suppress hints)]</fg>"; 429 sfx = "]</fg>";
425 } 430 }
426 } 431 }
427 break; 432 break;
428 433
429 case 'G': // gender 434 case 'G': // gender
430 { 435 {
431 expand_cfpod (pl, nest, cfpod, end); 436 cfpod = expand_cfpod (pl, nest, cfpod, end);
432 nest << '\0'; // zero-terminate 437 nest << '\0'; // zero-terminate
433 438
434 const char *str = nest.linearise (); 439 const char *str = nest.linearise ();
435 const char *sep = strchr (str, '|'); 440 const char *sep = strchr (str, '|');
436 441
437 if (sep) 442 if (sep)
438 { 443 {
439 if (pl->gender || 1) 444 if (pl->gender)
440 buf.add (sep + 1, nest.size () - (sep - str) - 2); 445 buf.add (sep + 1, nest.size () - (sep - str) - 2);
441 else 446 else
442 buf.add (str, sep - str); 447 buf.add (str, sep - str);
443 } 448 }
444 449
458 default: 463 default:
459 passthrough: 464 passthrough:
460 buf << ch; 465 buf << ch;
461 skip: 466 skip:
462 break; 467 break;
468
469 verbatim:
470 // elements cannot currently span multiple lines
471 do
472 {
473 buf << "<tt>";
474 cfpod = expand_cfpod (pl, buf, cfpod, -2);
475 buf << "</tt>\n";
476
477 while (*cfpod == '\n')
478 buf << *cfpod++;
479 }
480 while (*cfpod == ' ');
481
482 break;
463 } 483 }
464} 484}
465 485
466dynbuf_text * 486dynbuf_text *
467player::expand_cfpod (const char *cfpod) const 487player::expand_cfpod (const char *cfpod) const
468{ 488{
469 static dynbuf_text buf(1024, 1024); 489 static dynbuf_text buf(1024, 1024);
470 buf.clear (); 490 buf.clear ();
471 491
472 ::expand_cfpod (this, buf, cfpod, 0); 492 ::expand_cfpod (this, buf, cfpod);
473 493
474 return &buf; 494 return &buf;
475} 495}
476 496

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines