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.60 by root, Wed Nov 11 23:27:56 2009 UTC vs.
Revision 1.76 by root, Sat Nov 17 23:40:00 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26 27
34int 35int
35atnr_is_dragon_enabled (int attacknr) 36atnr_is_dragon_enabled (int attacknr)
36{ 37{
37 if (attacknr == ATNR_MAGIC || attacknr == ATNR_FIRE || 38 if (attacknr == ATNR_MAGIC || attacknr == ATNR_FIRE ||
38 attacknr == ATNR_ELECTRICITY || attacknr == ATNR_COLD || attacknr == ATNR_ACID || attacknr == ATNR_POISON) 39 attacknr == ATNR_ELECTRICITY || attacknr == ATNR_COLD || attacknr == ATNR_ACID || attacknr == ATNR_POISON)
39 return 1;
40
41 return 0;
42}
43
44/*
45 * returns true if the adressed object 'ob' is a player
46 * of the dragon race.
47 */
48int
49is_dragon_pl (const object *op)
50{
51 if (op
52 && op->type == PLAYER
53 && op->arch
54 && op->arch->race == shstr_dragon)
55 return 1; 40 return 1;
56 41
57 return 0; 42 return 0;
58} 43}
59 44
99 PL_OUT (savebed_map); 84 PL_OUT (savebed_map);
100 PL_OUT (bed_x); 85 PL_OUT (bed_x);
101 PL_OUT (bed_y); 86 PL_OUT (bed_y);
102 PL_OUT (weapon_sp); 87 PL_OUT (weapon_sp);
103 PL_OUT (weapon_sp_left); 88 PL_OUT (weapon_sp_left);
104 PL_OUT2 (Str, orig_stats.Str); 89 PL_OUT2 (str, orig_stats.Str);
105 PL_OUT2 (Dex, orig_stats.Dex); 90 PL_OUT2 (dex, orig_stats.Dex);
106 PL_OUT2 (Con, orig_stats.Con); 91 PL_OUT2 (con, orig_stats.Con);
107 PL_OUT2 (Int, orig_stats.Int); 92 PL_OUT2 (int, orig_stats.Int);
108 PL_OUT2 (Pow, orig_stats.Pow); 93 PL_OUT2 (pow, orig_stats.Pow);
109 PL_OUT2 (Wis, orig_stats.Wis); 94 PL_OUT2 (wis, orig_stats.Wis);
110 PL_OUT2 (Cha, orig_stats.Cha); 95 PL_OUT2 (cha, orig_stats.Cha);
111 96
112 PL_OUT2 (lev_array, 10); 97 PL_OUT2 (lev_array, 10);
113 98
114 for (int i = 1; i <= 10; i++) 99 for (int i = 1; i <= 10; i++)
115 { 100 {
119 } 104 }
120 105
121 freezer.put (ob->contr); 106 freezer.put (ob->contr);
122 freezer.put (KW(endplst)); 107 freezer.put (KW(endplst));
123 108
124 CLEAR_FLAG (ob, FLAG_WIZ); 109 ob->clr_flag (FLAG_WIZ);
125 ob->write (freezer); 110 ob->write (freezer);
126 111
127 /* Eneq(@csd.uu.se): Reveal the container if we have one. */ 112 /* Eneq(@csd.uu.se): Reveal the container if we have one. */
128 ob->container = container; 113 ob->container = container;
129 114
188 return pl; 173 return pl;
189 174
190 case KW_oid: f.get (pl, f.get_sint32 ()); break; 175 case KW_oid: f.get (pl, f.get_sint32 ()); break;
191 case KW_password: assign (pl->password , f.get_str ()); break; 176 case KW_password: assign (pl->password , f.get_str ()); break;
192 case KW_title: assign (pl->own_title, f.get_str ()); break; 177 case KW_title: assign (pl->own_title, f.get_str ()); break;
193 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break; 178 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
194 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break; 179 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
195 case KW_gender: f.get (pl->gender); break; 180 case KW_gender: f.get (pl->gender); break;
196 case KW_hintmode: f.get (pl->hintmode); break; 181 case KW_hintmode: f.get (pl->hintmode); break;
197 case KW_listening: /*TODO*/; break; 182 case KW_listening: /*TODO*/; break;
198 case KW_peaceful: f.get (pl->peaceful); break; 183 case KW_peaceful: f.get (pl->peaceful); break;
199 case KW_digestion: f.get (pl->digestion); break; 184 case KW_digestion: f.get (pl->digestion); break;
204 case KW_savebed_map: f.get (pl->savebed_map); break; 189 case KW_savebed_map: f.get (pl->savebed_map); break;
205 case KW_bed_x: f.get (pl->bed_x); break; 190 case KW_bed_x: f.get (pl->bed_x); break;
206 case KW_bed_y: f.get (pl->bed_y); break; 191 case KW_bed_y: f.get (pl->bed_y); break;
207 case KW_weapon_sp: f.get (pl->weapon_sp); break; 192 case KW_weapon_sp: f.get (pl->weapon_sp); break;
208 case KW_weapon_sp_left:f.get (pl->weapon_sp_left); break; 193 case KW_weapon_sp_left:f.get (pl->weapon_sp_left); break;
194
195 case KW_Str: // uppercase alias
209 case KW_Str: f.get (pl->orig_stats.Str); break; 196 case KW_str: f.get (pl->orig_stats.Str); break;
197 case KW_Dex: // uppercase alias
210 case KW_Dex: f.get (pl->orig_stats.Dex); break; 198 case KW_dex: f.get (pl->orig_stats.Dex); break;
199 case KW_Con: // uppercase alias
211 case KW_Con: f.get (pl->orig_stats.Con); break; 200 case KW_con: f.get (pl->orig_stats.Con); break;
201 case KW_Int: // uppercase alias
212 case KW_Int: f.get (pl->orig_stats.Int); break; 202 case KW_int: f.get (pl->orig_stats.Int); break;
203 case KW_Pow: // uppercase alias
213 case KW_Pow: f.get (pl->orig_stats.Pow); break; 204 case KW_pow: f.get (pl->orig_stats.Pow); break;
205 case KW_Wis: // uppercase alias
214 case KW_Wis: f.get (pl->orig_stats.Wis); break; 206 case KW_wis: f.get (pl->orig_stats.Wis); break;
207 case KW_Cha: // uppercase alias
215 case KW_Cha: f.get (pl->orig_stats.Cha); break; 208 case KW_cha: f.get (pl->orig_stats.Cha); break;
209
216 case KW_gen_hp: f.get (pl->gen_hp); break; 210 case KW_gen_hp: f.get (pl->gen_hp); break;
217 case KW_gen_sp: f.get (pl->gen_sp); break; 211 case KW_gen_sp: f.get (pl->gen_sp); break;
218 case KW_gen_grace: f.get (pl->gen_grace); break; 212 case KW_gen_grace: f.get (pl->gen_grace); break;
219 213
220 case KW_usekeys: 214 case KW_usekeys:
243 { 237 {
244 int count = f.get_sint32 (); 238 int count = f.get_sint32 ();
245 239
246 for (int i = 1; i <= count; i++) 240 for (int i = 1; i <= count; i++)
247 { 241 {
248 char line [32]; 242 f.next_line (); f.get (pl->levhp [i]);
249 243 f.next_line (); f.get (pl->levsp [i]);
250 fgets (line, 32, f); pl->levhp [i] = atoi (line); 244 f.next_line (); f.get (pl->levgrace[i]);
251 fgets (line, 32, f); pl->levsp [i] = atoi (line);
252 fgets (line, 32, f); pl->levgrace[i] = atoi (line);
253 } 245 }
254 } 246 }
255 break; 247 break;
256 } 248 }
257 249
267 pl->destroy (); 259 pl->destroy ();
268 260
269 return 0; 261 return 0;
270} 262}
271 263
272const char * 264const_utf8_string
273player::killer_name () const 265player::killer_name () const
274{ 266{
275 static char buf [2048]; 267 static char buf [2048];
276 268
277 if (!killer) 269 if (!killer)
292// expand one level of cfpod 284// expand one level of cfpod
293// end == -2, till '\n' 285// end == -2, till '\n'
294// end == -1, till '>' 286// end == -1, till '>'
295// end == 0, till eos 287// end == 0, till eos
296// end >= 1, levels of " >>>" 288// end >= 1, levels of " >>>"
289// pod sequences not handled: F, S, X
297static const char * 290static const char *
298expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) 291expand_cfpod (int hintmode, int gender, dynbuf_text &buf, const char *cfpod, int end = 0)
299{ 292{
300 static dynbuf_text nest(128, 128); 293 static dynbuf_text nest(128, 128);
301 294
302 for (;;) 295 for (;;)
303 switch (char ch = *cfpod++) 296 switch (char ch = *cfpod++)
371 if (*cfpod == ' ') 364 if (*cfpod == ' ')
372 goto verbatim; 365 goto verbatim;
373 366
374 break; 367 break;
375 368
376 case 'B': case 'C': case 'E': case 'G': 369 case 'B': case 'C': case 'E': case 'G': case 'H':
377 case 'H': case 'I': case 'T': case 'U': 370 case 'I': case 'L': case 'T': case 'U': case 'Z':
378 case 'Z':
379 { 371 {
380 int end = 0; 372 int end = 0;
381 373
382 while (cfpod [end] == '<') 374 while (cfpod [end] == '<')
383 ++end; 375 ++end;
403 case 'I': pfx = "<i>" ; sfx = "</i>" ; break; 395 case 'I': pfx = "<i>" ; sfx = "</i>" ; break;
404 case 'U': pfx = "<u>" ; sfx = "</u>" ; break; 396 case 'U': pfx = "<u>" ; sfx = "</u>" ; break;
405 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; 397 case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break;
406 case 'Z': pfx = "" ; sfx = "" ; break; 398 case 'Z': pfx = "" ; sfx = "" ; break;
407 399
400 case 'L': // link, not really supported - always use first (or only) component
401 {
402 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
403 nest << '\0'; // zero-terminate
404
405 const char *str = nest.linearise ();
406 const char *sep = strchr (str, '|');
407
408 buf.add (str, sep ? sep - str : nest.size ());
409
410 nest.clear ();
411
412 goto skip;
413 }
414
408 case 'H': // hint 415 case 'H': // hint
409 { 416 {
410 if (pl->hintmode) 417 if (hintmode)
411 { 418 {
412 cfpod = expand_cfpod (pl, nest, cfpod, end); 419 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
413 nest.clear (); 420 nest.clear ();
414 421
415 if (pl->hintmode == 1) 422 if (hintmode == 1)
416 buf << "<fg name=\"lightblue\">[Hint available]</fg>"; 423 buf << "<fg name=\"lightblue\">[Hint available]</fg>";
417 else 424 else
418 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace 425 while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace
419 ++cfpod; 426 ++cfpod;
420 427
428 } 435 }
429 break; 436 break;
430 437
431 case 'G': // gender 438 case 'G': // gender
432 { 439 {
433 cfpod = expand_cfpod (pl, nest, cfpod, end); 440 cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end);
434 nest << '\0'; // zero-terminate 441 nest << '\0'; // zero-terminate
435 442
436 const char *str = nest.linearise (); 443 const char *str = nest.linearise ();
437 const char *sep = strchr (str, '|'); 444 const char *sep = strchr (str, '|');
438 445
439 if (sep) 446 if (sep)
440 { 447 {
441 if (pl->gender) 448 if (gender)
442 buf.add (sep + 1, nest.size () - (sep - str) - 2); 449 buf.add (sep + 1, nest.size () - (sep - str) - 2);
443 else 450 else
444 buf.add (str, sep - str); 451 buf.add (str, sep - str);
445 } 452 }
446 453
454 sfx = "}"; 461 sfx = "}";
455 break; 462 break;
456 } 463 }
457 464
458 buf << pfx; 465 buf << pfx;
459 cfpod = expand_cfpod (pl, buf, cfpod, end); 466 cfpod = expand_cfpod (hintmode, gender, buf, cfpod, end);
460 buf << sfx; 467 buf << sfx;
461 } 468 }
462 469
463 break; 470 break;
464 471
471 verbatim: 478 verbatim:
472 // elements cannot currently span multiple lines 479 // elements cannot currently span multiple lines
473 do 480 do
474 { 481 {
475 buf << "<tt>"; 482 buf << "<tt>";
476 cfpod = expand_cfpod (pl, buf, cfpod, -2); 483 cfpod = expand_cfpod (hintmode, gender, buf, cfpod, -2);
477 buf << "</tt>\n"; 484 buf << "</tt>\n";
478 485
479 while (*cfpod == '\n') 486 while (*cfpod == '\n')
480 buf << *cfpod++; 487 buf << *cfpod++;
481 } 488 }
484 break; 491 break;
485 } 492 }
486} 493}
487 494
488dynbuf_text * 495dynbuf_text *
489player::expand_cfpod (const char *cfpod) const 496player::expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
490{ 497{
491 static dynbuf_text buf(1024, 1024); 498 static dynbuf_text buf(65536, 1024);
492 buf.clear (); 499 buf.clear ();
493 500
494 ::expand_cfpod (this, buf, cfpod); 501 ::expand_cfpod (hintmode, gender, buf, cfpod);
495 502
496 return &buf; 503 return &buf;
497} 504}
498 505
506dynbuf_text *
507player::expand_cfpod (const_utf8_string cfpod) const
508{
509 return expand_cfpod (hintmode, gender, cfpod);
510}
511

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines