--- cfmaps/cfmap2png 2005/11/22 06:46:43 1.12 +++ cfmaps/cfmap2png 2007/04/13 18:09:23 1.22 @@ -1,7 +1,7 @@ #!/opt/bin/perl # cfarch2png - convert crossfire maps to png+metadata -# Copyright (C) 2005 Marc Lehmann +# Copyright (C) 2005,2007 Marc Lehmann # # CFARCH2PNG is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,10 +17,20 @@ # along with gvpe; if not, write to the Free Software # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# tower of stars: missing craters? -# world_108_123 (8|18), hole below grass but shouldn't? +# Quoth The master himself: +# +# Object ordering is basically like this: +# top face: players or monsters. If none on the space, object with highest +# visibility value - if equal, then top object in terms of object stacking on the map. +# middle face: Object with highest visibility (of monster/player on a space). If +# no monster/player, then object with second highest visibility, or if all equal, +# second top object relative to map stacking. +# Bottom object: the highest object that is a floor type object. +# +# ... i believe that anytime, but it still doesn't mention the smoothlevel +# interaction :( -our $VERSION = '1.11'; +our $VERSION = '1.212'; use strict; @@ -45,7 +55,7 @@ } or do { my %pak; - open my $fh, "<:raw", $path + open my $fh, "<:raw:perlio", $path or die "$_[0]: $!"; while (<$fh>) { my ($type, $id, $len, $path) = split; @@ -68,7 +78,7 @@ } or do { my %smooth; - open my $fh, "<:raw", $path + open my $fh, "<:raw:perlio", $path or die "$path: $!"; while (<$fh>) { next if /^\s*($|#)/; @@ -77,6 +87,7 @@ } Storable::nstore \%smooth, "$path.pst"; + utime +(stat $path)[8,9], "$path.pst"; \%smooth } @@ -93,7 +104,7 @@ my %arc; my ($more, $prev); - open my $fh, "<:raw", $path + open my $fh, "<:utf8", $path or die "$path: $!"; my $parse_block; $parse_block = sub { @@ -154,8 +165,10 @@ undef $parse_block; # work around bug in perl not freeing $fh etc. - Storable::nstore \%arc, "$path.pst" - if $cache; + if ($cache) { + Storable::nstore \%arc, "$path.pst"; + utime +(stat $path)[8,9], "$path.pst"; + } \%arc } @@ -225,7 +238,9 @@ my $col = $map->[$x]; for my $y (0 .. $mapy - 1) { my $as = $col->[$y] || []; - + + my $minsmooth = 0; + for my $layer (0 .. $#$as) { my $a = $as->[$layer]; @@ -233,10 +248,16 @@ or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; - my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; - my $level = $smoothlevel ? $smoothlevel - : $is_floor ? $layer - 1000 - : $layer + 1000; + + # hack to ensure somewhat correct ordering in case of conflicting + # smoothlevel/stacking order + $smoothlevel = $minsmooth + 0.01 if $minsmooth >= $smoothlevel; + $minsmooth = $smoothlevel; + + #my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; + my $level = $smoothlevel + $layer * 256; + + $level -= 100 * 256 if $o->{_name} eq "blocked"; while ($o) { my $face = $a->{face} || $o->{face}; @@ -267,8 +288,8 @@ $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; # borders - $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0031; - $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0092; + $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0091; + $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0032; $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064; $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8; @@ -280,6 +301,7 @@ } $o = $o->{more}; + $level = ($layer + 1000) * 2; # put "big things" on top, no matter what } } } @@ -302,11 +324,11 @@ next if $x < 0 || $x >= $mapx || $y < 0 || $y >= $mapy; - # bits is 00XX XXXX YYYY YYFX cccc CCCC BBBB - # X don't draw - # F full tile draw with x|y bigface displacement - # c maybe draw these corners - # C do not draw these corners + # bits is xxxx xxxx yyyy yyyy __fn cccc CCCC bbbb + # f full tile draw with x|y bigface displacement + # n do not draw borders&corners + # c draw these corners, but... + # C ... not these # b draw these borders if ($bits & 0x2000) { @@ -365,13 +387,19 @@ for my $file (@ARGV) { my $mapa = read_arch $file; + $file =~ s/\.map$//; my ($pb, $meta) = cfmap_render $mapa, $file; - $pb->save ("$file.png~", "png"); - system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; + $pb->save ("$file.png~~", "png"); + system "gm", "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency - system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; - unlink "$file.png~"; + system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~"; +# system "pngnq <\Q$file.png~\E >\Q$file.png\E"; + unlink "$file.png~~"; Storable::nstore $meta, "$file.pst"; + utime +(stat $file)[8,9], "$file.pst"; + utime +(stat $file)[8,9], "$file.jpg"; + utime +(stat $file)[8,9], "$file.png~"; + rename "$file.png~", "$file.png"; }