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.35 by root, Thu Nov 8 19:43:23 2007 UTC vs.
Revision 1.42 by root, Mon Sep 8 11:30:53 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
20 * 20 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <funcpoint.h>
26 25
27/* Determine if the attacktype represented by the 26/* Determine if the attacktype represented by the
28 * specified attack-number is enabled for dragon players. 27 * specified attack-number is enabled for dragon players.
29 * A dragon player (quetzal) can gain resistances for 28 * A dragon player (quetzal) can gain resistances for
30 * all enabled attacktypes. 29 * all enabled attacktypes.
77#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
78 77
79 PL_OUT (password); 78 PL_OUT (password);
80 PL_OUT2 (title, own_title); 79 PL_OUT2 (title, own_title);
81 PL_OUT (gender); 80 PL_OUT (gender);
81 PL_OUT (hintmode);
82 PL_OUT (gen_hp); 82 PL_OUT (gen_hp);
83 PL_OUT (gen_sp); 83 PL_OUT (gen_sp);
84 PL_OUT (gen_grace); 84 PL_OUT (gen_grace);
85 PL_OUT (listening);
86 PL_OUT (bowtype); 85 PL_OUT (bowtype);
87 PL_OUT (petmode); 86 PL_OUT (petmode);
88 PL_OUT (peaceful); 87 PL_OUT (peaceful);
89 PL_OUT (digestion); 88 PL_OUT (digestion);
90 PL_OUT2 (pickup, mode); 89 PL_OUT2 (pickup, mode);
191 case KW_password: assign (pl->password , f.get_str ()); break; 190 case KW_password: assign (pl->password , f.get_str ()); break;
192 case KW_title: assign (pl->own_title, f.get_str ()); break; 191 case KW_title: assign (pl->own_title, f.get_str ()); break;
193 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
194 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
195 case KW_gender: f.get (pl->gender); break; 194 case KW_gender: f.get (pl->gender); break;
196 case KW_listening: f.get (pl->listening); break; 195 case KW_hintmode: f.get (pl->hintmode); break;
196 case KW_listening: /*TODO*/; break;
197 case KW_peaceful: f.get (pl->peaceful); break; 197 case KW_peaceful: f.get (pl->peaceful); break;
198 case KW_digestion: f.get (pl->digestion); break; 198 case KW_digestion: f.get (pl->digestion); break;
199 case KW_pickup: f.get (pl->mode); break; 199 case KW_pickup: f.get (pl->mode); break;
200 case KW_outputs_sync: f.get (pl->outputs_sync); break; 200 case KW_outputs_sync: f.get (pl->outputs_sync); break;
201 case KW_outputs_count: f.get (pl->outputs_count); break; 201 case KW_outputs_count: f.get (pl->outputs_count); break;
266 pl->destroy (); 266 pl->destroy ();
267 267
268 return 0; 268 return 0;
269} 269}
270 270
271const char *
272player::killer_name () const
273{
274 static char buf [2048];
275
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
288 return buf;
289}
290
291// expand one level of cfpod
292// end == -1, till eos
293// end == 0, one level of '>'
294// end >= 1, this many levels of " >>>"
295static const char *
296expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end)
297{
298 static dynbuf_text nest(128, 128);
299
300 for (;;)
301 switch (char ch = *cfpod++)
302 {
303 case 0:
304 return cfpod - 1;
305
306 case ' ':
307 if (end <= 0)
308 goto passthrough;
309
310 for (int i = 0; i < end; ++i)
311 if (cfpod [i] != '>')
312 goto passthrough;
313
314 return cfpod + end;
315
316 case '>':
317 if (end)
318 {
319 buf << "&gt;";
320 break;
321 }
322
323 return cfpod;
324
325 case '&':
326 buf << "&amp;";
327 break;
328
329 case '<':
330 buf << "&lt;";
331 break;
332
333 case '\r':
334 buf << '\n';
335 break;
336
337 case '\n':
338 if (*cfpod == ' ')
339 goto passthrough;
340 else if (*cfpod == '\n')
341 {
342 --cfpod;
343 do
344 buf << *cfpod++;
345 while (*cfpod == '\n');
346 }
347 else
348 buf << ' ';
349
350 break;
351
352 case 'B': case 'C': case 'E': case 'G':
353 case 'H': case 'I': case 'T': case 'U':
354 case 'Z':
355 {
356 int len = 0;
357
358 while (cfpod [len] == '<')
359 ++len;
360
361 if (!len)
362 goto passthrough;
363
364 if (len == 1 || cfpod [len] != ' ')
365 {
366 len = 0;
367 ++cfpod;
368 }
369 else
370 cfpod += len + 1;
371
372 const char *pfx, *sfx;
373
374 switch (ch)
375 {
376 case 'B': pfx = "<b>" ; sfx = "</b>" ; break;
377 case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break;
378 case 'E': pfx = "&" ; sfx = ";" ; break;
379 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
380 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
381 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
382
383 case 'H': // hint
384 {
385 if (pl->hintmode)
386 {
387 cfpod = expand_cfpod (pl, nest, cfpod, len);
388 nest.clear ();
389
390 if (pl->hintmode == 1)
391 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
392 else
393 while (*cfpod == ' ') // eat trailing whitespace
394 ++cfpod;
395
396 goto skip;
397 }
398 else
399 {
400 pfx = "<fg name=\"lightblue\">[";
401 sfx = " (Use hintmode to suppress hints)]</fg>";
402 }
403 }
404 break;
405
406 case 'G': // gender
407 {
408 expand_cfpod (pl, nest, cfpod, len);
409 nest << '\0'; // zero-terminate
410
411 const char *str = nest.linearise ();
412 const char *sep = strchr (str, '|');
413
414 if (sep)
415 {
416 if (pl->gender || 1)
417 buf.add (sep + 1, nest.size () - (sep - str) - 2);
418 else
419 buf.add (str, sep - str);
420 }
421
422 nest.clear ();
423
424 goto skip;
425 }
426 }
427
428 buf << pfx;
429 cfpod = expand_cfpod (pl, buf, cfpod, len);
430 buf << sfx;
431 }
432
433 break;
434
435 default:
436 passthrough:
437 buf << ch;
438 skip:
439 break;
440 }
441}
442
443dynbuf_text *
444player::expand_cfpod (const char *cfpod) const
445{
446 static dynbuf_text buf(1024, 1024);
447 buf.clear ();
448
449 ::expand_cfpod (this, buf, cfpod, -1);
450
451 return &buf;
452}
453

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines