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.30 by root, Mon May 28 21:21:40 2007 UTC vs.
Revision 1.58 by root, Sat Nov 7 18:30:05 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * under the terms of the GNU General Public License as published by the Free 9 * the terms of the Affero GNU General Public License as published by the
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * 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 along 18 * You should have received a copy of the Affero GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26
27//+GPL
27 28
28/* Determine if the attacktype represented by the 29/* Determine if the attacktype represented by the
29 * specified attack-number is enabled for dragon players. 30 * specified attack-number is enabled for dragon players.
30 * A dragon player (quetzal) can gain resistances for 31 * A dragon player (quetzal) can gain resistances for
31 * all enabled attacktypes. 32 * all enabled attacktypes.
48is_dragon_pl (const object *op) 49is_dragon_pl (const object *op)
49{ 50{
50 if (op 51 if (op
51 && op->type == PLAYER 52 && op->type == PLAYER
52 && op->arch 53 && op->arch
53 && op->arch->clone.race 54 && op->arch->race == shstr_dragon)
54 && !strcmp (op->arch->clone.race, "dragon"))
55 return 1; 55 return 1;
56 56
57 return 0; 57 return 0;
58} 58}
59 59
66 INVOKE_PLAYER (SAVE, ob->contr); 66 INVOKE_PLAYER (SAVE, ob->contr);
67 67
68 int wiz = ob->flag [FLAG_WIZ]; 68 int wiz = ob->flag [FLAG_WIZ];
69 69
70 /* 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. */
71 object *container = ob->container; 71 object *container = ob->container_ ();
72 ob->container = 0; 72 ob->container = 0;
73 73
74 if (ob->map) 74 if (ob->map)
75 maplevel = ob->map->path; 75 maplevel = ob->map->path;
76 76
77#define PL_OUT(k) freezer.put (KW_ ## k, k) 77#define PL_OUT(k) freezer.put (KW_ ## k, k)
78#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 78#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
79 79
80 PL_OUT (password); 80 PL_OUT (password);
81 PL_OUT2 (title, own_title); 81 PL_OUT2 (title, own_title);
82 PL_OUT (gender);
83 PL_OUT (hintmode);
82 PL_OUT (gen_hp); 84 PL_OUT (gen_hp);
83 PL_OUT (gen_sp); 85 PL_OUT (gen_sp);
84 PL_OUT (gen_grace); 86 PL_OUT (gen_grace);
85 PL_OUT (listening);
86 PL_OUT (bowtype); 87 PL_OUT (bowtype);
87 PL_OUT (petmode); 88 PL_OUT (petmode);
88 PL_OUT (peaceful); 89 PL_OUT (peaceful);
89 PL_OUT (digestion); 90 PL_OUT (digestion);
90 PL_OUT2 (pickup, mode); 91 PL_OUT2 (pickup, mode);
134 INVOKE_PLAYER (SAVE_DONE, ob->contr); 135 INVOKE_PLAYER (SAVE_DONE, ob->contr);
135 136
136 return true; 137 return true;
137} 138}
138 139
140//-GPL
141
139bool 142bool
140player::save_pl (const char *path) 143player::save_pl (const char *path)
141{ 144{
142 object_freezer freezer; 145 object_freezer freezer;
143 146
190 case KW_oid: f.get (pl, f.get_sint32 ()); break; 193 case KW_oid: f.get (pl, f.get_sint32 ()); break;
191 case KW_password: assign (pl->password , f.get_str ()); break; 194 case KW_password: assign (pl->password , f.get_str ()); break;
192 case KW_title: assign (pl->own_title, f.get_str ()); break; 195 case KW_title: assign (pl->own_title, f.get_str ()); break;
193 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 196 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
194 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 197 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
195 case KW_listening: f.get (pl->listening); break; 198 case KW_gender: f.get (pl->gender); 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;
265 pl->destroy (); 270 pl->destroy ();
266 271
267 return 0; 272 return 0;
268} 273}
269 274
270player * 275const char *
271player::load_pl (const char *path) 276player::killer_name () const
272{ 277{
273 object_thawer f (path); 278 static char buf [2048];
274 279
275 if (!f) 280 if (!killer)
281 return "a dungeon collapse";
282 else if (killer->contr)
283 snprintf (buf, sizeof (buf), "%s the %s", &killer->name,
284 *killer->contr->own_title ? killer->contr->own_title : killer->contr->title);
285 else if (killer->type == DEEP_SWAMP)
286 snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name);
287 else if (killer->owner)
288 snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name);
289 else
290 return &killer->name;
291
276 return 0; 292 return buf;
277
278 f.next ();
279
280 return load_pl (f);
281} 293}
282 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