--- deliantra/gde/GCE/Util.pm 2006/03/16 11:59:34 1.5 +++ deliantra/gde/GCE/Util.pm 2006/04/02 09:54:18 1.14 @@ -17,8 +17,60 @@ use Crossfire; use Crossfire::MapWidget; +use File::Spec::Functions; +use Cwd 'abs_path'; -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); +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 arch_is_exit map2abs exit_paths pseudohtml2txt); + +sub pseudohtml2txt { + my ($html) = @_; + + $html =~ s//\n/gsi; + $html =~ s/(.*?)<\/b>/_\1_/gsi; + $html +} + +sub exit_paths { + my ($mappath, $map1path, $map2path) = @_; + $mappath = abs_path $mappath; + $map1path = abs_path $map1path; + $map2path = abs_path $map2path; + + if ( (substr $map1path, 0, length $mappath) eq $mappath + and (substr $map2path, 0, length $mappath) eq $mappath) { + substr $map1path, 0, length $mappath, ''; + substr $map2path, 0, length $mappath, ''; + + my ($v1, $d1, $f1) = File::Spec->splitpath ($map1path); + my ($v2, $d2, $f2) = File::Spec->splitpath ($map2path); + + my @di1 = File::Spec->splitdir ($d1); + my @di2 = File::Spec->splitdir ($d2); + + if ((defined $di1[1]) and (defined $di2[1]) and $di1[1] eq $di2[1]) { + my $m1 = File::Spec->abs2rel ($map1path, File::Spec->catdir (@di2)); + my $m2 = File::Spec->abs2rel ($map2path, File::Spec->catdir (@di1)); + return ($m1, $m2); + } else { + return ($map1path, $map2path); + } + } else { + return ('', ''); + } +} + +sub map2abs { + my ($dest, $mape) = @_; + + my $dir; + if (File::Spec->file_name_is_absolute($dest)) { + $dir = catdir ($::CFG->{MAPDIR}, $dest); + } else { + my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); + $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); + } + return $dir; +} sub def($$) { return defined ($_[0]) ? $_[0] : $_[1]; @@ -54,13 +106,19 @@ } sub fill_pb_from_arch { - my ($pb, $arch) = @_; + my ($pb, $a) = @_; + + my $o = $Crossfire::ARCH{$a->{_name}}; + my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"} + or warn "no gfx found for arch '$a->{_name}' at ($x|$y)\n"; + + $face or return; $pb->fill (0x00000000); $TILE->composite ($pb, 0, 0, TILESIZE, TILESIZE, - - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64, + - ($face->{idx} % 64) * TILESIZE, - TILESIZE * int $face->{idx} / 64, 1, 1, 'nearest', 255 ); } @@ -82,14 +140,24 @@ } } +sub arch_is_exit { + my ($a) = @_; + my $type = $Crossfire::ARCH{$a->{_name}}->{type}; + return $type eq '66' || $type eq '41'; +} + sub arch_is_floor { my ($a) = @_; - return $Crossfire::ARCH{$a->{_name}}->{is_floor}; + my $ar = Crossfire::arch_attr $a; + return (substr $ar->{name}, 0, 5) eq 'Floor'; +#return $Crossfire::ARCH{$a->{_name}}->{is_floor}; } sub arch_is_wall { my ($a) = @_; - return $Crossfire::ARCH{$a->{_name}}->{no_pass}; + my $ar = Crossfire::arch_attr $a; + return $ar->{name} eq 'Wall'; +#return $Crossfire::ARCH{$a->{_name}}->{no_pass}; } sub arch_is_monster {