… | |
… | |
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.11'; |
33 | our $VERSION = '1.21'; |
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+)$/; |
76 | } |
87 | } |
77 | |
88 | |
78 | Storable::nstore \%smooth, "$path.pst"; |
89 | Storable::nstore \%smooth, "$path.pst"; |
|
|
90 | utime +(stat $path)[8,9], "$path.pst"; |
79 | |
91 | |
80 | \%smooth |
92 | \%smooth |
81 | } |
93 | } |
82 | } |
94 | } |
83 | |
95 | |
… | |
… | |
90 | && Storable::retrieve "$path.pst" |
102 | && Storable::retrieve "$path.pst" |
91 | } or do { |
103 | } or do { |
92 | my %arc; |
104 | my %arc; |
93 | my ($more, $prev); |
105 | my ($more, $prev); |
94 | |
106 | |
95 | open my $fh, "<:raw", $path |
107 | open my $fh, "<:utf8", $path |
96 | or die "$path: $!"; |
108 | or die "$path: $!"; |
97 | |
109 | |
98 | my $parse_block; $parse_block = sub { |
110 | my $parse_block; $parse_block = sub { |
99 | my %arc = @_; |
111 | my %arc = @_; |
100 | |
112 | |
… | |
… | |
151 | } |
163 | } |
152 | } |
164 | } |
153 | |
165 | |
154 | 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. |
155 | |
167 | |
|
|
168 | if ($cache) { |
156 | Storable::nstore \%arc, "$path.pst" |
169 | Storable::nstore \%arc, "$path.pst"; |
157 | if $cache; |
170 | utime +(stat $path)[8,9], "$path.pst"; |
|
|
171 | } |
158 | |
172 | |
159 | \%arc |
173 | \%arc |
160 | } |
174 | } |
161 | } |
175 | } |
162 | |
176 | |
… | |
… | |
222 | # first pass, gather face stacking order, border and corner info |
236 | # first pass, gather face stacking order, border and corner info |
223 | for my $x (0 .. $mapx - 1) { |
237 | for my $x (0 .. $mapx - 1) { |
224 | my $col = $map->[$x]; |
238 | my $col = $map->[$x]; |
225 | for my $y (0 .. $mapy - 1) { |
239 | for my $y (0 .. $mapy - 1) { |
226 | my $as = $col->[$y] || []; |
240 | my $as = $col->[$y] || []; |
227 | |
241 | |
|
|
242 | my $minsmooth = 0; |
|
|
243 | |
228 | for my $layer (0 .. $#$as) { |
244 | for my $layer (0 .. $#$as) { |
229 | my $a = $as->[$layer]; |
245 | my $a = $as->[$layer]; |
230 | |
246 | |
231 | my $o = $arch->{$a->{_name}} |
247 | my $o = $arch->{$a->{_name}} |
232 | 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; |
233 | |
249 | |
234 | 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 | |
235 | 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}; |
236 | my $level = $smoothlevel ? $smoothlevel |
258 | my $level = $smoothlevel + $layer * 256; |
237 | : $is_floor ? $layer - 1000 |
259 | |
238 | : $layer + 1000; |
260 | $level -= 100 * 256 if $o->{_name} eq "blocked"; |
239 | |
261 | |
240 | while ($o) { |
262 | while ($o) { |
241 | my $face = $a->{face} || $o->{face}; |
263 | my $face = $a->{face} || $o->{face}; |
242 | |
264 | |
243 | my $pb = tile $face |
265 | my $pb = tile $face |
… | |
… | |
277 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
299 | $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; |
278 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
300 | $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; |
279 | } |
301 | } |
280 | |
302 | |
281 | $o = $o->{more}; |
303 | $o = $o->{more}; |
|
|
304 | $level = ($layer + 1000) * 2; # put "big things" on top, no matter what |
282 | } |
305 | } |
283 | } |
306 | } |
284 | } |
307 | } |
285 | } |
308 | } |
286 | |
309 | |
… | |
… | |
299 | my ($x, $y) = split $;, $xy; |
322 | my ($x, $y) = split $;, $xy; |
300 | |
323 | |
301 | next if $x < 0 || $x >= $mapx |
324 | next if $x < 0 || $x >= $mapx |
302 | || $y < 0 || $y >= $mapy; |
325 | || $y < 0 || $y >= $mapy; |
303 | |
326 | |
304 | # bits is 00XX XXXX YYYY YYFX cccc CCCC BBBB |
327 | # bits is xxxx xxxx yyyy yyyy __fn cccc CCCC bbbb |
305 | # X don't draw |
|
|
306 | # F full tile draw with x|y bigface displacement |
328 | # f full tile draw with x|y bigface displacement |
307 | # c maybe draw these corners |
|
|
308 | # C do not draw these corners |
329 | # n do not draw borders&corners |
|
|
330 | # c draw these corners, but... |
|
|
331 | # C ... not these |
309 | # b draw these borders |
332 | # b draw these borders |
310 | |
333 | |
311 | if ($bits & 0x2000) { |
334 | if ($bits & 0x2000) { |
312 | my $dx = (($bits >> 24) & 0xff) - 128; |
335 | my $dx = (($bits >> 24) & 0xff) - 128; |
313 | my $dy = (($bits >> 16) & 0xff) - 128; |
336 | my $dy = (($bits >> 16) & 0xff) - 128; |
… | |
… | |
363 | } |
386 | } |
364 | |
387 | |
365 | for my $file (@ARGV) { |
388 | for my $file (@ARGV) { |
366 | my $mapa = read_arch $file; |
389 | my $mapa = read_arch $file; |
367 | my ($pb, $meta) = cfmap_render $mapa, $file; |
390 | my ($pb, $meta) = cfmap_render $mapa, $file; |
368 | $pb->save ("$file.png~", "png"); |
391 | $pb->save ("$file.png~~", "png"); |
369 | 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"; |
370 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
393 | #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency |
371 | 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~"; |
|
|
395 | # system "pngnq <\Q$file.png~\E >\Q$file.png\E"; |
372 | unlink "$file.png~"; |
396 | unlink "$file.png~~"; |
373 | 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"; |
374 | } |
402 | } |
375 | |
403 | |
376 | |
404 | |
377 | |
405 | |
378 | |
406 | |