ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.134 by root, Wed Oct 28 10:17:01 2009 UTC vs.
Revision 1.142 by root, Sat May 15 00:30:53 2010 UTC

6 6
7=cut 7=cut
8 8
9package Deliantra; 9package Deliantra;
10 10
11our $VERSION = '1.25'; 11our $VERSION = '1.30';
12 12
13use common::sense; 13use common::sense;
14 14
15use base 'Exporter'; 15use 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.
59our @FIELD_ORDER_MAP = (qw( 59our @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 {
339 345
340# object as in "Object xxx", i.e. archetypes 346# object as in "Object xxx", i.e. archetypes
341sub normalize_object($) { 347sub normalize_object($) {
342 my ($ob) = @_; 348 my ($ob) = @_;
343 349
350 delete $ob->{editable}; # deprecated
351
344 # convert material bitset to materialname, if possible 352 # convert material bitset to materialname, if possible
345 if (exists $ob->{material}) { 353 if (exists $ob->{material}) {
346 if (!$ob->{material}) { 354 if (!$ob->{material}) {
347 delete $ob->{material}; 355 delete $ob->{material};
348 } elsif (exists $ob->{materialname}) { 356 } elsif (exists $ob->{materialname}) {
807 } else { 815 } else {
808 $root = $Deliantra::Data::TYPE{Misc}; 816 $root = $Deliantra::Data::TYPE{Misc};
809 } 817 }
810 } 818 }
811 819
820 my (%ignore);
812 my @import = ($root); 821 my @import = ($root);
813
814 unshift @import, \%Deliantra::Data::DEFAULT_ATTR
815 unless $type == 116;
816 822
817 my (%ignore); 823 my @new_import;
818 my (@section_order, %section, @attr_order);
819
820 while (my $type = shift @import) { 824 while (my $type = shift @import) {
825 # first import everything we will need:
821 push @import, 826 push @import,
822 grep $_, 827 grep $_,
823 map $Deliantra::Data::TYPE{$_}, 828 map $Deliantra::Data::TYPE{$_},
824 @{$type->{import} || []}; 829 @{$type->{import} || []};
825 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) {
826 $attr->{$_} ||= $type->{$_} 849 $attr->{$_} ||= $type->{$_}
827 for qw(name desc use); 850 for qw(name desc use);
828
829 for (@{$type->{ignore} || []}) {
830 $ignore{$_}++ for ref $_ ? @$_ : $_;
831 }
832 851
833 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { 852 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
834 my ($name, $attr) = @$_; 853 my ($name, $attr) = @$_;
835 push @section_order, $name; 854 push @section_order, $name;
836 for (@$attr) { 855 for (@$attr) {
837 my ($k, $v) = @$_; 856 my ($k, $v) = @$_;
838 push @attr_order, $k; 857 push @attr_order, $k;
839 $section{$name}{$k} ||= $v; 858 $section{$name}{$k} = $v; # overwrite, so that the root decides
840 }
841 } 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.
842 } 876 }
843 877
844 $attr->{section} = [ 878 $attr->{section} = [
845 map !exists $section{$_} ? () : do { 879 map !exists $section{$_} ? () : do {
846 my $attr = delete $section{$_}; 880 my $attr = delete $section{$_};
850 map exists $attr->{$_} && !$ignore{$_} 884 map exists $attr->{$_} && !$ignore{$_}
851 ? [$_ => delete $attr->{$_}] : (), 885 ? [$_ => delete $attr->{$_}] : (),
852 @attr_order 886 @attr_order
853 ] 887 ]
854 }, 888 },
855
856 exists $section{$_} ? [$_ => delete $section{$_}] : (), 889 exists $section{$_} ? [$_ => delete $section{$_}] : (),
857 @section_order 890 @section_order
858 ]; 891 ];
859 892
860 $attr 893 $attr
861} 894}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines