… | |
… | |
4 | |
4 | |
5 | =cut |
5 | =cut |
6 | |
6 | |
7 | package Crossfire; |
7 | package Crossfire; |
8 | |
8 | |
9 | our $VERSION = '0.92'; |
9 | our $VERSION = '0.96'; |
10 | |
10 | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
… | |
… | |
58 | qw(move_type move_block move_allow move_on move_off move_slow); |
58 | qw(move_type move_block move_allow move_on move_off move_slow); |
59 | |
59 | |
60 | # same as in server save routine, to (hopefully) be compatible |
60 | # same as in server save routine, to (hopefully) be compatible |
61 | # to the other editors. |
61 | # to the other editors. |
62 | our @FIELD_ORDER_MAP = (qw( |
62 | our @FIELD_ORDER_MAP = (qw( |
|
|
63 | file_format_version |
63 | name attach swap_time reset_timeout fixed_resettime difficulty region |
64 | name attach swap_time reset_timeout fixed_resettime difficulty region |
64 | shopitems shopgreed shopmin shopmax shoprace |
65 | shopitems shopgreed shopmin shopmax shoprace |
65 | darkness width height enter_x enter_y msg maplore |
66 | darkness width height enter_x enter_y msg maplore |
66 | unique template |
67 | unique template |
67 | outdoor temp pressure humid windspeed winddir sky nosmooth |
68 | outdoor temp pressure humid windspeed winddir sky nosmooth |
… | |
… | |
199 | while (my ($k, $v) = each %attack_mask) { |
200 | while (my ($k, $v) = each %attack_mask) { |
200 | $ob->{"resist_$k"} = min 100, max -100, $ob->{"resist_$k"} + $value if $mask & $v; |
201 | $ob->{"resist_$k"} = min 100, max -100, $ob->{"resist_$k"} + $value if $mask & $v; |
201 | } |
202 | } |
202 | } |
203 | } |
203 | |
204 | |
|
|
205 | my %MATERIAL = reverse |
|
|
206 | paper => 1, |
|
|
207 | iron => 2, |
|
|
208 | glass => 4, |
|
|
209 | leather => 8, |
|
|
210 | wood => 16, |
|
|
211 | organic => 32, |
|
|
212 | stone => 64, |
|
|
213 | cloth => 128, |
|
|
214 | adamant => 256, |
|
|
215 | liquid => 512, |
|
|
216 | tin => 1024, |
|
|
217 | bone => 2048, |
|
|
218 | ice => 4096, |
|
|
219 | |
|
|
220 | # guesses |
|
|
221 | runestone => 12, |
|
|
222 | bronze => 18, |
|
|
223 | "ancient wood" => 20, |
|
|
224 | glass => 36, |
|
|
225 | marble => 66, |
|
|
226 | ice => 68, |
|
|
227 | stone => 70, |
|
|
228 | stone => 80, |
|
|
229 | cloth => 136, |
|
|
230 | ironwood => 144, |
|
|
231 | adamantium => 258, |
|
|
232 | glacium => 260, |
|
|
233 | blood => 544, |
|
|
234 | ; |
|
|
235 | |
204 | # object as in "Object xxx", i.e. archetypes |
236 | # object as in "Object xxx", i.e. archetypes |
205 | sub normalize_object($) { |
237 | sub normalize_object($) { |
206 | my ($ob) = @_; |
238 | my ($ob) = @_; |
|
|
239 | |
|
|
240 | # convert material bitset to materialname, if possible |
|
|
241 | if (exists $ob->{material}) { |
|
|
242 | if (!$ob->{material}) { |
|
|
243 | delete $ob->{material}; |
|
|
244 | } elsif (exists $ob->{materialname}) { |
|
|
245 | if ($MATERIAL{$ob->{material}} eq $ob->{materialname}) { |
|
|
246 | delete $ob->{material}; |
|
|
247 | } else { |
|
|
248 | warn "object $ob->{_name} has both materialname ($ob->{materialname}) and material ($ob->{material}) set.\n"; |
|
|
249 | delete $ob->{material}; # assume materilname is more specific and nuke material |
|
|
250 | } |
|
|
251 | } elsif (my $name = $MATERIAL{$ob->{material}}) { |
|
|
252 | delete $ob->{material}; |
|
|
253 | $ob->{materialname} = $name; |
|
|
254 | } else { |
|
|
255 | warn "object $ob->{_name} has unknown material ($ob->{material}) set.\n"; |
|
|
256 | } |
|
|
257 | } |
207 | |
258 | |
208 | # nuke outdated or never supported fields |
259 | # nuke outdated or never supported fields |
209 | delete @$ob{qw( |
260 | delete @$ob{qw( |
210 | can_knockback can_parry can_impale can_cut can_dam_armour |
261 | can_knockback can_parry can_impale can_cut can_dam_armour |
211 | can_apply pass_thru can_pass_thru |
262 | can_apply pass_thru can_pass_thru |
… | |
… | |
254 | if (defined (my $v = delete $ob->{slow_move})) { |
305 | if (defined (my $v = delete $ob->{slow_move})) { |
255 | $ob->{move_slow} |= MOVE_WALK; |
306 | $ob->{move_slow} |= MOVE_WALK; |
256 | $ob->{move_slow_penalty} = $v; |
307 | $ob->{move_slow_penalty} = $v; |
257 | } |
308 | } |
258 | if (defined (my $v = delete $ob->{walk_on})) { |
309 | if (defined (my $v = delete $ob->{walk_on})) { |
259 | $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; |
310 | $ob->{move_on} = MOVE_NONE unless exists $ob->{move_on}; |
260 | $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK |
311 | $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK |
261 | : $ob->{move_on} & ~MOVE_WALK; |
312 | : $ob->{move_on} & ~MOVE_WALK; |
262 | } |
313 | } |
263 | if (defined (my $v = delete $ob->{walk_off})) { |
314 | if (defined (my $v = delete $ob->{walk_off})) { |
264 | $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; |
315 | $ob->{move_off} = MOVE_NONE unless exists $ob->{move_off}; |
265 | $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK |
316 | $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK |
266 | : $ob->{move_off} & ~MOVE_WALK; |
317 | : $ob->{move_off} & ~MOVE_WALK; |
267 | } |
318 | } |
268 | if (defined (my $v = delete $ob->{fly_on})) { |
319 | if (defined (my $v = delete $ob->{fly_on})) { |
269 | $ob->{move_on} = MOVE_ALL unless exists $ob->{move_on}; |
320 | $ob->{move_on} = MOVE_NONE unless exists $ob->{move_on}; |
270 | $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW |
321 | $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW |
271 | : $ob->{move_on} & ~MOVE_FLY_LOW; |
322 | : $ob->{move_on} & ~MOVE_FLY_LOW; |
272 | } |
323 | } |
273 | if (defined (my $v = delete $ob->{fly_off})) { |
324 | if (defined (my $v = delete $ob->{fly_off})) { |
274 | $ob->{move_off} = MOVE_ALL unless exists $ob->{move_off}; |
325 | $ob->{move_off} = MOVE_NONE unless exists $ob->{move_off}; |
275 | $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW |
326 | $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW |
276 | : $ob->{move_off} & ~MOVE_FLY_LOW; |
327 | : $ob->{move_off} & ~MOVE_FLY_LOW; |
277 | } |
328 | } |
278 | if (defined (my $v = delete $ob->{flying})) { |
329 | if (defined (my $v = delete $ob->{flying})) { |
279 | $ob->{move_type} = MOVE_ALL unless exists $ob->{move_type}; |
330 | $ob->{move_type} = MOVE_NONE unless exists $ob->{move_type}; |
280 | $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW |
331 | $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW |
281 | : $ob->{move_type} & ~MOVE_FLY_LOW; |
332 | : $ob->{move_type} & ~MOVE_FLY_LOW; |
282 | } |
333 | } |
283 | |
334 | |
284 | # convert idiotic event_xxx things into objects |
335 | # convert idiotic event_xxx things into objects |
… | |
… | |
384 | sub read_arch($;$) { |
435 | sub read_arch($;$) { |
385 | my ($path, $toplevel) = @_; |
436 | my ($path, $toplevel) = @_; |
386 | |
437 | |
387 | my %arc; |
438 | my %arc; |
388 | my ($more, $prev); |
439 | my ($more, $prev); |
|
|
440 | my $comment; |
389 | |
441 | |
390 | open my $fh, "<:raw:perlio:utf8", $path |
442 | open my $fh, "<:raw:perlio:utf8", $path |
391 | or Carp::croak "$path: $!"; |
443 | or Carp::croak "$path: $!"; |
392 | |
444 | |
393 | # binmode $fh; |
445 | # binmode $fh; |
… | |
… | |
397 | |
449 | |
398 | while (<$fh>) { |
450 | while (<$fh>) { |
399 | s/\s+$//; |
451 | s/\s+$//; |
400 | if (/^end$/i) { |
452 | if (/^end$/i) { |
401 | last; |
453 | last; |
|
|
454 | |
402 | } elsif (/^arch (\S+)$/i) { |
455 | } elsif (/^arch (\S+)$/i) { |
403 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
456 | push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); |
|
|
457 | |
404 | } elsif (/^lore$/i) { |
458 | } elsif (/^lore$/i) { |
405 | while (<$fh>) { |
459 | while (<$fh>) { |
406 | last if /^endlore\s*$/i; |
460 | last if /^endlore\s*$/i; |
407 | $arc{lore} .= $_; |
461 | $arc{lore} .= $_; |
408 | } |
462 | } |
… | |
… | |
417 | chomp; |
471 | chomp; |
418 | push @{ $arc{anim} }, $_; |
472 | push @{ $arc{anim} }, $_; |
419 | } |
473 | } |
420 | } elsif (/^(\S+)\s*(.*)$/) { |
474 | } elsif (/^(\S+)\s*(.*)$/) { |
421 | $arc{lc $1} = $2; |
475 | $arc{lc $1} = $2; |
422 | } elsif (/^\s*($|#)/) { |
476 | } elsif (/^\s*#/) { |
|
|
477 | $arc{_comment} .= "$_\n"; |
|
|
478 | |
|
|
479 | } elsif (/^\s*$/) { |
423 | # |
480 | # |
424 | } else { |
481 | } else { |
425 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
482 | warn "$path: unparsable line '$_' in arch $arc{_name}"; |
426 | } |
483 | } |
427 | } |
484 | } |
… | |
… | |
433 | s/\s+$//; |
490 | s/\s+$//; |
434 | if (/^more$/i) { |
491 | if (/^more$/i) { |
435 | $more = $prev; |
492 | $more = $prev; |
436 | } elsif (/^object (\S+)$/i) { |
493 | } elsif (/^object (\S+)$/i) { |
437 | my $name = $1; |
494 | my $name = $1; |
438 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name); |
495 | my $arc = attr_thaw normalize_object $parse_block->(_name => $name, _comment => $comment); |
|
|
496 | undef $comment; |
|
|
497 | delete $arc{_comment} unless length $arc{_comment}; |
439 | $arc->{_atype} = 'object'; |
498 | $arc->{_atype} = 'object'; |
440 | |
499 | |
441 | if ($more) { |
500 | if ($more) { |
442 | $more->{more} = $arc; |
501 | $more->{more} = $arc; |
443 | } else { |
502 | } else { |
… | |
… | |
445 | } |
504 | } |
446 | $prev = $arc; |
505 | $prev = $arc; |
447 | $more = undef; |
506 | $more = undef; |
448 | } elsif (/^arch (\S+)$/i) { |
507 | } elsif (/^arch (\S+)$/i) { |
449 | my $name = $1; |
508 | my $name = $1; |
450 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); |
509 | my $arc = attr_thaw normalize_arch $parse_block->(_name => $name, _comment => $comment); |
|
|
510 | undef $comment; |
|
|
511 | delete $arc{_comment} unless length $arc{_comment}; |
451 | $arc->{_atype} = 'arch'; |
512 | $arc->{_atype} = 'arch'; |
452 | |
513 | |
453 | if ($more) { |
514 | if ($more) { |
454 | $more->{more} = $arc; |
515 | $more->{more} = $arc; |
455 | } else { |
516 | } else { |
… | |
… | |
464 | push @{$toplevel->{lev_array}}, $_+0; |
525 | push @{$toplevel->{lev_array}}, $_+0; |
465 | } |
526 | } |
466 | } else { |
527 | } else { |
467 | $toplevel->{$1} = $2; |
528 | $toplevel->{$1} = $2; |
468 | } |
529 | } |
|
|
530 | } elsif (/^\s*#/) { |
|
|
531 | $comment .= "$_\n"; |
469 | } elsif (/^\s*($|#)/) { |
532 | } elsif (/^\s*($|#)/) { |
470 | # |
533 | # |
471 | } else { |
534 | } else { |
472 | die "$path: unparseable top-level line '$_'"; |
535 | die "$path: unparseable top-level line '$_'"; |
473 | } |
536 | } |
… | |
… | |
493 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
556 | if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { |
494 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
557 | $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) |
495 | | (delete $a{attack_movement_bits_4_7}); |
558 | | (delete $a{attack_movement_bits_4_7}); |
496 | } |
559 | } |
497 | |
560 | |
|
|
561 | if (my $comment = delete $a{_comment}) { |
|
|
562 | if ($comment =~ /[^\n\s#]/) { |
|
|
563 | $str .= $comment; |
|
|
564 | } |
|
|
565 | } |
|
|
566 | |
498 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
567 | $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; |
499 | |
568 | |
500 | my $inv = delete $a{inventory}; |
569 | my $inv = delete $a{inventory}; |
501 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
570 | my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some |
502 | my $anim = delete $a{anim}; |
571 | my $anim = delete $a{anim}; |
|
|
572 | |
|
|
573 | if ($a{_atype} eq 'object') { |
|
|
574 | $str .= join "\n", "anim", @$anim, "mina\n" |
|
|
575 | if $anim; |
|
|
576 | } |
503 | |
577 | |
504 | my @kv; |
578 | my @kv; |
505 | |
579 | |
506 | for ($a{_name} eq "map" |
580 | for ($a{_name} eq "map" |
507 | ? @Crossfire::FIELD_ORDER_MAP |
581 | ? @Crossfire::FIELD_ORDER_MAP |
… | |
… | |
554 | |
628 | |
555 | if ($inv) { |
629 | if ($inv) { |
556 | $append->($_) for @$inv; |
630 | $append->($_) for @$inv; |
557 | } |
631 | } |
558 | |
632 | |
|
|
633 | $str .= "end\n"; |
|
|
634 | |
559 | if ($a{_atype} eq 'object') { |
635 | if ($a{_atype} eq 'object') { |
560 | $str .= join "\n", "anim", @$anim, "mina\n" |
636 | if ($more) { |
561 | if $anim; |
|
|
562 | } |
|
|
563 | |
|
|
564 | $str .= "end\n"; |
|
|
565 | |
|
|
566 | if (($a{_atype} eq 'object') && $more) { |
|
|
567 | $str .= "\nmore\n"; |
637 | $str .= "more\n"; |
568 | $append->($more) if $more; |
638 | $append->($more) if $more; |
|
|
639 | } else { |
|
|
640 | $str .= "\n"; |
|
|
641 | } |
569 | } |
642 | } |
570 | }; |
643 | }; |
571 | |
644 | |
572 | for (@$arch) { |
645 | for (@$arch) { |
573 | $append->($_); |
646 | $append->($_); |
… | |
… | |
602 | my ($a) = @_; |
675 | my ($a) = @_; |
603 | |
676 | |
604 | my $o = $ARCH{$a->{_name}} |
677 | my $o = $ARCH{$a->{_name}} |
605 | or return; |
678 | or return; |
606 | |
679 | |
607 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"} |
680 | my $face = $FACE{$a->{face} || $o->{face} || "blank.111"}; |
|
|
681 | unless ($face) { |
|
|
682 | $face = $FACE{"blank.x11"} |
608 | or (warn "no face data found for arch '$a->{_name}'"), return; |
683 | or (warn "no face data found for arch '$a->{_name}'"), return; |
|
|
684 | } |
609 | |
685 | |
610 | if ($face->{w} > 1 || $face->{h} > 1) { |
686 | if ($face->{w} > 1 || $face->{h} > 1) { |
611 | # bigface |
687 | # bigface |
612 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
688 | return (0, 0, $face->{w} - 1, $face->{h} - 1); |
613 | |
689 | |
… | |
… | |
720 | ]; |
796 | ]; |
721 | |
797 | |
722 | $attr |
798 | $attr |
723 | } |
799 | } |
724 | |
800 | |
725 | sub arch_edit_sections { |
|
|
726 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
|
|
727 | # edit_type = 0; |
|
|
728 | # else if (edit_type != 0) { |
|
|
729 | # // all flags from 'check_type' must be unset in this arch because they get recalculated now |
|
|
730 | # edit_type &= ~check_type; |
|
|
731 | # } |
|
|
732 | # |
|
|
733 | # } |
|
|
734 | # if ((check_type & IGUIConstants.TILE_EDIT_MONSTER) != 0 && |
|
|
735 | # getAttributeValue("alive", defarch) == 1 && |
|
|
736 | # (getAttributeValue("monster", defarch) == 1 || |
|
|
737 | # getAttributeValue("generator", defarch) == 1)) { |
|
|
738 | # // Monster: monsters/npcs/generators |
|
|
739 | # edit_type |= IGUIConstants.TILE_EDIT_MONSTER; |
|
|
740 | # } |
|
|
741 | # if ((check_type & IGUIConstants.TILE_EDIT_WALL) != 0 && |
|
|
742 | # arch_type == 0 && getAttributeValue("no_pass", defarch) == 1) { |
|
|
743 | # // Walls |
|
|
744 | # edit_type |= IGUIConstants.TILE_EDIT_WALL; |
|
|
745 | # } |
|
|
746 | # if ((check_type & IGUIConstants.TILE_EDIT_CONNECTED) != 0 && |
|
|
747 | # getAttributeValue("connected", defarch) != 0) { |
|
|
748 | # // Connected Objects |
|
|
749 | # edit_type |= IGUIConstants.TILE_EDIT_CONNECTED; |
|
|
750 | # } |
|
|
751 | # if ((check_type & IGUIConstants.TILE_EDIT_EXIT) != 0 && |
|
|
752 | # arch_type == 66 || arch_type == 41 || arch_type == 95) { |
|
|
753 | # // Exit: teleporter/exit/trapdoors |
|
|
754 | # edit_type |= IGUIConstants.TILE_EDIT_EXIT; |
|
|
755 | # } |
|
|
756 | # if ((check_type & IGUIConstants.TILE_EDIT_TREASURE) != 0 && |
|
|
757 | # getAttributeValue("no_pick", defarch) == 0 && (arch_type == 4 || |
|
|
758 | # arch_type == 5 || arch_type == 36 || arch_type == 60 || |
|
|
759 | # arch_type == 85 || arch_type == 111 || arch_type == 123 || |
|
|
760 | # arch_type == 124 || arch_type == 130)) { |
|
|
761 | # // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls |
|
|
762 | # edit_type |= IGUIConstants.TILE_EDIT_TREASURE; |
|
|
763 | # } |
|
|
764 | # if ((check_type & IGUIConstants.TILE_EDIT_DOOR) != 0 && |
|
|
765 | # arch_type == 20 || arch_type == 23 || arch_type == 26 || |
|
|
766 | # arch_type == 91 || arch_type == 21 || arch_type == 24) { |
|
|
767 | # // Door: door/special door/gates + keys |
|
|
768 | # edit_type |= IGUIConstants.TILE_EDIT_DOOR; |
|
|
769 | # } |
|
|
770 | # if ((check_type & IGUIConstants.TILE_EDIT_EQUIP) != 0 && |
|
|
771 | # getAttributeValue("no_pick", defarch) == 0 && ((arch_type >= 13 && |
|
|
772 | # arch_type <= 16) || arch_type == 33 || arch_type == 34 || |
|
|
773 | # arch_type == 35 || arch_type == 39 || arch_type == 70 || |
|
|
774 | # arch_type == 87 || arch_type == 99 || arch_type == 100 || |
|
|
775 | # arch_type == 104 || arch_type == 109 || arch_type == 113 || |
|
|
776 | # arch_type == 122 || arch_type == 3)) { |
|
|
777 | # // Equipment: weapons/armour/wands/rods |
|
|
778 | # edit_type |= IGUIConstants.TILE_EDIT_EQUIP; |
|
|
779 | # } |
|
|
780 | # |
|
|
781 | # return(edit_type); |
|
|
782 | # |
|
|
783 | # |
|
|
784 | } |
|
|
785 | |
|
|
786 | sub cache_file($$&&) { |
801 | sub cache_file($$&&) { |
787 | my ($src, $cache, $load, $create) = @_; |
802 | my ($src, $cache, $load, $create) = @_; |
788 | |
803 | |
789 | my ($size, $mtime) = (stat $src)[7,9] |
804 | my ($size, $mtime) = (stat $src)[7,9] |
790 | or Carp::croak "$src: $!"; |
805 | or Carp::croak "$src: $!"; |