… | |
… | |
4 | |
4 | |
5 | =cut |
5 | =cut |
6 | |
6 | |
7 | package Crossfire; |
7 | package Crossfire; |
8 | |
8 | |
9 | our $VERSION = '0.95'; |
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 |
… | |
… | |
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}; |
503 | |
572 | |
504 | my @kv; |
573 | my @kv; |
505 | |
574 | |
… | |
… | |
561 | if $anim; |
630 | if $anim; |
562 | } |
631 | } |
563 | |
632 | |
564 | $str .= "end\n"; |
633 | $str .= "end\n"; |
565 | |
634 | |
566 | if (($a{_atype} eq 'object') && $more) { |
635 | if ($a{_atype} eq 'object') { |
|
|
636 | if ($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 | |