… | |
… | |
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 | # world_108_123 (8|18), hole below grass but shouldn't? |
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 :( |
22 | |
32 | |
23 | our $VERSION = '1.11'; |
33 | our $VERSION = '1.21'; |
24 | |
34 | |
25 | use strict; |
35 | use strict; |
26 | |
36 | |
27 | use Storable; |
37 | use Storable; |
28 | use List::Util qw(max); |
38 | use List::Util qw(max); |
… | |
… | |
43 | -M "$path.pst" < -M $path |
53 | -M "$path.pst" < -M $path |
44 | && Storable::retrieve "$path.pst" |
54 | && Storable::retrieve "$path.pst" |
45 | } or do { |
55 | } or do { |
46 | my %pak; |
56 | my %pak; |
47 | |
57 | |
48 | open my $fh, "<:raw", $path |
58 | open my $fh, "<:raw:perlio", $path |
49 | or die "$_[0]: $!"; |
59 | or die "$_[0]: $!"; |
50 | while (<$fh>) { |
60 | while (<$fh>) { |
51 | my ($type, $id, $len, $path) = split; |
61 | my ($type, $id, $len, $path) = split; |
52 | $path =~ s/.*\///; |
62 | $path =~ s/.*\///; |
53 | read $fh, $pak{$path}, $len; |
63 | read $fh, $pak{$path}, $len; |
… | |
… | |
66 | -M "$path.pst" < -M $path |
76 | -M "$path.pst" < -M $path |
67 | && Storable::retrieve "$path.pst" |
77 | && Storable::retrieve "$path.pst" |
68 | } or do { |
78 | } or do { |
69 | my %smooth; |
79 | my %smooth; |
70 | |
80 | |
71 | open my $fh, "<:raw", $path |
81 | open my $fh, "<:raw:perlio", $path |
72 | or die "$path: $!"; |
82 | or die "$path: $!"; |
73 | while (<$fh>) { |
83 | while (<$fh>) { |
74 | next if /^\s*($|#)/; |
84 | next if /^\s*($|#)/; |
75 | |
85 | |
76 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
86 | $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; |
77 | } |
87 | } |
78 | |
88 | |
79 | Storable::nstore \%smooth, "$path.pst"; |
89 | Storable::nstore \%smooth, "$path.pst"; |
|
|
90 | utime +(stat $path)[8,9], "$path.pst"; |
80 | |
91 | |
81 | \%smooth |
92 | \%smooth |
82 | } |
93 | } |
83 | } |
94 | } |
84 | |
95 | |
… | |
… | |
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 | |
… | |
… | |
152 | } |
163 | } |
153 | } |
164 | } |
154 | |
165 | |
155 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
166 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
156 | |
167 | |
|
|
168 | if ($cache) { |
157 | Storable::nstore \%arc, "$path.pst" |
169 | Storable::nstore \%arc, "$path.pst"; |
158 | if $cache; |
170 | utime +(stat $path)[8,9], "$path.pst"; |
|
|
171 | } |
159 | |
172 | |
160 | \%arc |
173 | \%arc |
161 | } |
174 | } |
162 | } |
175 | } |
163 | |
176 | |
… | |
… | |
223 | # first pass, gather face stacking order, border and corner info |
236 | # first pass, gather face stacking order, border and corner info |
224 | for my $x (0 .. $mapx - 1) { |
237 | for my $x (0 .. $mapx - 1) { |
225 | my $col = $map->[$x]; |
238 | my $col = $map->[$x]; |
226 | for my $y (0 .. $mapy - 1) { |
239 | for my $y (0 .. $mapy - 1) { |
227 | my $as = $col->[$y] || []; |
240 | my $as = $col->[$y] || []; |
228 | |
241 | |
|
|
242 | my $minsmooth = 0; |
|
|
243 | |
229 | for my $layer (0 .. $#$as) { |
244 | for my $layer (0 .. $#$as) { |
230 | my $a = $as->[$layer]; |
245 | my $a = $as->[$layer]; |
231 | |
246 | |
232 | my $o = $arch->{$a->{_name}} |
247 | my $o = $arch->{$a->{_name}} |
233 | or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; |
248 | or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; |
234 | |
249 | |
235 | my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; |
250 | my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; |
|
|
251 | |
|
|
252 | # hack to ensure somewhat correct ordering in case of conflicting |
|
|
253 | # smoothlevel/stacking order |
|
|
254 | $smoothlevel = $minsmooth + 0.01 if $minsmooth >= $smoothlevel; |
|
|
255 | $minsmooth = $smoothlevel; |
|
|
256 | |
236 | my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; |
257 | #my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; |
237 | my $level = $smoothlevel ? $smoothlevel |
258 | my $level = $smoothlevel + $layer * 256; |
238 | : $is_floor ? $layer - 1000 |
259 | |
239 | : $layer + 1000; |
260 | $level -= 100 * 256 if $o->{_name} eq "blocked"; |
240 | |
261 | |
241 | while ($o) { |
262 | while ($o) { |
242 | my $face = $a->{face} || $o->{face}; |
263 | my $face = $a->{face} || $o->{face}; |
243 | |
264 | |
244 | my $pb = tile $face |
265 | my $pb = tile $face |
… | |
… | |
278 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
299 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
279 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
300 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
280 | } |
301 | } |
281 | |
302 | |
282 | $o = $o->{more}; |
303 | $o = $o->{more}; |
|
|
304 | $level = ($layer + 1000) * 2; # put "big things" on top, no matter what |
283 | } |
305 | } |
284 | } |
306 | } |
285 | } |
307 | } |
286 | } |
308 | } |
287 | |
309 | |
… | |
… | |
364 | } |
386 | } |
365 | |
387 | |
366 | for my $file (@ARGV) { |
388 | for my $file (@ARGV) { |
367 | my $mapa = read_arch $file; |
389 | my $mapa = read_arch $file; |
368 | my ($pb, $meta) = cfmap_render $mapa, $file; |
390 | my ($pb, $meta) = cfmap_render $mapa, $file; |
369 | $pb->save ("$file.png~", "png"); |
391 | $pb->save ("$file.png~~", "png"); |
370 | system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; |
392 | system "gm", "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; |
371 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
393 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
372 | system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; |
394 | system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~"; |
373 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
395 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
374 | unlink "$file.png~"; |
396 | unlink "$file.png~~"; |
375 | Storable::nstore $meta, "$file.pst"; |
397 | Storable::nstore $meta, "$file.pst"; |
|
|
398 | utime +(stat $file)[8,9], "$file.pst"; |
|
|
399 | utime +(stat $file)[8,9], "$file.jpg"; |
|
|
400 | utime +(stat $file)[8,9], "$file.png~"; |
|
|
401 | rename "$file.png~", "$file.png"; |
376 | } |
402 | } |
377 | |
403 | |
378 | |
404 | |
379 | |
405 | |
380 | |
406 | |