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.32 by root, Sun Jun 24 01:09:27 2007 UTC vs.
Revision 1.43 by root, Mon Sep 8 18:34:35 2008 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 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
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your 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 GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <funcpoint.h>
27 25
28/* Determine if the attacktype represented by the 26/* Determine if the attacktype represented by the
29 * specified attack-number is enabled for dragon players. 27 * specified attack-number is enabled for dragon players.
30 * A dragon player (quetzal) can gain resistances for 28 * A dragon player (quetzal) can gain resistances for
31 * all enabled attacktypes. 29 * all enabled attacktypes.
78#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
79 77
80 PL_OUT (password); 78 PL_OUT (password);
81 PL_OUT2 (title, own_title); 79 PL_OUT2 (title, own_title);
82 PL_OUT (gender); 80 PL_OUT (gender);
81 PL_OUT (hintmode);
83 PL_OUT (gen_hp); 82 PL_OUT (gen_hp);
84 PL_OUT (gen_sp); 83 PL_OUT (gen_sp);
85 PL_OUT (gen_grace); 84 PL_OUT (gen_grace);
86 PL_OUT (listening);
87 PL_OUT (bowtype); 85 PL_OUT (bowtype);
88 PL_OUT (petmode); 86 PL_OUT (petmode);
89 PL_OUT (peaceful); 87 PL_OUT (peaceful);
90 PL_OUT (digestion); 88 PL_OUT (digestion);
91 PL_OUT2 (pickup, mode); 89 PL_OUT2 (pickup, mode);
192 case KW_password: assign (pl->password , f.get_str ()); break; 190 case KW_password: assign (pl->password , f.get_str ()); break;
193 case KW_title: assign (pl->own_title, f.get_str ()); break; 191 case KW_title: assign (pl->own_title, f.get_str ()); break;
194 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
195 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
196 case KW_gender: f.get (pl->gender); break; 194 case KW_gender: f.get (pl->gender); break;
197 case KW_listening: f.get (pl->listening); break; 195 case KW_hintmode: f.get (pl->hintmode); break;
196 case KW_listening: /*TODO*/; break;
198 case KW_peaceful: f.get (pl->peaceful); break; 197 case KW_peaceful: f.get (pl->peaceful); break;
199 case KW_digestion: f.get (pl->digestion); break; 198 case KW_digestion: f.get (pl->digestion); break;
200 case KW_pickup: f.get (pl->mode); break; 199 case KW_pickup: f.get (pl->mode); break;
201 case KW_outputs_sync: f.get (pl->outputs_sync); break; 200 case KW_outputs_sync: f.get (pl->outputs_sync); break;
202 case KW_outputs_count: f.get (pl->outputs_count); break; 201 case KW_outputs_count: f.get (pl->outputs_count); break;
267 pl->destroy (); 266 pl->destroy ();
268 267
269 return 0; 268 return 0;
270} 269}
271 270
272player * 271const char *
273player::load_pl (const char *path) 272player::killer_name () const
274{ 273{
275 object_thawer f (path); 274 static char buf [2048];
276 275
277 if (!f) 276 if (!killer)
277 return "a dungeon collapse";
278 else if (killer->contr)
279 snprintf (buf, sizeof (buf), "%s the %s", &killer->name,
280 *killer->contr->own_title ? killer->contr->own_title : killer->contr->title);
281 else if (killer->type == DEEP_SWAMP)
282 snprintf (buf, sizeof (buf), "drowning in a %s", &killer->name);
283 else if (killer->owner)
284 snprintf (buf, sizeof (buf), "%s's %s", &killer->outer_owner ()->name, &killer->name);
285 else
286 return &killer->name;
287
278 return 0; 288 return buf;
279
280 f.next ();
281
282 return load_pl (f);
283} 289}
284 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)
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 if (end < 1)
309 goto passthrough;
310
311 for (int i = 0; i < end; ++i)
312 if (cfpod [i] != '>')
313 goto passthrough;
314
315 return cfpod + end;
316
317 case '>':
318 if (end != -1)
319 {
320 buf << "&gt;";
321 break;
322 }
323
324 return cfpod;
325
326 case '&':
327 buf << "&amp;";
328 break;
329
330 case '<':
331 buf << "&lt;";
332 break;
333
334 case '\r':
335 buf << '\n';
336 break;
337
338 case '\n':
339 if (end == -2)
340 return cfpod;
341
342 // \n\ => newline, tt
343 // \n\n => \n\n
344 // \n => single space
345
346 // two or more newlines will be copied verbatim, one is replaced by space
347 if (*cfpod == '\n')
348 {
349 --cfpod;
350 do
351 buf << *cfpod++;
352 while (*cfpod == '\n');
353 }
354 else if (*cfpod != ' ')
355 buf << ' ';
356
357 // start verbatim block's?
358 if (*cfpod == ' ')
359 {
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 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
406 case 'H': // hint
407 {
408 if (pl->hintmode)
409 {
410 cfpod = expand_cfpod (pl, nest, cfpod, end);
411 nest.clear ();
412
413 if (pl->hintmode == 1)
414 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
415 else
416 while (*cfpod == ' ') // eat trailing whitespace
417 ++cfpod;
418
419 goto skip;
420 }
421 else
422 {
423 pfx = "<fg name=\"lightblue\">[";
424 sfx = " (Use hintmode to suppress hints)]</fg>";
425 }
426 }
427 break;
428
429 case 'G': // gender
430 {
431 expand_cfpod (pl, nest, cfpod, end);
432 nest << '\0'; // zero-terminate
433
434 const char *str = nest.linearise ();
435 const char *sep = strchr (str, '|');
436
437 if (sep)
438 {
439 if (pl->gender || 1)
440 buf.add (sep + 1, nest.size () - (sep - str) - 2);
441 else
442 buf.add (str, sep - str);
443 }
444
445 nest.clear ();
446
447 goto skip;
448 }
449 }
450
451 buf << pfx;
452 cfpod = expand_cfpod (pl, buf, cfpod, end);
453 buf << sfx;
454 }
455
456 break;
457
458 default:
459 passthrough:
460 buf << ch;
461 skip:
462 break;
463 }
464}
465
466dynbuf_text *
467player::expand_cfpod (const char *cfpod) const
468{
469 static dynbuf_text buf(1024, 1024);
470 buf.clear ();
471
472 ::expand_cfpod (this, buf, cfpod, 0);
473
474 return &buf;
475}
476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines