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.38 by root, Wed Apr 30 10:31:04 2008 UTC vs.
Revision 1.58 by root, Sat Nov 7 18:30:05 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
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);
83 PL_OUT (hintmode);
81 PL_OUT (gen_hp); 84 PL_OUT (gen_hp);
82 PL_OUT (gen_sp); 85 PL_OUT (gen_sp);
83 PL_OUT (gen_grace); 86 PL_OUT (gen_grace);
84 PL_OUT (listening);
85 PL_OUT (bowtype); 87 PL_OUT (bowtype);
86 PL_OUT (petmode); 88 PL_OUT (petmode);
87 PL_OUT (peaceful); 89 PL_OUT (peaceful);
88 PL_OUT (digestion); 90 PL_OUT (digestion);
89 PL_OUT2 (pickup, mode); 91 PL_OUT2 (pickup, mode);
133 INVOKE_PLAYER (SAVE_DONE, ob->contr); 135 INVOKE_PLAYER (SAVE_DONE, ob->contr);
134 136
135 return true; 137 return true;
136} 138}
137 139
140//-GPL
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;
142 146
190 case KW_password: assign (pl->password , f.get_str ()); break; 194 case KW_password: assign (pl->password , f.get_str ()); break;
191 case KW_title: assign (pl->own_title, f.get_str ()); break; 195 case KW_title: assign (pl->own_title, f.get_str ()); break;
192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 196 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 197 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
194 case KW_gender: f.get (pl->gender); break; 198 case KW_gender: f.get (pl->gender); break;
195 case KW_listening: f.get (pl->listening); break; 199 case KW_hintmode: f.get (pl->hintmode); break;
200 case KW_listening: /*TODO*/; break;
196 case KW_peaceful: f.get (pl->peaceful); break; 201 case KW_peaceful: f.get (pl->peaceful); break;
197 case KW_digestion: f.get (pl->digestion); break; 202 case KW_digestion: f.get (pl->digestion); break;
198 case KW_pickup: f.get (pl->mode); break; 203 case KW_pickup: f.get (pl->mode); break;
199 case KW_outputs_sync: f.get (pl->outputs_sync); break; 204 case KW_outputs_sync: f.get (pl->outputs_sync); break;
200 case KW_outputs_count: f.get (pl->outputs_count); break; 205 case KW_outputs_count: f.get (pl->outputs_count); break;
273 static char buf [2048]; 278 static char buf [2048];
274 279
275 if (!killer) 280 if (!killer)
276 return "a dungeon collapse"; 281 return "a dungeon collapse";
277 else if (killer->contr) 282 else if (killer->contr)
278 snprintf (buf, sizeof (buf), "%s the %s", &killer->name, &killer->title); 283 snprintf (buf, sizeof (buf), "%s the %s", &killer->name,
284 *killer->contr->own_title ? killer->contr->own_title : killer->contr->title);
279 else if (killer->type == DEEP_SWAMP) 285 else if (killer->type == DEEP_SWAMP)
280 snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name); 286 snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name);
281 else if (killer->owner) 287 else if (killer->owner)
282 snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name); 288 snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name);
283 else 289 else
284 return &killer->name; 290 return &killer->name;
285 291
286 return buf; 292 return buf;
287} 293}
288 294
295// expand one level of cfpod
296// end == -2, till '\n'
297// end == -1, till '>'
298// end == 0, till eos
299// end >= 1, levels of " >>>"
300static const char *
301expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
302{
303 static dynbuf_text nest(128, 128);
304
305 for (;;)
306 switch (char ch = *cfpod++)
307 {
308 case 0:
309 return cfpod - 1;
310
311 case ' ':
312 // verbatim block?
313 if (!buf.size () && !end)
314 {
315 --cfpod;
316 goto verbatim;
317 }
318
319 if (end < 1)
320 goto passthrough;
321
322 for (int i = 0; i < end; ++i)
323 if (cfpod [i] != '>')
324 goto passthrough;
325
326 return cfpod + end;
327
328 case '>':
329 if (end != -1)
330 {
331 buf << "&gt;";
332 break;
333 }
334
335 return cfpod;
336
337 case '&':
338 buf << "&amp;";
339 break;
340
341 case '<':
342 buf << "&lt;";
343 break;
344
345 case '\r':
346 buf << '\n';
347 /* \r\n+ becomes one or more newlines */
348 while (*cfpod == '\n')
349 buf << *cfpod++;
350 break;
351
352 case '\n':
353 if (end == -2)
354 return cfpod;
355
356 // \n\ => newline, tt
357 // \n\n => \n\n
358 // \n => single space
359
360 // two or more newlines will be copied verbatim, one is replaced by space
361 if (*cfpod == '\n')
362 {
363 --cfpod;
364 do
365 buf << *cfpod++;
366 while (*cfpod == '\n');
367 }
368 else if (*cfpod == ' ')
369 buf << '\n';
370 else
371 buf << ' ';
372
373 // verbatim block?
374 if (*cfpod == ' ')
375 goto verbatim;
376
377 break;
378
379 case 'B': case 'C': case 'E': case 'G':
380 case 'H': case 'I': case 'T': case 'U':
381 case 'Z':
382 {
383 int end = 0;
384
385 while (cfpod [end] == '<')
386 ++end;
387
388 if (!end)
389 goto passthrough;
390
391 if (end == 1 || cfpod [end] != ' ')
392 {
393 end = -1;
394 ++cfpod;
395 }
396 else
397 cfpod += end + 1;
398
399 const char *pfx, *sfx;
400
401 switch (ch)
402 {
403 case 'B': pfx = "<b>" ; sfx = "</b>" ; break;
404 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
405 case 'E': pfx = "&" ; sfx = ";" ; break;
406 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
407 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
408 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
409 case 'Z': pfx = "" ; sfx = "" ; break;
410
411 case 'H': // hint
412 {
413 if (pl->hintmode)
414 {
415 cfpod = expand_cfpod (pl, nest, cfpod, end);
416 nest.clear ();
417
418 if (pl->hintmode == 1)
419 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
420 else
421 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
422 ++cfpod;
423
424 goto skip;
425 }
426 else
427 {
428 pfx = "<fg name=\"lightblue\">[Hint: ";
429 sfx = "]</fg>";
430 }
431 }
432 break;
433
434 case 'G': // gender
435 {
436 cfpod = expand_cfpod (pl, nest, cfpod, end);
437 nest << '\0'; // zero-terminate
438
439 const char *str = nest.linearise ();
440 const char *sep = strchr (str, '|');
441
442 if (sep)
443 {
444 if (pl->gender)
445 buf.add (sep + 1, nest.size () - (sep - str) - 2);
446 else
447 buf.add (str, sep - str);
448 }
449
450 nest.clear ();
451
452 goto skip;
453 }
454
455 default:
456 pfx = "UNKNOWN_DIRECTIVE{";
457 sfx = "}";
458 break;
459 }
460
461 buf << pfx;
462 cfpod = expand_cfpod (pl, buf, cfpod, end);
463 buf << sfx;
464 }
465
466 break;
467
468 default:
469 passthrough:
470 buf << ch;
471 skip:
472 break;
473
474 verbatim:
475 // elements cannot currently span multiple lines
476 do
477 {
478 buf << "<tt>";
479 cfpod = expand_cfpod (pl, buf, cfpod, -2);
480 buf << "</tt>\n";
481
482 while (*cfpod == '\n')
483 buf << *cfpod++;
484 }
485 while (*cfpod == ' ');
486
487 break;
488 }
489}
490
491dynbuf_text *
492player::expand_cfpod (const char *cfpod) const
493{
494 static dynbuf_text buf(1024, 1024);
495 buf.clear ();
496
497 ::expand_cfpod (this, buf, cfpod);
498
499 return &buf;
500}
501

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines