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.40 by root, Fri Aug 29 02:07:09 2008 UTC vs.
Revision 1.56 by root, Mon Oct 19 21:48:49 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
64 INVOKE_PLAYER (SAVE, ob->contr); 64 INVOKE_PLAYER (SAVE, ob->contr);
65 65
66 int wiz = ob->flag [FLAG_WIZ]; 66 int wiz = ob->flag [FLAG_WIZ];
67 67
68 /* Eneq(@csd.uu.se): If we have an open container hide it. */ 68 /* Eneq(@csd.uu.se): If we have an open container hide it. */
69 object *container = ob->container; 69 object *container = ob->container_ ();
70 ob->container = 0; 70 ob->container = 0;
71 71
72 if (ob->map) 72 if (ob->map)
73 maplevel = ob->map->path; 73 maplevel = ob->map->path;
74 74
76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
77 77
78 PL_OUT (password); 78 PL_OUT (password);
79 PL_OUT2 (title, own_title); 79 PL_OUT2 (title, own_title);
80 PL_OUT (gender); 80 PL_OUT (gender);
81 PL_OUT (hintmode);
81 PL_OUT (gen_hp); 82 PL_OUT (gen_hp);
82 PL_OUT (gen_sp); 83 PL_OUT (gen_sp);
83 PL_OUT (gen_grace); 84 PL_OUT (gen_grace);
84 PL_OUT (bowtype); 85 PL_OUT (bowtype);
85 PL_OUT (petmode); 86 PL_OUT (petmode);
189 case KW_password: assign (pl->password , f.get_str ()); break; 190 case KW_password: assign (pl->password , f.get_str ()); break;
190 case KW_title: assign (pl->own_title, f.get_str ()); break; 191 case KW_title: assign (pl->own_title, f.get_str ()); break;
191 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
192 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
193 case KW_gender: f.get (pl->gender); break; 194 case KW_gender: f.get (pl->gender); break;
195 case KW_hintmode: f.get (pl->hintmode); break;
194 case KW_listening: /*TODO*/; break; 196 case KW_listening: /*TODO*/; break;
195 case KW_peaceful: f.get (pl->peaceful); break; 197 case KW_peaceful: f.get (pl->peaceful); break;
196 case KW_digestion: f.get (pl->digestion); break; 198 case KW_digestion: f.get (pl->digestion); break;
197 case KW_pickup: f.get (pl->mode); break; 199 case KW_pickup: f.get (pl->mode); break;
198 case KW_outputs_sync: f.get (pl->outputs_sync); break; 200 case KW_outputs_sync: f.get (pl->outputs_sync); break;
284 return &killer->name; 286 return &killer->name;
285 287
286 return buf; 288 return buf;
287} 289}
288 290
291// expand one level of cfpod
292// end == -2, till '\n'
293// end == -1, till '>'
294// end == 0, till eos
295// end >= 1, levels of " >>>"
296static const char *
297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
298{
299 static dynbuf_text nest(128, 128);
300
301 for (;;)
302 switch (char ch = *cfpod++)
303 {
304 case 0:
305 return cfpod - 1;
306
307 case ' ':
308 // verbatim block?
309 if (!buf.size () && !end)
310 {
311 --cfpod;
312 goto verbatim;
313 }
314
315 if (end < 1)
316 goto passthrough;
317
318 for (int i = 0; i < end; ++i)
319 if (cfpod [i] != '>')
320 goto passthrough;
321
322 return cfpod + end;
323
324 case '>':
325 if (end != -1)
326 {
327 buf << "&gt;";
328 break;
329 }
330
331 return cfpod;
332
333 case '&':
334 buf << "&amp;";
335 break;
336
337 case '<':
338 buf << "&lt;";
339 break;
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
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
357 if (*cfpod == '\n')
358 {
359 --cfpod;
360 do
361 buf << *cfpod++;
362 while (*cfpod == '\n');
363 }
364 else if (*cfpod == ' ')
365 buf << '\n';
366 else
367 buf << ' ';
368
369 // verbatim block?
370 if (*cfpod == ' ')
371 goto verbatim;
372
373 break;
374
375 case 'B': case 'C': case 'E': case 'G':
376 case 'H': case 'I': case 'T': case 'U':
377 case 'Z':
378 {
379 int end = 0;
380
381 while (cfpod [end] == '<')
382 ++end;
383
384 if (!end)
385 goto passthrough;
386
387 if (end == 1 || cfpod [end] != ' ')
388 {
389 end = -1;
390 ++cfpod;
391 }
392 else
393 cfpod += end + 1;
394
395 const char *pfx, *sfx;
396
397 switch (ch)
398 {
399 case 'B': pfx = "<b>" ; sfx = "</b>" ; break;
400 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
401 case 'E': pfx = "&" ; sfx = ";" ; break;
402 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
403 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
404 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
405 case 'Z': pfx = "" ; sfx = "" ; break;
406
407 case 'H': // hint
408 {
409 if (pl->hintmode)
410 {
411 cfpod = expand_cfpod (pl, nest, cfpod, end);
412 nest.clear ();
413
414 if (pl->hintmode == 1)
415 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
416 else
417 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
418 ++cfpod;
419
420 goto skip;
421 }
422 else
423 {
424 pfx = "<fg name=\"lightblue\">[Hint: ";
425 sfx = "]</fg>";
426 }
427 }
428 break;
429
430 case 'G': // gender
431 {
432 cfpod = expand_cfpod (pl, nest, cfpod, end);
433 nest << '\0'; // zero-terminate
434
435 const char *str = nest.linearise ();
436 const char *sep = strchr (str, '|');
437
438 if (sep)
439 {
440 if (pl->gender)
441 buf.add (sep + 1, nest.size () - (sep - str) - 2);
442 else
443 buf.add (str, sep - str);
444 }
445
446 nest.clear ();
447
448 goto skip;
449 }
450 }
451
452 buf << pfx;
453 cfpod = expand_cfpod (pl, buf, cfpod, end);
454 buf << sfx;
455 }
456
457 break;
458
459 default:
460 passthrough:
461 buf << ch;
462 skip:
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;
479 }
480}
481
482dynbuf_text *
483player::expand_cfpod (const char *cfpod) const
484{
485 static dynbuf_text buf(1024, 1024);
486 buf.clear ();
487
488 ::expand_cfpod (this, buf, cfpod);
489
490 return &buf;
491}
492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines