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.60 by root, Wed Nov 11 23:27:56 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
75#define PL_OUT(k) freezer.put (KW_ ## k, k) 77#define PL_OUT(k) freezer.put (KW(k), k)
76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 78#define PL_OUT2(k,v) freezer.put (KW(k), v)
77 79
78 PL_OUT (password); 80 PL_OUT (password);
79 PL_OUT2 (title, own_title); 81 PL_OUT2 (title, own_title);
80 PL_OUT (gender); 82 PL_OUT (gender);
81 PL_OUT (hintmode); 83 PL_OUT (hintmode);
88 PL_OUT (digestion); 90 PL_OUT (digestion);
89 PL_OUT2 (pickup, mode); 91 PL_OUT2 (pickup, mode);
90 PL_OUT (outputs_sync); 92 PL_OUT (outputs_sync);
91 PL_OUT (outputs_count); 93 PL_OUT (outputs_count);
92 94
93 freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers")); 95 freezer.put (KW(usekeys), usekeys == key_inventory ? CS(key_inventory) : (usekeys == keyrings ? CS(keyrings) : CS(containers)));
94 freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always")); 96 freezer.put (KW(unapply), unapply == unapply_nochoice ? CS(unapply_nochoice) : (unapply == unapply_never ? CS(unapply_never) : CS(unapply_always)));
95 97
96 PL_OUT2 (map, maplevel); 98 PL_OUT2 (map, maplevel);
97 PL_OUT (savebed_map); 99 PL_OUT (savebed_map);
98 PL_OUT (bed_x); 100 PL_OUT (bed_x);
99 PL_OUT (bed_y); 101 PL_OUT (bed_y);
115 freezer.add (levsp [i]); freezer.add ('\n'); 117 freezer.add (levsp [i]); freezer.add ('\n');
116 freezer.add (levgrace[i]); freezer.add ('\n'); 118 freezer.add (levgrace[i]); freezer.add ('\n');
117 } 119 }
118 120
119 freezer.put (ob->contr); 121 freezer.put (ob->contr);
120 freezer.put (KW_endplst); 122 freezer.put (KW(endplst));
121 123
122 SET_FLAG (ob, FLAG_NO_FIX_PLAYER);
123 CLEAR_FLAG (ob, FLAG_WIZ); 124 CLEAR_FLAG (ob, FLAG_WIZ);
124 ob->write (freezer); 125 ob->write (freezer);
125 126
126 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
127
128 /* Eneq(@csd.uu.se): Reveal the container if we have one. */ 127 /* Eneq(@csd.uu.se): Reveal the container if we have one. */
129 ob->container = container; 128 ob->container = container;
130 129
131 ob->flag [FLAG_WIZ] = wiz; 130 ob->flag [FLAG_WIZ] = wiz;
132 131
133 INVOKE_PLAYER (SAVE_DONE, ob->contr); 132 INVOKE_PLAYER (SAVE_DONE, ob->contr);
134 133
135 return true; 134 return true;
136} 135}
136
137//-GPL
137 138
138bool 139bool
139player::save_pl (const char *path) 140player::save_pl (const char *path)
140{ 141{
141 object_freezer freezer; 142 object_freezer freezer;
292// end == -2, till '\n' 293// end == -2, till '\n'
293// end == -1, till '>' 294// end == -1, till '>'
294// end == 0, till eos 295// end == 0, till eos
295// end >= 1, levels of " >>>" 296// end >= 1, levels of " >>>"
296static const char * 297static const char *
297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 298expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
298{ 299{
299 static dynbuf_text nest(128, 128); 300 static dynbuf_text nest(128, 128);
300 301
301 for (;;) 302 for (;;)
302 switch (char ch = *cfpod++) 303 switch (char ch = *cfpod++)
303 { 304 {
304 case 0: 305 case 0:
305 return cfpod - 1; 306 return cfpod - 1;
306 307
307 case ' ': 308 case ' ':
309 // verbatim block?
310 if (!buf.size () && !end)
311 {
312 --cfpod;
313 goto verbatim;
314 }
315
308 if (end < 1) 316 if (end < 1)
309 goto passthrough; 317 goto passthrough;
310 318
311 for (int i = 0; i < end; ++i) 319 for (int i = 0; i < end; ++i)
312 if (cfpod [i] != '>') 320 if (cfpod [i] != '>')
331 buf << "&lt;"; 339 buf << "&lt;";
332 break; 340 break;
333 341
334 case '\r': 342 case '\r':
335 buf << '\n'; 343 buf << '\n';
344 /* \r\n+ becomes one or more newlines */
345 while (*cfpod == '\n')
346 buf << *cfpod++;
336 break; 347 break;
337 348
338 case '\n': 349 case '\n':
339 if (end == -2) 350 if (end == -2)
340 return cfpod; 351 return cfpod;
349 --cfpod; 360 --cfpod;
350 do 361 do
351 buf << *cfpod++; 362 buf << *cfpod++;
352 while (*cfpod == '\n'); 363 while (*cfpod == '\n');
353 } 364 }
354 else if (*cfpod != ' ') 365 else if (*cfpod == ' ')
366 buf << '\n';
367 else
355 buf << ' '; 368 buf << ' ';
356 369
357 // start verbatim block's? 370 // verbatim block?
358 if (*cfpod == ' ') 371 if (*cfpod == ' ')
359 { 372 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 373
373 break; 374 break;
374 375
375 case 'B': case 'C': case 'E': case 'G': 376 case 'B': case 'C': case 'E': case 'G':
376 case 'H': case 'I': case 'T': case 'U': 377 case 'H': case 'I': case 'T': case 'U':
400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; 401 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
401 case 'E': pfx = "&" ; sfx = ";" ; break; 402 case 'E': pfx = "&" ; sfx = ";" ; break;
402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 403 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 404 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 405 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
406 case 'Z': pfx = "" ; sfx = "" ; break;
405 407
406 case 'H': // hint 408 case 'H': // hint
407 { 409 {
408 if (pl->hintmode) 410 if (pl->hintmode)
409 { 411 {
410 cfpod = expand_cfpod (pl, nest, cfpod, end); 412 cfpod = expand_cfpod (pl, nest, cfpod, end);
411 nest.clear (); 413 nest.clear ();
412 414
413 if (pl->hintmode == 1) 415 if (pl->hintmode == 1)
414 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 416 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
415 else 417 else
416 while (*cfpod == ' ') // eat trailing whitespace 418 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
417 ++cfpod; 419 ++cfpod;
418 420
419 goto skip; 421 goto skip;
420 } 422 }
421 else 423 else
422 { 424 {
423 pfx = "<fg name=\"lightblue\">["; 425 pfx = "<fg name=\"lightblue\">[Hint: ";
424 sfx = " (Use hintmode to suppress hints)]</fg>"; 426 sfx = "]</fg>";
425 } 427 }
426 } 428 }
427 break; 429 break;
428 430
429 case 'G': // gender 431 case 'G': // gender
430 { 432 {
431 expand_cfpod (pl, nest, cfpod, end); 433 cfpod = expand_cfpod (pl, nest, cfpod, end);
432 nest << '\0'; // zero-terminate 434 nest << '\0'; // zero-terminate
433 435
434 const char *str = nest.linearise (); 436 const char *str = nest.linearise ();
435 const char *sep = strchr (str, '|'); 437 const char *sep = strchr (str, '|');
436 438
437 if (sep) 439 if (sep)
438 { 440 {
439 if (pl->gender || 1) 441 if (pl->gender)
440 buf.add (sep + 1, nest.size () - (sep - str) - 2); 442 buf.add (sep + 1, nest.size () - (sep - str) - 2);
441 else 443 else
442 buf.add (str, sep - str); 444 buf.add (str, sep - str);
443 } 445 }
444 446
445 nest.clear (); 447 nest.clear ();
446 448
447 goto skip; 449 goto skip;
448 } 450 }
451
452 default:
453 pfx = "UNKNOWN_DIRECTIVE{";
454 sfx = "}";
455 break;
449 } 456 }
450 457
451 buf << pfx; 458 buf << pfx;
452 cfpod = expand_cfpod (pl, buf, cfpod, end); 459 cfpod = expand_cfpod (pl, buf, cfpod, end);
453 buf << sfx; 460 buf << sfx;
458 default: 465 default:
459 passthrough: 466 passthrough:
460 buf << ch; 467 buf << ch;
461 skip: 468 skip:
462 break; 469 break;
470
471 verbatim:
472 // elements cannot currently span multiple lines
473 do
474 {
475 buf << "<tt>";
476 cfpod = expand_cfpod (pl, buf, cfpod, -2);
477 buf << "</tt>\n";
478
479 while (*cfpod == '\n')
480 buf << *cfpod++;
481 }
482 while (*cfpod == ' ');
483
484 break;
463 } 485 }
464} 486}
465 487
466dynbuf_text * 488dynbuf_text *
467player::expand_cfpod (const char *cfpod) const 489player::expand_cfpod (const char *cfpod) const
468{ 490{
469 static dynbuf_text buf(1024, 1024); 491 static dynbuf_text buf(1024, 1024);
470 buf.clear (); 492 buf.clear ();
471 493
472 ::expand_cfpod (this, buf, cfpod, 0); 494 ::expand_cfpod (this, buf, cfpod);
473 495
474 return &buf; 496 return &buf;
475} 497}
476 498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines