1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | # cfarch2png - convert crossfire maps to png+metadata |
3 | # cfarch2png - convert crossfire maps to png+metadata |
4 | # Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de> |
4 | # Copyright (C) 2005,2007 Marc Lehmann <cfmaps@schmorp.de> |
5 | # |
5 | # |
6 | # CFARCH2PNG is free software; you can redistribute it and/or modify |
6 | # CFARCH2PNG is free software; you can redistribute it and/or modify |
7 | # it under the terms of the GNU General Public License as published by |
7 | # it under the terms of the GNU General Public License as published by |
8 | # the Free Software Foundation; either version 2 of the License, or |
8 | # the Free Software Foundation; either version 2 of the License, or |
9 | # (at your option) any later version. |
9 | # (at your option) any later version. |
… | |
… | |
15 | # |
15 | # |
16 | # You should have received a copy of the GNU General Public License |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with gvpe; if not, write to the Free Software |
17 | # along with gvpe; if not, write to the Free Software |
18 | # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | |
19 | |
20 | # tower of stars: missing craters? |
20 | # Quoth The master himself: |
|
|
21 | # |
|
|
22 | # Object ordering is basically like this: |
|
|
23 | # top face: players or monsters. If none on the space, object with highest |
|
|
24 | # visibility value - if equal, then top object in terms of object stacking on the map. |
|
|
25 | # middle face: Object with highest visibility (of monster/player on a space). If |
|
|
26 | # no monster/player, then object with second highest visibility, or if all equal, |
|
|
27 | # second top object relative to map stacking. |
|
|
28 | # Bottom object: the highest object that is a floor type object. |
|
|
29 | # |
|
|
30 | # ... i believe that anytime, but it still doesn't mention the smoothlevel |
|
|
31 | # interaction :( |
21 | |
32 | |
22 | our $VERSION = '1.2'; |
33 | our $VERSION = '1.211'; |
23 | |
34 | |
24 | use strict; |
35 | use strict; |
25 | |
36 | |
26 | use Storable; |
37 | use Storable; |
27 | use List::Util qw(max); |
38 | use List::Util qw(max); |
… | |
… | |
42 | -M "$path.pst" < -M $path |
53 | -M "$path.pst" < -M $path |
43 | && Storable::retrieve "$path.pst" |
54 | && Storable::retrieve "$path.pst" |
44 | } or do { |
55 | } or do { |
45 | my %pak; |
56 | my %pak; |
46 | |
57 | |
47 | open my $fh, "<:raw", $path |
58 | open my $fh, "<:raw:perlio", $path |
48 | or die "$_[0]: $!"; |
59 | or die "$_[0]: $!"; |
49 | while (<$fh>) { |
60 | while (<$fh>) { |
50 | my ($type, $id, $len, $path) = split; |
61 | my ($type, $id, $len, $path) = split; |
51 | $path =~ s/.*\///; |
62 | $path =~ s/.*\///; |
52 | read $fh, $pak{$path}, $len; |
63 | read $fh, $pak{$path}, $len; |
… | |
… | |
65 | -M "$path.pst" < -M $path |
76 | -M "$path.pst" < -M $path |
66 | && Storable::retrieve "$path.pst" |
77 | && Storable::retrieve "$path.pst" |
67 | } or do { |
78 | } or do { |
68 | my %smooth; |
79 | my %smooth; |
69 | |
80 | |
70 | open my $fh, "<:raw", $path |
81 | open my $fh, "<:raw:perlio", $path |
71 | or die "$path: $!"; |
82 | or die "$path: $!"; |
72 | while (<$fh>) { |
83 | while (<$fh>) { |
73 | next if /^\s*($|#)/; |
84 | next if /^\s*($|#)/; |
74 | |
85 | |
75 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
86 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
… | |
… | |
91 | && Storable::retrieve "$path.pst" |
102 | && Storable::retrieve "$path.pst" |
92 | } or do { |
103 | } or do { |
93 | my %arc; |
104 | my %arc; |
94 | my ($more, $prev); |
105 | my ($more, $prev); |
95 | |
106 | |
96 | open my $fh, "<:raw", $path |
107 | open my $fh, "<:utf8", $path |
97 | or die "$path: $!"; |
108 | or die "$path: $!"; |
98 | |
109 | |
99 | my $parse_block; $parse_block = sub { |
110 | my $parse_block; $parse_block = sub { |
100 | my %arc = @_; |
111 | my %arc = @_; |
101 | |
112 | |
… | |
… | |
374 | ($map_pb, \%meta) |
385 | ($map_pb, \%meta) |
375 | } |
386 | } |
376 | |
387 | |
377 | for my $file (@ARGV) { |
388 | for my $file (@ARGV) { |
378 | my $mapa = read_arch $file; |
389 | my $mapa = read_arch $file; |
|
|
390 | $file =~ s/\.map$//; |
379 | my ($pb, $meta) = cfmap_render $mapa, $file; |
391 | my ($pb, $meta) = cfmap_render $mapa, $file; |
380 | $pb->save ("$file.png~~", "png"); |
392 | $pb->save ("$file.png~~", "png"); |
381 | system "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; |
393 | system "gm", "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; |
382 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
394 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
383 | system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~"; |
395 | system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~"; |
384 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
396 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
385 | unlink "$file.png~~"; |
397 | unlink "$file.png~~"; |
386 | Storable::nstore $meta, "$file.pst"; |
398 | Storable::nstore $meta, "$file.pst"; |
387 | utime +(stat $file)[8,9], "$file.pst"; |
399 | utime +(stat $file)[8,9], "$file.pst"; |
|
|
400 | utime +(stat $file)[8,9], "$file.jpg"; |
388 | utime +(stat $file)[8,9], "$file.png~"; |
401 | utime +(stat $file)[8,9], "$file.png~"; |
389 | rename "$file.png~", "$file.png"; |
402 | rename "$file.png~", "$file.png"; |
390 | } |
403 | } |
391 | |
404 | |
392 | |
405 | |