… | |
… | |
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.29'; |
12 | |
12 | |
13 | use common::sense; |
13 | use common::sense; |
14 | |
14 | |
15 | use base 'Exporter'; |
15 | use base 'Exporter'; |
16 | |
16 | |
… | |
… | |
162 | |
162 | |
163 | use overload |
163 | use overload |
164 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
164 | '=' => sub { bless [@{$_[0]}], ref $_[0] }, |
165 | '""' => \&as_string, |
165 | '""' => \&as_string, |
166 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
166 | '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, |
|
|
167 | '<=' => sub { |
|
|
168 | ($_[0][0] & $MOVE_TYPE{$_[1]}) == $MOVE_TYPE{$_[1]} |
|
|
169 | ? $_[0][1] & $MOVE_TYPE{$_[1]} |
|
|
170 | : undef |
|
|
171 | }, |
167 | '+=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] |= $MOVE_TYPE{$_[1]}; &normalise }, |
172 | '+=' => 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 }, |
173 | '-=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
169 | '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
174 | '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, |
170 | 'x=' => sub { |
175 | 'x=' => sub { # toggle between off, + and - |
171 | my $cur = $_[0] >= $_[1]; |
176 | my $cur = $_[0] >= $_[1]; |
172 | if (!defined $cur) { |
177 | if (!defined $cur) { |
173 | if ($_[0] >= "all") { |
178 | if ($_[0] >= "all") { |
174 | $_[0] -= $_[1]; |
179 | $_[0] -= $_[1]; |
175 | } else { |
180 | } else { |
… | |
… | |
339 | |
344 | |
340 | # object as in "Object xxx", i.e. archetypes |
345 | # object as in "Object xxx", i.e. archetypes |
341 | sub normalize_object($) { |
346 | sub normalize_object($) { |
342 | my ($ob) = @_; |
347 | my ($ob) = @_; |
343 | |
348 | |
|
|
349 | delete $ob->{editable}; # deprecated |
|
|
350 | |
344 | # convert material bitset to materialname, if possible |
351 | # convert material bitset to materialname, if possible |
345 | if (exists $ob->{material}) { |
352 | if (exists $ob->{material}) { |
346 | if (!$ob->{material}) { |
353 | if (!$ob->{material}) { |
347 | delete $ob->{material}; |
354 | delete $ob->{material}; |
348 | } elsif (exists $ob->{materialname}) { |
355 | } elsif (exists $ob->{materialname}) { |
… | |
… | |
807 | } else { |
814 | } else { |
808 | $root = $Deliantra::Data::TYPE{Misc}; |
815 | $root = $Deliantra::Data::TYPE{Misc}; |
809 | } |
816 | } |
810 | } |
817 | } |
811 | |
818 | |
|
|
819 | my (%ignore); |
812 | my @import = ($root); |
820 | my @import = ($root); |
813 | |
|
|
814 | unshift @import, \%Deliantra::Data::DEFAULT_ATTR |
|
|
815 | unless $type == 116; |
|
|
816 | |
821 | |
817 | my (%ignore); |
822 | my @new_import; |
818 | my (@section_order, %section, @attr_order); |
|
|
819 | |
|
|
820 | while (my $type = shift @import) { |
823 | while (my $type = shift @import) { |
|
|
824 | # first import everything we will need: |
821 | push @import, |
825 | push @import, |
822 | grep $_, |
826 | grep $_, |
823 | map $Deliantra::Data::TYPE{$_}, |
827 | map $Deliantra::Data::TYPE{$_}, |
824 | @{$type->{import} || []}; |
828 | @{$type->{import} || []}; |
825 | |
829 | |
|
|
830 | # and compute the ignored attributes |
|
|
831 | for (@{$type->{ignore} || []}) { |
|
|
832 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
833 | } |
|
|
834 | |
|
|
835 | push @new_import, $type; |
|
|
836 | } |
|
|
837 | (@import) = @new_import; |
|
|
838 | |
|
|
839 | # then add defaults to the back of the list, so they are added |
|
|
840 | # as last resort. |
|
|
841 | push @import, \%Deliantra::Data::DEFAULT_ATTR |
|
|
842 | unless $type == 116; |
|
|
843 | |
|
|
844 | my (@section_order, %section, @attr_order); |
|
|
845 | |
|
|
846 | # @import = root, imported, default |
|
|
847 | while (my $type = pop @import) { |
826 | $attr->{$_} ||= $type->{$_} |
848 | $attr->{$_} ||= $type->{$_} |
827 | for qw(name desc use); |
849 | for qw(name desc use); |
828 | |
|
|
829 | for (@{$type->{ignore} || []}) { |
|
|
830 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
831 | } |
|
|
832 | |
850 | |
833 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
851 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
834 | my ($name, $attr) = @$_; |
852 | my ($name, $attr) = @$_; |
835 | push @section_order, $name; |
853 | push @section_order, $name; |
836 | for (@$attr) { |
854 | for (@$attr) { |
837 | my ($k, $v) = @$_; |
855 | my ($k, $v) = @$_; |
838 | push @attr_order, $k; |
856 | push @attr_order, $k; |
839 | $section{$name}{$k} ||= $v; |
857 | $section{$name}{$k} = $v; # overwrite, so that the root decides |
840 | } |
|
|
841 | } |
858 | } |
|
|
859 | } |
|
|
860 | } |
|
|
861 | |
|
|
862 | # remove ignores for "root" type |
|
|
863 | for ( |
|
|
864 | map @{$_->[1]}, # section attributes |
|
|
865 | [general => ($root->{attr} || [])], |
|
|
866 | @{$root->{section} || []} |
|
|
867 | ) { |
|
|
868 | my ($k, $v) = @$_; |
|
|
869 | # skip fixed attributes, if they are ignored thats fine |
|
|
870 | next if $v->{type} eq 'fixed'; |
|
|
871 | |
|
|
872 | delete $ignore{$k}; # if the attributes are defined explicitly they |
|
|
873 | # should NOT be ignored. ignore should mainly |
|
|
874 | # hit imported/inherited attributes. |
842 | } |
875 | } |
843 | |
876 | |
844 | $attr->{section} = [ |
877 | $attr->{section} = [ |
845 | map !exists $section{$_} ? () : do { |
878 | map !exists $section{$_} ? () : do { |
846 | my $attr = delete $section{$_}; |
879 | my $attr = delete $section{$_}; |
… | |
… | |
850 | map exists $attr->{$_} && !$ignore{$_} |
883 | map exists $attr->{$_} && !$ignore{$_} |
851 | ? [$_ => delete $attr->{$_}] : (), |
884 | ? [$_ => delete $attr->{$_}] : (), |
852 | @attr_order |
885 | @attr_order |
853 | ] |
886 | ] |
854 | }, |
887 | }, |
855 | |
|
|
856 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
888 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
857 | @section_order |
889 | @section_order |
858 | ]; |
890 | ]; |
859 | |
891 | |
860 | $attr |
892 | $attr |
861 | } |
893 | } |