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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 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 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 3 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, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | |
|
|
27 | //+GPL |
25 | |
28 | |
26 | /* Determine if the attacktype represented by the |
29 | /* Determine if the attacktype represented by the |
27 | * specified attack-number is enabled for dragon players. |
30 | * specified attack-number is enabled for dragon players. |
28 | * A dragon player (quetzal) can gain resistances for |
31 | * A dragon player (quetzal) can gain resistances for |
29 | * all enabled attacktypes. |
32 | * all enabled attacktypes. |
… | |
… | |
46 | is_dragon_pl (const object *op) |
49 | is_dragon_pl (const object *op) |
47 | { |
50 | { |
48 | if (op |
51 | if (op |
49 | && op->type == PLAYER |
52 | && op->type == PLAYER |
50 | && op->arch |
53 | && op->arch |
51 | && op->arch->race |
54 | && op->arch->race == shstr_dragon) |
52 | && !strcmp (op->arch->race, "dragon")) |
|
|
53 | return 1; |
55 | return 1; |
54 | |
56 | |
55 | return 0; |
57 | return 0; |
56 | } |
58 | } |
57 | |
59 | |
… | |
… | |
64 | INVOKE_PLAYER (SAVE, ob->contr); |
66 | INVOKE_PLAYER (SAVE, ob->contr); |
65 | |
67 | |
66 | int wiz = ob->flag [FLAG_WIZ]; |
68 | int wiz = ob->flag [FLAG_WIZ]; |
67 | |
69 | |
68 | /* 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. */ |
69 | object *container = ob->container; |
71 | object *container = ob->container_ (); |
70 | ob->container = 0; |
72 | ob->container = 0; |
71 | |
73 | |
72 | if (ob->map) |
74 | if (ob->map) |
73 | maplevel = ob->map->path; |
75 | maplevel = ob->map->path; |
74 | |
76 | |
… | |
… | |
132 | |
134 | |
133 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
135 | INVOKE_PLAYER (SAVE_DONE, ob->contr); |
134 | |
136 | |
135 | return true; |
137 | return true; |
136 | } |
138 | } |
|
|
139 | |
|
|
140 | //-GPL |
137 | |
141 | |
138 | bool |
142 | bool |
139 | player::save_pl (const char *path) |
143 | player::save_pl (const char *path) |
140 | { |
144 | { |
141 | object_freezer freezer; |
145 | object_freezer freezer; |
… | |
… | |
287 | |
291 | |
288 | return buf; |
292 | return buf; |
289 | } |
293 | } |
290 | |
294 | |
291 | // expand one level of cfpod |
295 | // expand one level of cfpod |
|
|
296 | // end == -2, till '\n' |
|
|
297 | // end == -1, till '>' |
292 | // end == -1, till eos |
298 | // end == 0, till eos |
293 | // end == 0, one level of '>' |
|
|
294 | // end >= 1, this many levels of " >>>" |
299 | // end >= 1, levels of " >>>" |
295 | static const char * |
300 | static const char * |
296 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) |
301 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) |
297 | { |
302 | { |
298 | static dynbuf_text nest(128, 128); |
303 | static dynbuf_text nest(128, 128); |
299 | |
304 | |
300 | for (;;) |
305 | for (;;) |
301 | switch (char ch = *cfpod++) |
306 | switch (char ch = *cfpod++) |
302 | { |
307 | { |
303 | case 0: |
308 | case 0: |
304 | return cfpod - 1; |
309 | return cfpod - 1; |
305 | |
310 | |
306 | case ' ': |
311 | case ' ': |
|
|
312 | // verbatim block? |
|
|
313 | if (!buf.size () && !end) |
|
|
314 | { |
|
|
315 | --cfpod; |
|
|
316 | goto verbatim; |
|
|
317 | } |
|
|
318 | |
307 | if (end <= 0) |
319 | if (end < 1) |
308 | goto passthrough; |
320 | goto passthrough; |
309 | |
321 | |
310 | for (int i = 0; i < end; ++i) |
322 | for (int i = 0; i < end; ++i) |
311 | if (cfpod [i] != '>') |
323 | if (cfpod [i] != '>') |
312 | goto passthrough; |
324 | goto passthrough; |
313 | |
325 | |
314 | return cfpod + end; |
326 | return cfpod + end; |
315 | |
327 | |
316 | case '>': |
328 | case '>': |
317 | if (end) |
329 | if (end != -1) |
318 | { |
330 | { |
319 | buf << ">"; |
331 | buf << ">"; |
320 | break; |
332 | break; |
321 | } |
333 | } |
322 | |
334 | |
… | |
… | |
330 | buf << "<"; |
342 | buf << "<"; |
331 | break; |
343 | break; |
332 | |
344 | |
333 | case '\r': |
345 | case '\r': |
334 | buf << '\n'; |
346 | buf << '\n'; |
|
|
347 | /* \r\n+ becomes one or more newlines */ |
|
|
348 | while (*cfpod == '\n') |
|
|
349 | buf << *cfpod++; |
335 | break; |
350 | break; |
336 | |
351 | |
337 | case '\n': |
352 | case '\n': |
|
|
353 | if (end == -2) |
|
|
354 | return cfpod; |
|
|
355 | |
|
|
356 | // \n\ => newline, tt |
|
|
357 | // \n\n => \n\n |
|
|
358 | // \n => single space |
|
|
359 | |
|
|
360 | // two or more newlines will be copied verbatim, one is replaced by space |
338 | if (*cfpod == ' ') |
361 | if (*cfpod == '\n') |
339 | goto passthrough; |
|
|
340 | else if (*cfpod == '\n') |
|
|
341 | { |
362 | { |
342 | --cfpod; |
363 | --cfpod; |
343 | do |
364 | do |
344 | buf << *cfpod++; |
365 | buf << *cfpod++; |
345 | while (*cfpod == '\n'); |
366 | while (*cfpod == '\n'); |
346 | } |
367 | } |
|
|
368 | else if (*cfpod == ' ') |
|
|
369 | buf << '\n'; |
347 | else |
370 | else |
348 | buf << ' '; |
371 | buf << ' '; |
|
|
372 | |
|
|
373 | // verbatim block? |
|
|
374 | if (*cfpod == ' ') |
|
|
375 | goto verbatim; |
349 | |
376 | |
350 | break; |
377 | break; |
351 | |
378 | |
352 | case 'B': case 'C': case 'E': case 'G': |
379 | case 'B': case 'C': case 'E': case 'G': |
353 | case 'H': case 'I': case 'T': case 'U': |
380 | case 'H': case 'I': case 'T': case 'U': |
354 | case 'Z': |
381 | case 'Z': |
355 | { |
382 | { |
356 | int len = 0; |
383 | int end = 0; |
357 | |
384 | |
358 | while (cfpod [len] == '<') |
385 | while (cfpod [end] == '<') |
359 | ++len; |
386 | ++end; |
360 | |
387 | |
361 | if (!len) |
388 | if (!end) |
362 | goto passthrough; |
389 | goto passthrough; |
363 | |
390 | |
364 | if (len == 1 || cfpod [len] != ' ') |
391 | if (end == 1 || cfpod [end] != ' ') |
365 | { |
392 | { |
366 | len = 0; |
393 | end = -1; |
367 | ++cfpod; |
394 | ++cfpod; |
368 | } |
395 | } |
369 | else |
396 | else |
370 | cfpod += len + 1; |
397 | cfpod += end + 1; |
371 | |
398 | |
372 | const char *pfx, *sfx; |
399 | const char *pfx, *sfx; |
373 | |
400 | |
374 | switch (ch) |
401 | switch (ch) |
375 | { |
402 | { |
… | |
… | |
377 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
404 | case 'C': pfx = "<tt>" ; sfx = "</tt>" ; break; |
378 | case 'E': pfx = "&" ; sfx = ";" ; break; |
405 | case 'E': pfx = "&" ; sfx = ";" ; break; |
379 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
406 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
380 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
407 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
381 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
408 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
|
|
409 | case 'Z': pfx = "" ; sfx = "" ; break; |
382 | |
410 | |
383 | case 'H': // hint |
411 | case 'H': // hint |
384 | { |
412 | { |
385 | if (pl->hintmode) |
413 | if (pl->hintmode) |
386 | { |
414 | { |
387 | cfpod = expand_cfpod (pl, nest, cfpod, len); |
415 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
388 | nest.clear (); |
416 | nest.clear (); |
389 | |
417 | |
390 | if (pl->hintmode == 1) |
418 | if (pl->hintmode == 1) |
391 | buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; |
419 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
392 | else |
420 | else |
393 | while (*cfpod == ' ') // eat trailing whitespace |
421 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
394 | ++cfpod; |
422 | ++cfpod; |
395 | |
423 | |
396 | goto skip; |
424 | goto skip; |
397 | } |
425 | } |
398 | else |
426 | else |
399 | { |
427 | { |
400 | pfx = "<fg name=\"lightblue\">["; |
428 | pfx = "<fg name=\"lightblue\">[Hint: "; |
401 | sfx = " (Use hintmode to suppress hints)]</fg>"; |
429 | sfx = "]</fg>"; |
402 | } |
430 | } |
403 | } |
431 | } |
404 | break; |
432 | break; |
405 | |
433 | |
406 | case 'G': // gender |
434 | case 'G': // gender |
407 | { |
435 | { |
408 | expand_cfpod (pl, nest, cfpod, len); |
436 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
409 | nest << '\0'; // zero-terminate |
437 | nest << '\0'; // zero-terminate |
410 | |
438 | |
411 | const char *str = nest.linearise (); |
439 | const char *str = nest.linearise (); |
412 | const char *sep = strchr (str, '|'); |
440 | const char *sep = strchr (str, '|'); |
413 | |
441 | |
414 | if (sep) |
442 | if (sep) |
415 | { |
443 | { |
416 | if (pl->gender || 1) |
444 | if (pl->gender) |
417 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
445 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
418 | else |
446 | else |
419 | buf.add (str, sep - str); |
447 | buf.add (str, sep - str); |
420 | } |
448 | } |
421 | |
449 | |
422 | nest.clear (); |
450 | nest.clear (); |
423 | |
451 | |
424 | goto skip; |
452 | goto skip; |
425 | } |
453 | } |
|
|
454 | |
|
|
455 | default: |
|
|
456 | pfx = "UNKNOWN_DIRECTIVE{"; |
|
|
457 | sfx = "}"; |
|
|
458 | break; |
426 | } |
459 | } |
427 | |
460 | |
428 | buf << pfx; |
461 | buf << pfx; |
429 | cfpod = expand_cfpod (pl, buf, cfpod, len); |
462 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
430 | buf << sfx; |
463 | buf << sfx; |
431 | } |
464 | } |
432 | |
465 | |
433 | break; |
466 | break; |
434 | |
467 | |
435 | default: |
468 | default: |
436 | passthrough: |
469 | passthrough: |
437 | buf << ch; |
470 | buf << ch; |
438 | skip: |
471 | skip: |
439 | break; |
472 | break; |
|
|
473 | |
|
|
474 | verbatim: |
|
|
475 | // elements cannot currently span multiple lines |
|
|
476 | do |
|
|
477 | { |
|
|
478 | buf << "<tt>"; |
|
|
479 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
|
|
480 | buf << "</tt>\n"; |
|
|
481 | |
|
|
482 | while (*cfpod == '\n') |
|
|
483 | buf << *cfpod++; |
|
|
484 | } |
|
|
485 | while (*cfpod == ' '); |
|
|
486 | |
|
|
487 | break; |
440 | } |
488 | } |
441 | } |
489 | } |
442 | |
490 | |
443 | dynbuf_text * |
491 | dynbuf_text * |
444 | player::expand_cfpod (const char *cfpod) const |
492 | player::expand_cfpod (const char *cfpod) const |
445 | { |
493 | { |
446 | static dynbuf_text buf(1024, 1024); |
494 | static dynbuf_text buf(1024, 1024); |
447 | buf.clear (); |
495 | buf.clear (); |
448 | |
496 | |
449 | ::expand_cfpod (this, buf, cfpod, -1); |
497 | ::expand_cfpod (this, buf, cfpod); |
450 | |
498 | |
451 | return &buf; |
499 | return &buf; |
452 | } |
500 | } |
453 | |
501 | |