--- deliantra/Deliantra/Deliantra.pm 2006/08/27 16:33:19 1.70 +++ deliantra/Deliantra/Deliantra.pm 2006/08/31 21:09:32 1.71 @@ -390,6 +390,7 @@ } elsif (/^object (\S+)$/i) { my $name = $1; my $arc = attr_thaw normalize_object $parse_block->(_name => $name); + $arc->{_atype} = 'object'; if ($more) { $more->{more} = $arc; @@ -401,6 +402,7 @@ } elsif (/^arch (\S+)$/i) { my $name = $1; my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); + $arc->{_atype} = 'arch'; if ($more) { $more->{more} = $arc; @@ -430,6 +432,104 @@ \%arc } +sub archlist_to_string { + my ($arch) = @_; + + my $str; + + my $append; $append = sub { + my %a = %{$_[0]}; + + Crossfire::attr_freeze \%a; + Crossfire::normalize_arch \%a; + + # undo the bit-split we did before + if (exists $a{attack_movement_bits_0_3} or exists $a{attack_movement_bits_4_7}) { + $a{attack_movement} = (delete $a{attack_movement_bits_0_3}) + | (delete $a{attack_movement_bits_4_7}); + } + + $str .= ((exists $a{_atype}) ? $a{_atype} : 'arch'). " $a{_name}\n"; + + my $inv = delete $a{inventory}; + my $more = delete $a{more}; # arches do not support 'more', but old maps can contain some + my $anim = delete $a{anim}; + + my @kv; + + for ($a{_name} eq "map" + ? @Crossfire::FIELD_ORDER_MAP + : @Crossfire::FIELD_ORDER) { + push @kv, [$_, delete $a{$_}] + if exists $a{$_}; + } + + for (sort keys %a) { + next if /^_/; # ignore our _-keys + push @kv, [$_, delete $a{$_}]; + } + + for (@kv) { + my ($k, $v) = @$_; + + if (my $end = $Crossfire::FIELD_MULTILINE{$k}) { + $v =~ s/\n$//; + $str .= "$k\n$v\n$end\n"; + } elsif (exists $Crossfire::FIELD_MOVEMENT{$k}) { + if ($v & ~Crossfire::MOVE_ALL or !$v) { + $str .= "$k $v\n"; + + } elsif ($v & Crossfire::MOVE_ALLBIT) { + $str .= "$k all"; + + $str .= " -walk" unless $v & Crossfire::MOVE_WALK; + $str .= " -fly_low" unless $v & Crossfire::MOVE_FLY_LOW; + $str .= " -fly_high" unless $v & Crossfire::MOVE_FLY_HIGH; + $str .= " -swim" unless $v & Crossfire::MOVE_SWIM; + $str .= " -boat" unless $v & Crossfire::MOVE_BOAT; + + $str .= "\n"; + + } else { + $str .= $k; + + $str .= " walk" if $v & Crossfire::MOVE_WALK; + $str .= " fly_low" if $v & Crossfire::MOVE_FLY_LOW; + $str .= " fly_high" if $v & Crossfire::MOVE_FLY_HIGH; + $str .= " swim" if $v & Crossfire::MOVE_SWIM; + $str .= " boat" if $v & Crossfire::MOVE_BOAT; + + $str .= "\n"; + } + } else { + $str .= "$k $v\n"; + } + } + + if ($inv) { + $append->($_) for @$inv; + } + + if ($a{_atype} eq 'object') { + $str .= join "\n", "anim", @$anim, "mina\n" + if $anim; + } + + $str .= "end\n"; + + if (($a{_atype} eq 'object') && $more) { + $str .= "\nmore\n"; + $append->($more) if $more; + } + }; + + for (@$arch) { + $append->($_); + } + + $str +} + # put all archs into a hash with editor_face as it's key # NOTE: the arrays in the hash values are references to # the archs from $ARCH