--- deliantra/Deliantra/Deliantra.pm 2006/02/09 20:54:42 1.13 +++ deliantra/Deliantra/Deliantra.pm 2006/02/11 16:17:14 1.14 @@ -31,17 +31,81 @@ our $ARCH; our %FIELD_MULTILINE = ( - msg => "endmsg", + msg => "endmsg", + lore => "endlore", ); # not used yet, maybe alphabetical is ok our @FIELD_ORDER = (qw(name name_pl)); -# not used yet, AND NOT CHECKED, should also be BY TYPE -our %FIELD_NORMALIZE = ( - "enter_x" => "hp", - "enter_y" => "sp", -); +sub MOVE_WALK (){ 0x1 } +sub MOVE_FLY_LOW (){ 0x2 } +sub MOVE_FLY_HIGH (){ 0x4 } +sub MOVE_FLYING (){ 0x6 } +sub MOVE_SWIM (){ 0x8 } +sub MOVE_ALL (){ 0xf } + +sub normalize_arch($) { + my ($ob) = @_; + + my $arch = $ARCH->{$ob->{_name}} + or (warn "$ob->{_name}: no such archetype", return $ob); + + delete $ob->{$_} for qw(can_knockback can_parry can_impale can_cut can_dam_armour can_apply); + + if ($arch->{type} == 22) { # map + my %normalize = ( + "enter_x" => "hp", + "enter_y" => "sp", + "width" => "x", + "height" => "y", + "reset_timeout" => "weight", + "swap_time" => "value", + "difficulty" => "level", + "darkness" => "invisible", + "fixed_resettime" => "stand_still", + ); + + while (my ($k2, $k1) = each %normalize) { + if (defined (my $v = delete $ob->{$k1})) { + $ob->{$k2} = $v; + } + } + } + + if (defined (my $v = delete $ob->{no_pass})) { + $ob->{move_block} = $v ? MOVE_ALL : 0; + } + if (defined (my $v = delete $ob->{walk_on})) { + $ob->{move_on} = $v ? $ob->{move_on} | MOVE_WALK + : $ob->{move_on} & ~MOVE_WALK; + } + if (defined (my $v = delete $ob->{walk_off})) { + $ob->{move_off} = $v ? $ob->{move_off} | MOVE_WALK + : $ob->{move_off} & ~MOVE_WALK; + } + if (defined (my $v = delete $ob->{fly_on})) { + $ob->{move_on} = $v ? $ob->{move_on} | MOVE_FLY_LOW + : $ob->{move_on} & ~MOVE_FLY_LOW; + } + if (defined (my $v = delete $ob->{fly_off})) { + $ob->{move_off} = $v ? $ob->{move_off} | MOVE_FLY_LOW + : $ob->{move_off} & ~MOVE_FLY_LOW; + } + if (defined (my $v = delete $ob->{flying})) { + $ob->{move_type} = $v ? $ob->{move_type} | MOVE_FLY_LOW + : $ob->{move_type} & ~MOVE_FLY_LOW; + } + + # if value matches archetype default, delete + while (my ($k, $v) = each %$ob) { + if (exists $arch->{$k} and $arch->{$k} eq $v) { + delete $ob->{$k}; + } + } + + $ob +} sub read_pak($;$) { my ($path, $cache) = @_; @@ -90,7 +154,7 @@ if (/^end$/i) { last; } elsif (/^arch (\S+)$/) { - push @{ $arc{inventory} }, $parse_block->(_name => $1); + push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1); } elsif (/^lore$/) { while (<$fh>) { last if /^endlore\s*$/i; @@ -129,7 +193,7 @@ $prev = $arc; $more = undef; } elsif (/^arch (\S+)$/i) { - push @{ $arc{arch} }, $parse_block->(_name => $1); + push @{ $arc{arch} }, normalize_arch $parse_block->(_name => $1); } elsif (/^\s*($|#)/) { # } else {