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 | # 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 :( |
|
|
32 | |
20 | our $VERSION = '1.21'; |
33 | our $VERSION = '1.211'; |
21 | |
34 | |
22 | use strict; |
35 | use strict; |
23 | |
36 | |
24 | use Storable; |
37 | use Storable; |
25 | use List::Util qw(max); |
38 | use List::Util qw(max); |
… | |
… | |
40 | -M "$path.pst" < -M $path |
53 | -M "$path.pst" < -M $path |
41 | && Storable::retrieve "$path.pst" |
54 | && Storable::retrieve "$path.pst" |
42 | } or do { |
55 | } or do { |
43 | my %pak; |
56 | my %pak; |
44 | |
57 | |
45 | open my $fh, "<:raw", $path |
58 | open my $fh, "<:raw:perlio", $path |
46 | or die "$_[0]: $!"; |
59 | or die "$_[0]: $!"; |
47 | while (<$fh>) { |
60 | while (<$fh>) { |
48 | my ($type, $id, $len, $path) = split; |
61 | my ($type, $id, $len, $path) = split; |
49 | $path =~ s/.*\///; |
62 | $path =~ s/.*\///; |
50 | read $fh, $pak{$path}, $len; |
63 | read $fh, $pak{$path}, $len; |
… | |
… | |
63 | -M "$path.pst" < -M $path |
76 | -M "$path.pst" < -M $path |
64 | && Storable::retrieve "$path.pst" |
77 | && Storable::retrieve "$path.pst" |
65 | } or do { |
78 | } or do { |
66 | my %smooth; |
79 | my %smooth; |
67 | |
80 | |
68 | open my $fh, "<:raw", $path |
81 | open my $fh, "<:raw:perlio", $path |
69 | or die "$path: $!"; |
82 | or die "$path: $!"; |
70 | while (<$fh>) { |
83 | while (<$fh>) { |
71 | next if /^\s*($|#)/; |
84 | next if /^\s*($|#)/; |
72 | |
85 | |
73 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
86 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
… | |
… | |
89 | && Storable::retrieve "$path.pst" |
102 | && Storable::retrieve "$path.pst" |
90 | } or do { |
103 | } or do { |
91 | my %arc; |
104 | my %arc; |
92 | my ($more, $prev); |
105 | my ($more, $prev); |
93 | |
106 | |
94 | open my $fh, "<:raw", $path |
107 | open my $fh, "<:utf8", $path |
95 | or die "$path: $!"; |
108 | or die "$path: $!"; |
96 | |
109 | |
97 | my $parse_block; $parse_block = sub { |
110 | my $parse_block; $parse_block = sub { |
98 | my %arc = @_; |
111 | my %arc = @_; |
99 | |
112 | |
… | |
… | |
372 | ($map_pb, \%meta) |
385 | ($map_pb, \%meta) |
373 | } |
386 | } |
374 | |
387 | |
375 | for my $file (@ARGV) { |
388 | for my $file (@ARGV) { |
376 | my $mapa = read_arch $file; |
389 | my $mapa = read_arch $file; |
|
|
390 | $file =~ s/\.map$//; |
377 | my ($pb, $meta) = cfmap_render $mapa, $file; |
391 | my ($pb, $meta) = cfmap_render $mapa, $file; |
378 | $pb->save ("$file.png~~", "png"); |
392 | $pb->save ("$file.png~~", "png"); |
379 | 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"; |
380 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
394 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
381 | 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~"; |
382 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
396 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
383 | unlink "$file.png~~"; |
397 | unlink "$file.png~~"; |
384 | Storable::nstore $meta, "$file.pst"; |
398 | Storable::nstore $meta, "$file.pst"; |