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.21 by root, Fri Feb 16 19:43:41 2007 UTC vs.
Revision 1.56 by root, Mon Oct 19 21:48:49 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 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 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>
27 26
28/* Determine if the attacktype represented by the 27/* Determine if the attacktype represented by the
29 * specified attack-number is enabled for dragon players. 28 * specified attack-number is enabled for dragon players.
30 * A dragon player (quetzal) can gain resistances for 29 * A dragon player (quetzal) can gain resistances for
31 * all enabled attacktypes. 30 * all enabled attacktypes.
45 * of the dragon race. 44 * of the dragon race.
46 */ 45 */
47int 46int
48is_dragon_pl (const object *op) 47is_dragon_pl (const object *op)
49{ 48{
50 if (op != NULL && op->type == PLAYER && op->arch != NULL && op->arch->clone.race != NULL && strcmp (op->arch->clone.race, "dragon") == 0) 49 if (op
50 && op->type == PLAYER
51 && op->arch
52 && op->arch->race == shstr_dragon)
51 return 1; 53 return 1;
52 54
53 return 0; 55 return 0;
54} 56}
55 57
62 INVOKE_PLAYER (SAVE, ob->contr); 64 INVOKE_PLAYER (SAVE, ob->contr);
63 65
64 int wiz = ob->flag [FLAG_WIZ]; 66 int wiz = ob->flag [FLAG_WIZ];
65 67
66 /* Eneq(@csd.uu.se): If we have an open container hide it. */ 68 /* Eneq(@csd.uu.se): If we have an open container hide it. */
67 object *container = ob->container; 69 object *container = ob->container_ ();
68 ob->container = 0; 70 ob->container = 0;
69 71
70 if (ob->map) 72 if (ob->map)
71 maplevel = ob->map->path; 73 maplevel = ob->map->path;
72 74
73#define PL_OUT(k) freezer.put (KW_ ## k, k) 75#define PL_OUT(k) freezer.put (KW_ ## k, k)
74#define PL_OUT2(k,v) freezer.put (KW_ ## k, v) 76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
75 77
76 PL_OUT (password); 78 PL_OUT (password);
77 PL_OUT2 (title, own_title); 79 PL_OUT2 (title, own_title);
80 PL_OUT (gender);
81 PL_OUT (hintmode);
78 PL_OUT (gen_hp); 82 PL_OUT (gen_hp);
79 PL_OUT (gen_sp); 83 PL_OUT (gen_sp);
80 PL_OUT (gen_grace); 84 PL_OUT (gen_grace);
81 PL_OUT (listening);
82 PL_OUT (shoottype);
83 PL_OUT (bowtype); 85 PL_OUT (bowtype);
84 PL_OUT (petmode); 86 PL_OUT (petmode);
85 PL_OUT (peaceful); 87 PL_OUT (peaceful);
86 PL_OUT (digestion); 88 PL_OUT (digestion);
87 PL_OUT2 (pickup, mode); 89 PL_OUT2 (pickup, mode);
94 PL_OUT2 (map, maplevel); 96 PL_OUT2 (map, maplevel);
95 PL_OUT (savebed_map); 97 PL_OUT (savebed_map);
96 PL_OUT (bed_x); 98 PL_OUT (bed_x);
97 PL_OUT (bed_y); 99 PL_OUT (bed_y);
98 PL_OUT (weapon_sp); 100 PL_OUT (weapon_sp);
101 PL_OUT (weapon_sp_left);
99 PL_OUT2 (Str, orig_stats.Str); 102 PL_OUT2 (Str, orig_stats.Str);
100 PL_OUT2 (Dex, orig_stats.Dex); 103 PL_OUT2 (Dex, orig_stats.Dex);
101 PL_OUT2 (Con, orig_stats.Con); 104 PL_OUT2 (Con, orig_stats.Con);
102 PL_OUT2 (Int, orig_stats.Int); 105 PL_OUT2 (Int, orig_stats.Int);
103 PL_OUT2 (Pow, orig_stats.Pow); 106 PL_OUT2 (Pow, orig_stats.Pow);
106 109
107 PL_OUT2 (lev_array, 10); 110 PL_OUT2 (lev_array, 10);
108 111
109 for (int i = 1; i <= 10; i++) 112 for (int i = 1; i <= 10; i++)
110 { 113 {
111 fprintf (freezer, "%d\n", levhp [i]); 114 freezer.add (levhp [i]); freezer.add ('\n');
112 fprintf (freezer, "%d\n", levsp [i]); 115 freezer.add (levsp [i]); freezer.add ('\n');
113 fprintf (freezer, "%d\n", levgrace[i]); 116 freezer.add (levgrace[i]); freezer.add ('\n');
114 } 117 }
115 118
116 freezer.put (ob->contr); 119 freezer.put (ob->contr);
117 freezer.put (KW_endplst); 120 freezer.put (KW_endplst);
118 121
184 return pl; 187 return pl;
185 188
186 case KW_oid: f.get (pl, f.get_sint32 ()); break; 189 case KW_oid: f.get (pl, f.get_sint32 ()); break;
187 case KW_password: assign (pl->password , f.get_str ()); break; 190 case KW_password: assign (pl->password , f.get_str ()); break;
188 case KW_title: assign (pl->own_title, f.get_str ()); break; 191 case KW_title: assign (pl->own_title, f.get_str ()); break;
189 case KW_shoottype: pl->shoottype = (rangetype) f.get_sint32 (); break;
190 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
191 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
192 case KW_listening: f.get (pl->listening); break; 194 case KW_gender: f.get (pl->gender); break;
195 case KW_hintmode: f.get (pl->hintmode); break;
196 case KW_listening: /*TODO*/; break;
193 case KW_peaceful: f.get (pl->peaceful); break; 197 case KW_peaceful: f.get (pl->peaceful); break;
194 case KW_digestion: f.get (pl->digestion); break; 198 case KW_digestion: f.get (pl->digestion); break;
195 case KW_pickup: f.get (pl->mode); break; 199 case KW_pickup: f.get (pl->mode); break;
196 case KW_outputs_sync: f.get (pl->outputs_sync); break; 200 case KW_outputs_sync: f.get (pl->outputs_sync); break;
197 case KW_outputs_count: f.get (pl->outputs_count); break; 201 case KW_outputs_count: f.get (pl->outputs_count); break;
198 case KW_map: f.get (pl->maplevel); break; 202 case KW_map: f.get (pl->maplevel); break;
199 case KW_savebed_map: f.get (pl->savebed_map); break; 203 case KW_savebed_map: f.get (pl->savebed_map); break;
200 case KW_bed_x: f.get (pl->bed_x); break; 204 case KW_bed_x: f.get (pl->bed_x); break;
201 case KW_bed_y: f.get (pl->bed_y); break; 205 case KW_bed_y: f.get (pl->bed_y); break;
202 case KW_weapon_sp: f.get (pl->weapon_sp); break; 206 case KW_weapon_sp: f.get (pl->weapon_sp); break;
207 case KW_weapon_sp_left:f.get (pl->weapon_sp_left); break;
203 case KW_Str: f.get (pl->orig_stats.Str); break; 208 case KW_Str: f.get (pl->orig_stats.Str); break;
204 case KW_Dex: f.get (pl->orig_stats.Dex); break; 209 case KW_Dex: f.get (pl->orig_stats.Dex); break;
205 case KW_Con: f.get (pl->orig_stats.Con); break; 210 case KW_Con: f.get (pl->orig_stats.Con); break;
206 case KW_Int: f.get (pl->orig_stats.Int); break; 211 case KW_Int: f.get (pl->orig_stats.Int); break;
207 case KW_Pow: f.get (pl->orig_stats.Pow); break; 212 case KW_Pow: f.get (pl->orig_stats.Pow); break;
253 } 258 }
254 259
255failure: 260failure:
256 LOG (llevError, "%s: too many or too grave errors, aborting player load.\n", f.name); 261 LOG (llevError, "%s: too many or too grave errors, aborting player load.\n", f.name);
257 262
263 if (pl->ob)
258 pl->ob->destroy (); 264 pl->ob->destroy ();
265
259 pl->destroy (); 266 pl->destroy ();
260 267
261 return 0; 268 return 0;
262} 269}
263 270
264player * 271const char *
265player::load_pl (const char *path) 272player::killer_name () const
266{ 273{
267 object_thawer f (path); 274 static char buf [2048];
268 275
269 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
270 return 0; 288 return buf;
271
272 f.next ();
273
274 return load_pl (f);
275} 289}
276 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 = 0)
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 // verbatim block?
309 if (!buf.size () && !end)
310 {
311 --cfpod;
312 goto verbatim;
313 }
314
315 if (end < 1)
316 goto passthrough;
317
318 for (int i = 0; i < end; ++i)
319 if (cfpod [i] != '>')
320 goto passthrough;
321
322 return cfpod + end;
323
324 case '>':
325 if (end != -1)
326 {
327 buf << "&gt;";
328 break;
329 }
330
331 return cfpod;
332
333 case '&':
334 buf << "&amp;";
335 break;
336
337 case '<':
338 buf << "&lt;";
339 break;
340
341 case '\r':
342 buf << '\n';
343 /* \r\n+ becomes one or more newlines */
344 while (*cfpod == '\n')
345 buf << *cfpod++;
346 break;
347
348 case '\n':
349 if (end == -2)
350 return cfpod;
351
352 // \n\ => newline, tt
353 // \n\n => \n\n
354 // \n => single space
355
356 // two or more newlines will be copied verbatim, one is replaced by space
357 if (*cfpod == '\n')
358 {
359 --cfpod;
360 do
361 buf << *cfpod++;
362 while (*cfpod == '\n');
363 }
364 else if (*cfpod == ' ')
365 buf << '\n';
366 else
367 buf << ' ';
368
369 // verbatim block?
370 if (*cfpod == ' ')
371 goto verbatim;
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 case 'Z': pfx = "" ; sfx = "" ; break;
406
407 case 'H': // hint
408 {
409 if (pl->hintmode)
410 {
411 cfpod = expand_cfpod (pl, nest, cfpod, end);
412 nest.clear ();
413
414 if (pl->hintmode == 1)
415 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
416 else
417 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
418 ++cfpod;
419
420 goto skip;
421 }
422 else
423 {
424 pfx = "<fg name=\"lightblue\">[Hint: ";
425 sfx = "]</fg>";
426 }
427 }
428 break;
429
430 case 'G': // gender
431 {
432 cfpod = expand_cfpod (pl, nest, cfpod, end);
433 nest << '\0'; // zero-terminate
434
435 const char *str = nest.linearise ();
436 const char *sep = strchr (str, '|');
437
438 if (sep)
439 {
440 if (pl->gender)
441 buf.add (sep + 1, nest.size () - (sep - str) - 2);
442 else
443 buf.add (str, sep - str);
444 }
445
446 nest.clear ();
447
448 goto skip;
449 }
450 }
451
452 buf << pfx;
453 cfpod = expand_cfpod (pl, buf, cfpod, end);
454 buf << sfx;
455 }
456
457 break;
458
459 default:
460 passthrough:
461 buf << ch;
462 skip:
463 break;
464
465 verbatim:
466 // elements cannot currently span multiple lines
467 do
468 {
469 buf << "<tt>";
470 cfpod = expand_cfpod (pl, buf, cfpod, -2);
471 buf << "</tt>\n";
472
473 while (*cfpod == '\n')
474 buf << *cfpod++;
475 }
476 while (*cfpod == ' ');
477
478 break;
479 }
480}
481
482dynbuf_text *
483player::expand_cfpod (const char *cfpod) const
484{
485 static dynbuf_text buf(1024, 1024);
486 buf.clear ();
487
488 ::expand_cfpod (this, buf, cfpod);
489
490 return &buf;
491}
492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines