1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | # usage: res2pm >Crossfire/Data.pm |
3 | # usage: res2pm |
|
|
4 | |
|
|
5 | open STDOUT, ">:utf8", "Crossfire/Data.pm" |
|
|
6 | or die "Crossfire/Data.pm: $!"; |
4 | |
7 | |
5 | print <<EOF; |
8 | print <<EOF; |
6 | =head1 NAME |
9 | =head1 NAME |
7 | |
10 | |
8 | Crossfire::Data - various data structures useful for understanding archs and objects |
11 | Crossfire::Data - various data structures useful for understanding archs and objects |
… | |
… | |
65 | } |
68 | } |
66 | |
69 | |
67 | sub parse_attr { |
70 | sub parse_attr { |
68 | my ($e, $sect) = @_; |
71 | my ($e, $sect) = @_; |
69 | |
72 | |
70 | $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = { |
73 | my $arch = { |
71 | name => $e->attr ("editor"), |
74 | name => $e->attr ("editor"), |
72 | type => $e->attr ("type"), |
75 | type => $e->attr ("type"), |
73 | desc => string $e, |
76 | desc => string $e, |
74 | $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), |
77 | $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), |
75 | }; |
78 | }; |
|
|
79 | |
|
|
80 | if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { |
|
|
81 | $arch->{values} = $BITMASK{$2} ||= {}; |
|
|
82 | } |
|
|
83 | |
|
|
84 | $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; |
76 | } |
85 | } |
77 | |
86 | |
78 | sub parse_type { |
87 | sub parse_type { |
79 | my ($e, $type) = @_; |
88 | my ($e, $type) = @_; |
80 | |
89 | |
… | |
… | |
112 | $type |
121 | $type |
113 | } |
122 | } |
114 | |
123 | |
115 | for my $e (grep ref, @{$type->root->contents}) { |
124 | for my $e (grep ref, @{$type->root->contents}) { |
116 | if ($e->name eq "bitmask") { |
125 | if ($e->name eq "bitmask") { |
117 | my $bm = $bitmask{$e->attr ("name")} = {}; |
126 | my $bm = $bitmask{$e->attr ("name")} ||= {}; |
118 | for my $b (grep ref, @{$e->contents}) { |
127 | for my $b (grep ref, @{$e->contents}) { |
119 | $bm->{$b->attr ("bit")} = $b->attr ("name"); |
128 | $bm->{$b->attr ("bit")} = $b->attr ("name"); |
120 | } |
129 | } |
121 | } elsif ($e->name eq "list") { |
130 | } elsif ($e->name eq "list") { |
122 | my $list = $list{$e->attr ("name")} = {}; |
131 | my $list = $list{$e->attr ("name")} ||= {}; |
123 | for my $b (grep ref, @{$e->contents}) { |
132 | for my $b (grep ref, @{$e->contents}) { |
124 | $list->{$b->attr ("value")} = $b->attr ("name"); |
133 | $list->{$b->attr ("value")} = $b->attr ("name"); |
125 | } |
134 | } |
126 | } elsif ($e->name eq "ignore_list") { |
135 | } elsif ($e->name eq "ignore_list") { |
127 | my $list = $ignore_list{$e->attr ("name")} ||= []; |
136 | my $list = $ignore_list{$e->attr ("name")} ||= []; |
… | |
… | |
147 | $type{$_->attr ("number")}{name} = $_->attr ("name"); |
156 | $type{$_->attr ("number")}{name} = $_->attr ("name"); |
148 | } |
157 | } |
149 | |
158 | |
150 | dump_hash "TYPE", \%type; |
159 | dump_hash "TYPE", \%type; |
151 | |
160 | |
152 | dump_hash "LIST", \%list; |
|
|
153 | dump_hash "BITMASK", \%bitmask; |
|
|
154 | |
|
|
155 | my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") |
161 | my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") |
156 | or die; |
162 | or die; |
157 | |
163 | |
158 | my %spell; |
164 | my %spell; |
159 | |
165 | |