… | |
… | |
15 | use Storable; |
15 | use Storable; |
16 | use List::Util qw(min max); |
16 | use List::Util qw(min max); |
17 | |
17 | |
18 | use Crossfire; |
18 | use Crossfire; |
19 | use Crossfire::MapWidget; |
19 | use Crossfire::MapWidget; |
|
|
20 | use File::Spec::Functions; |
|
|
21 | use Cwd 'abs_path'; |
20 | |
22 | |
21 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall arch_is_monster add_table_widget quick_msg def); |
23 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb |
|
|
24 | fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall |
|
|
25 | stack_find arch_is_wall arch_is_monster add_table_widget quick_msg |
|
|
26 | def arch_is_exit map2abs exit_paths pseudohtml2txt arch_is_connector); |
|
|
27 | |
|
|
28 | sub pseudohtml2txt { |
|
|
29 | my ($html) = @_; |
|
|
30 | |
|
|
31 | $html =~ s/<br\s*?\/?>/\n/gsi; |
|
|
32 | $html =~ s/<b>(.*?)<\/b>/_\1_/gsi; |
|
|
33 | $html =~ s/<li>/\n* /gi; |
|
|
34 | $html =~ s/<\/?\s*li>//gi; |
|
|
35 | $html =~ s/<\/?\s*ul>//gi; |
|
|
36 | $html =~ s/>/>/g; |
|
|
37 | $html =~ s/</</g; |
|
|
38 | $html |
|
|
39 | } |
|
|
40 | |
|
|
41 | sub exit_paths { |
|
|
42 | my ($mappath, $map1path, $map2path) = @_; |
|
|
43 | $mappath = abs_path $mappath; |
|
|
44 | $map1path = abs_path $map1path; |
|
|
45 | $map2path = abs_path $map2path; |
|
|
46 | |
|
|
47 | if ( (substr $map1path, 0, length $mappath) eq $mappath |
|
|
48 | and (substr $map2path, 0, length $mappath) eq $mappath) { |
|
|
49 | substr $map1path, 0, length $mappath, ''; |
|
|
50 | substr $map2path, 0, length $mappath, ''; |
|
|
51 | |
|
|
52 | my ($v1, $d1, $f1) = File::Spec->splitpath ($map1path); |
|
|
53 | my ($v2, $d2, $f2) = File::Spec->splitpath ($map2path); |
|
|
54 | |
|
|
55 | my @di1 = File::Spec->splitdir ($d1); |
|
|
56 | my @di2 = File::Spec->splitdir ($d2); |
|
|
57 | |
|
|
58 | if ((defined $di1[1]) and (defined $di2[1]) and $di1[1] eq $di2[1]) { |
|
|
59 | my $m1 = File::Spec->abs2rel ($map1path, File::Spec->catdir (@di2)); |
|
|
60 | my $m2 = File::Spec->abs2rel ($map2path, File::Spec->catdir (@di1)); |
|
|
61 | return ($m1, $m2); |
|
|
62 | } else { |
|
|
63 | return ($map1path, $map2path); |
|
|
64 | } |
|
|
65 | } else { |
|
|
66 | return ('', ''); |
|
|
67 | } |
|
|
68 | } |
|
|
69 | |
|
|
70 | sub map2abs { |
|
|
71 | my ($dest, $mape) = @_; |
|
|
72 | |
|
|
73 | $mappath = abs_path $mappath; |
|
|
74 | my $dir; |
|
|
75 | if (File::Spec->file_name_is_absolute($dest)) { |
|
|
76 | $dir = catdir ($::CFG->{MAPDIR}, $dest); |
|
|
77 | } else { |
|
|
78 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
|
|
79 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
|
|
80 | } |
|
|
81 | return $dir; |
|
|
82 | } |
22 | |
83 | |
23 | sub def($$) { |
84 | sub def($$) { |
24 | return defined ($_[0]) ? $_[0] : $_[1]; |
85 | return defined ($_[0]) ? $_[0] : $_[1]; |
25 | } |
86 | } |
26 | |
87 | |
… | |
… | |
86 | |
147 | |
87 | return 'between'; |
148 | return 'between'; |
88 | } |
149 | } |
89 | } |
150 | } |
90 | |
151 | |
|
|
152 | sub arch_is_exit { |
|
|
153 | my ($a) = @_; |
|
|
154 | my $type = $Crossfire::ARCH{$a->{_name}}->{type}; |
|
|
155 | return $type eq '66' || $type eq '41'; |
|
|
156 | } |
|
|
157 | |
91 | sub arch_is_floor { |
158 | sub arch_is_floor { |
92 | my ($a) = @_; |
159 | my ($a) = @_; |
93 | return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
160 | my $ar = Crossfire::arch_attr $a; |
|
|
161 | return (substr $ar->{name}, 0, 5) eq 'Floor'; |
|
|
162 | } |
|
|
163 | |
|
|
164 | sub arch_is_connector { |
|
|
165 | my ($a) = @_; |
|
|
166 | my $ar = Crossfire::arch_attr $a; |
|
|
167 | my $has_connect_field = 0; |
|
|
168 | |
|
|
169 | TOP: for (@{$ar->{section}}) { |
|
|
170 | my $name = shift @$_; |
|
|
171 | my @r = @$_; |
|
|
172 | if ($name eq 'general') { |
|
|
173 | for (@r) { |
|
|
174 | my ($k, $s) = ($_->[0], $_->[1]); |
|
|
175 | if ($k eq 'connected' && $s->{name} eq 'connection') { |
|
|
176 | $has_connect_field = 1; |
|
|
177 | last TOP; |
|
|
178 | } |
|
|
179 | } |
|
|
180 | last TOP; |
|
|
181 | } |
|
|
182 | } |
|
|
183 | |
|
|
184 | return $has_connect_field; |
94 | } |
185 | } |
95 | |
186 | |
96 | sub arch_is_wall { |
187 | sub arch_is_wall { |
97 | my ($a) = @_; |
188 | my ($a) = @_; |
|
|
189 | my $ar = Crossfire::arch_attr $a; |
|
|
190 | return $ar->{name} eq 'Wall'; |
98 | return $Crossfire::ARCH{$a->{_name}}->{no_pass}; |
191 | #return $Crossfire::ARCH{$a->{_name}}->{no_pass}; |
99 | } |
192 | } |
100 | |
193 | |
101 | sub arch_is_monster { |
194 | sub arch_is_monster { |
102 | my ($a) = @_; |
195 | my ($a) = @_; |
103 | my $arch = $Crossfire::ARCH{$a->{_name}}; |
196 | my $arch = $Crossfire::ARCH{$a->{_name}}; |