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.29 by root, Sun May 27 23:14:37 2007 UTC vs.
Revision 1.62 by root, Sat Jan 16 13:41:37 2010 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program 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 2 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, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail at <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);
91 PL_OUT (outputs_sync); 92 PL_OUT (outputs_sync);
92 PL_OUT (outputs_count); 93 PL_OUT (outputs_count);
93 94
94 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)));
95 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)));
96 97
97 PL_OUT2 (map, maplevel); 98 PL_OUT2 (map, maplevel);
98 PL_OUT (savebed_map); 99 PL_OUT (savebed_map);
99 PL_OUT (bed_x); 100 PL_OUT (bed_x);
100 PL_OUT (bed_y); 101 PL_OUT (bed_y);
116 freezer.add (levsp [i]); freezer.add ('\n'); 117 freezer.add (levsp [i]); freezer.add ('\n');
117 freezer.add (levgrace[i]); freezer.add ('\n'); 118 freezer.add (levgrace[i]); freezer.add ('\n');
118 } 119 }
119 120
120 freezer.put (ob->contr); 121 freezer.put (ob->contr);
121 freezer.put (KW_endplst); 122 freezer.put (KW(endplst));
122 123
123 SET_FLAG (ob, FLAG_NO_FIX_PLAYER);
124 CLEAR_FLAG (ob, FLAG_WIZ); 124 CLEAR_FLAG (ob, FLAG_WIZ);
125 ob->write (freezer); 125 ob->write (freezer);
126 126
127 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
128
129 /* Eneq(@csd.uu.se): Reveal the container if we have one. */ 127 /* Eneq(@csd.uu.se): Reveal the container if we have one. */
130 ob->container = container; 128 ob->container = container;
131 129
132 ob->flag [FLAG_WIZ] = wiz; 130 ob->flag [FLAG_WIZ] = wiz;
133 131
134 INVOKE_PLAYER (SAVE_DONE, ob->contr); 132 INVOKE_PLAYER (SAVE_DONE, ob->contr);
135 133
136 return true; 134 return true;
137} 135}
136
137//-GPL
138 138
139bool 139bool
140player::save_pl (const char *path) 140player::save_pl (const char *path)
141{ 141{
142 object_freezer freezer; 142 object_freezer freezer;
190 case KW_oid: f.get (pl, f.get_sint32 ()); break; 190 case KW_oid: f.get (pl, f.get_sint32 ()); break;
191 case KW_password: assign (pl->password , f.get_str ()); break; 191 case KW_password: assign (pl->password , f.get_str ()); break;
192 case KW_title: assign (pl->own_title, f.get_str ()); break; 192 case KW_title: assign (pl->own_title, f.get_str ()); break;
193 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 193 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
194 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 194 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
195 case KW_listening: f.get (pl->listening); break; 195 case KW_gender: f.get (pl->gender); break;
196 case KW_hintmode: f.get (pl->hintmode); break;
197 case KW_listening: /*TODO*/; break;
196 case KW_peaceful: f.get (pl->peaceful); break; 198 case KW_peaceful: f.get (pl->peaceful); break;
197 case KW_digestion: f.get (pl->digestion); break; 199 case KW_digestion: f.get (pl->digestion); break;
198 case KW_pickup: f.get (pl->mode); break; 200 case KW_pickup: f.get (pl->mode); break;
199 case KW_outputs_sync: f.get (pl->outputs_sync); break; 201 case KW_outputs_sync: f.get (pl->outputs_sync); break;
200 case KW_outputs_count: f.get (pl->outputs_count); break; 202 case KW_outputs_count: f.get (pl->outputs_count); break;
265 pl->destroy (); 267 pl->destroy ();
266 268
267 return 0; 269 return 0;
268} 270}
269 271
270player * 272const_utf8_string
271player::load_pl (const char *path) 273player::killer_name () const
272{ 274{
273 object_thawer f (path); 275 static char buf [2048];
274 276
275 if (!f) 277 if (!killer)
278 return "a dungeon collapse";
279 else if (killer->contr)
280 snprintf (buf, sizeof (buf), "%s the %s", &killer->name,
281 *killer->contr->own_title ? killer->contr->own_title : killer->contr->title);
282 else if (killer->type == DEEP_SWAMP)
283 snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name);
284 else if (killer->owner)
285 snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name);
286 else
287 return &killer->name;
288
276 return 0; 289 return buf;
277
278 f.next ();
279
280 return load_pl (f);
281} 290}
282 291
292// expand one level of cfpod
293// end == -2, till '\n'
294// end == -1, till '>'
295// end == 0, till eos
296// end >= 1, levels of " >>>"
297static const char *
298expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
299{
300 static dynbuf_text nest(128, 128);
301
302 for (;;)
303 switch (char ch = *cfpod++)
304 {
305 case 0:
306 return cfpod - 1;
307
308 case ' ':
309 // verbatim block?
310 if (!buf.size () && !end)
311 {
312 --cfpod;
313 goto verbatim;
314 }
315
316 if (end < 1)
317 goto passthrough;
318
319 for (int i = 0; i < end; ++i)
320 if (cfpod [i] != '>')
321 goto passthrough;
322
323 return cfpod + end;
324
325 case '>':
326 if (end != -1)
327 {
328 buf << "&gt;";
329 break;
330 }
331
332 return cfpod;
333
334 case '&':
335 buf << "&amp;";
336 break;
337
338 case '<':
339 buf << "&lt;";
340 break;
341
342 case '\r':
343 buf << '\n';
344 /* \r\n+ becomes one or more newlines */
345 while (*cfpod == '\n')
346 buf << *cfpod++;
347 break;
348
349 case '\n':
350 if (end == -2)
351 return cfpod;
352
353 // \n\ => newline, tt
354 // \n\n => \n\n
355 // \n => single space
356
357 // two or more newlines will be copied verbatim, one is replaced by space
358 if (*cfpod == '\n')
359 {
360 --cfpod;
361 do
362 buf << *cfpod++;
363 while (*cfpod == '\n');
364 }
365 else if (*cfpod == ' ')
366 buf << '\n';
367 else
368 buf << ' ';
369
370 // verbatim block?
371 if (*cfpod == ' ')
372 goto verbatim;
373
374 break;
375
376 case 'B': case 'C': case 'E': case 'G':
377 case 'H': case 'I': case 'T': case 'U':
378 case 'Z':
379 {
380 int end = 0;
381
382 while (cfpod [end] == '<')
383 ++end;
384
385 if (!end)
386 goto passthrough;
387
388 if (end == 1 || cfpod [end] != ' ')
389 {
390 end = -1;
391 ++cfpod;
392 }
393 else
394 cfpod += end + 1;
395
396 const char *pfx, *sfx;
397
398 switch (ch)
399 {
400 case 'B': pfx = "<b>" ; sfx = "</b>" ; break;
401 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
402 case 'E': pfx = "&" ; sfx = ";" ; break;
403 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
404 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
405 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
406 case 'Z': pfx = "" ; sfx = "" ; break;
407
408 case 'H': // hint
409 {
410 if (pl->hintmode)
411 {
412 cfpod = expand_cfpod (pl, nest, cfpod, end);
413 nest.clear ();
414
415 if (pl->hintmode == 1)
416 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
417 else
418 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
419 ++cfpod;
420
421 goto skip;
422 }
423 else
424 {
425 pfx = "<fg name=\"lightblue\">[Hint: ";
426 sfx = "]</fg>";
427 }
428 }
429 break;
430
431 case 'G': // gender
432 {
433 cfpod = expand_cfpod (pl, nest, cfpod, end);
434 nest << '\0'; // zero-terminate
435
436 const char *str = nest.linearise ();
437 const char *sep = strchr (str, '|');
438
439 if (sep)
440 {
441 if (pl->gender)
442 buf.add (sep + 1, nest.size () - (sep - str) - 2);
443 else
444 buf.add (str, sep - str);
445 }
446
447 nest.clear ();
448
449 goto skip;
450 }
451
452 default:
453 pfx = "UNKNOWN_DIRECTIVE{";
454 sfx = "}";
455 break;
456 }
457
458 buf << pfx;
459 cfpod = expand_cfpod (pl, buf, cfpod, end);
460 buf << sfx;
461 }
462
463 break;
464
465 default:
466 passthrough:
467 buf << ch;
468 skip:
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;
485 }
486}
487
488dynbuf_text *
489player::expand_cfpod (const char *cfpod) const
490{
491 static dynbuf_text buf(1024, 1024);
492 buf.clear ();
493
494 ::expand_cfpod (this, buf, cfpod);
495
496 return &buf;
497}
498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines