… | |
… | |
6 | |
6 | |
7 | =cut |
7 | =cut |
8 | |
8 | |
9 | package Deliantra; |
9 | package Deliantra; |
10 | |
10 | |
11 | our $VERSION = '1.25'; |
11 | our $VERSION = '1.30'; |
12 | |
12 | |
13 | use common::sense; |
13 | use common::sense; |
14 | |
14 | |
15 | use base 'Exporter'; |
15 | use base 'Exporter'; |
16 | |
16 | |
… | |
… | |
56 | |
56 | |
57 | # same as in server save routine, to (hopefully) be compatible |
57 | # same as in server save routine, to (hopefully) be compatible |
58 | # to the other editors. |
58 | # to the other editors. |
59 | our @FIELD_ORDER_MAP = (qw( |
59 | our @FIELD_ORDER_MAP = (qw( |
60 | file_format_version |
60 | file_format_version |
61 | name attach swap_time reset_timeout fixed_resettime difficulty region |
61 | name attach swap_time reset_timeout fixed_resettime difficulty |
|
|
62 | region music |
62 | shopitems shopgreed shopmin shopmax shoprace |
63 | shopitems shopgreed shopmin shopmax shoprace |
63 | darkness width height enter_x enter_y msg maplore |
64 | darkness width height enter_x enter_y msg maplore |
64 | unique template |
65 | unique template |
65 | outdoor temp pressure humid windspeed winddir sky nosmooth |
66 | outdoor temp pressure humid windspeed winddir sky nosmooth |
66 | tile_path_1 tile_path_2 tile_path_3 tile_path_4 |
67 | tile_path_1 tile_path_2 tile_path_3 tile_path_4 |
… | |
… | |
162 | |
163 | |
163 | use overload |
164 | use overload |
164 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
165 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
165 | '""' => \&as_string, |
166 | '""' => \&as_string, |
166 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
167 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
|
|
168 | '<=' => sub { |
|
|
169 | ($_[0][0] & $MOVE_TYPE{$_[1]}) == $MOVE_TYPE{$_[1]} |
|
|
170 | ? $_[0][1] & $MOVE_TYPE{$_[1]} |
|
|
171 | : undef |
|
|
172 | }, |
167 | '+=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] |= $MOVE_TYPE{$_[1]}; &normalise }, |
173 | '+=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] |= $MOVE_TYPE{$_[1]}; &normalise }, |
168 | '-=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
174 | '-=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
169 | '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
175 | '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
170 | 'x=' => sub { |
176 | 'x=' => sub { # toggle between off, + and - |
171 | my $cur = $_[0] >= $_[1]; |
177 | my $cur = $_[0] >= $_[1]; |
172 | if (!defined $cur) { |
178 | if (!defined $cur) { |
173 | if ($_[0] >= "all") { |
179 | if ($_[0] >= "all") { |
174 | $_[0] -= $_[1]; |
180 | $_[0] -= $_[1]; |
175 | } else { |
181 | } else { |
… | |
… | |
809 | } else { |
815 | } else { |
810 | $root = $Deliantra::Data::TYPE{Misc}; |
816 | $root = $Deliantra::Data::TYPE{Misc}; |
811 | } |
817 | } |
812 | } |
818 | } |
813 | |
819 | |
|
|
820 | my (%ignore); |
814 | my @import = ($root); |
821 | my @import = ($root); |
815 | |
|
|
816 | unshift @import, \%Deliantra::Data::DEFAULT_ATTR |
|
|
817 | unless $type == 116; |
|
|
818 | |
822 | |
819 | my (%ignore); |
823 | my @new_import; |
820 | my (@section_order, %section, @attr_order); |
|
|
821 | |
|
|
822 | while (my $type = shift @import) { |
824 | while (my $type = shift @import) { |
|
|
825 | # first import everything we will need: |
823 | push @import, |
826 | push @import, |
824 | grep $_, |
827 | grep $_, |
825 | map $Deliantra::Data::TYPE{$_}, |
828 | map $Deliantra::Data::TYPE{$_}, |
826 | @{$type->{import} || []}; |
829 | @{$type->{import} || []}; |
827 | |
830 | |
|
|
831 | # and compute the ignored attributes |
|
|
832 | for (@{$type->{ignore} || []}) { |
|
|
833 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
834 | } |
|
|
835 | |
|
|
836 | push @new_import, $type; |
|
|
837 | } |
|
|
838 | (@import) = @new_import; |
|
|
839 | |
|
|
840 | # then add defaults to the back of the list, so they are added |
|
|
841 | # as last resort. |
|
|
842 | push @import, \%Deliantra::Data::DEFAULT_ATTR |
|
|
843 | unless $type == 116; |
|
|
844 | |
|
|
845 | my (@section_order, %section, @attr_order); |
|
|
846 | |
|
|
847 | # @import = root, imported, default |
|
|
848 | while (my $type = pop @import) { |
828 | $attr->{$_} ||= $type->{$_} |
849 | $attr->{$_} ||= $type->{$_} |
829 | for qw(name desc use); |
850 | for qw(name desc use); |
830 | |
|
|
831 | for (@{$type->{ignore} || []}) { |
|
|
832 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
833 | } |
|
|
834 | |
851 | |
835 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
852 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
836 | my ($name, $attr) = @$_; |
853 | my ($name, $attr) = @$_; |
837 | push @section_order, $name; |
854 | push @section_order, $name; |
838 | for (@$attr) { |
855 | for (@$attr) { |
839 | my ($k, $v) = @$_; |
856 | my ($k, $v) = @$_; |
840 | push @attr_order, $k; |
857 | push @attr_order, $k; |
841 | $section{$name}{$k} ||= $v; |
858 | $section{$name}{$k} = $v; # overwrite, so that the root decides |
842 | } |
|
|
843 | } |
859 | } |
|
|
860 | } |
|
|
861 | } |
|
|
862 | |
|
|
863 | # remove ignores for "root" type |
|
|
864 | for ( |
|
|
865 | map @{$_->[1]}, # section attributes |
|
|
866 | [general => ($root->{attr} || [])], |
|
|
867 | @{$root->{section} || []} |
|
|
868 | ) { |
|
|
869 | my ($k, $v) = @$_; |
|
|
870 | # skip fixed attributes, if they are ignored thats fine |
|
|
871 | next if $v->{type} eq 'fixed'; |
|
|
872 | |
|
|
873 | delete $ignore{$k}; # if the attributes are defined explicitly they |
|
|
874 | # should NOT be ignored. ignore should mainly |
|
|
875 | # hit imported/inherited attributes. |
844 | } |
876 | } |
845 | |
877 | |
846 | $attr->{section} = [ |
878 | $attr->{section} = [ |
847 | map !exists $section{$_} ? () : do { |
879 | map !exists $section{$_} ? () : do { |
848 | my $attr = delete $section{$_}; |
880 | my $attr = delete $section{$_}; |
… | |
… | |
852 | map exists $attr->{$_} && !$ignore{$_} |
884 | map exists $attr->{$_} && !$ignore{$_} |
853 | ? [$_ => delete $attr->{$_}] : (), |
885 | ? [$_ => delete $attr->{$_}] : (), |
854 | @attr_order |
886 | @attr_order |
855 | ] |
887 | ] |
856 | }, |
888 | }, |
857 | |
|
|
858 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
889 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
859 | @section_order |
890 | @section_order |
860 | ]; |
891 | ]; |
861 | |
892 | |
862 | $attr |
893 | $attr |
863 | } |
894 | } |