ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cfmaps/cfmap2png
(Generate patch)

Comparing cfmaps/cfmap2png (file contents):
Revision 1.6 by root, Fri Nov 18 12:50:24 2005 UTC vs.
Revision 1.12 by root, Tue Nov 22 06:46:43 2005 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# cfarch2png - convert crossfire maps to png+metadata
4# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de>
5#
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
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with gvpe; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
3# tower of stars: missing craters? 20# tower of stars: missing craters?
21# world_108_123 (8|18), hole below grass but shouldn't?
22
23our $VERSION = '1.11';
4 24
5use strict; 25use strict;
6 26
7use Storable; 27use Storable;
8use List::Util qw(max); 28use List::Util qw(max);
9 29
10use Gtk2; 30use Gtk2;
11
12our $VERSION = '1.0';
13 31
14#init Gtk2::Gdk; 32#init Gtk2::Gdk;
15 33
16my $LIB = $ENV{CROSSFIRE_LIBDIR} 34my $LIB = $ENV{CROSSFIRE_LIBDIR}
17 or die "\$CROSSFIRE_LIBDIR must be set\n"; 35 or die "\$CROSSFIRE_LIBDIR must be set\n";
173 191
174 my %meta; 192 my %meta;
175 193
176 my ($mapx, $mapy); 194 my ($mapx, $mapy);
177 195
178 my $map = $meta{map} = []; 196 my $map;
179 197
180 for (@{ $mapa->{arch} }) { 198 for (@{ $mapa->{arch} }) {
199 my ($x, $y) = ($_->{x}, $_->{y});
200
181 if ($_->{_name} eq "map") { 201 if ($_->{_name} eq "map") {
182 $meta{info} = $_; 202 $meta{info} = $_;
183 203
184 $mapx = $_->{width} || $_->{x}; 204 $mapx = $_->{width} || $x;
185 $mapy = $_->{height} || $_->{y}; 205 $mapy = $_->{height} || $y;
186 } else { 206 } else {
187 push @{ $map->[$_->{x}][$_->{y}] }, $_; 207 push @{ $map->[$x][$y] }, $_;
188 208
189 # arch map is unreliable w.r.t. width and height 209 # arch map is unreliable w.r.t. width and height
190 $mapx = $_->{x} + 1 if $mapx <= $_->{x}; 210 $mapx = $x + 1 if $mapx <= $x;
191 $mapy = $_->{y} + 1 if $mapy <= $_->{y}; 211 $mapy = $y + 1 if $mapy <= $y;
192 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x}; 212 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
193 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y}; 213 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
194 } 214 }
195 } 215 }
196 216
197 $meta{width} = $mapx; 217 $meta{width} = $mapx;
198 $meta{height} = $mapy; 218 $meta{height} = $mapy;
199 219
200 my %draw_info; 220 my %draw_info;
221 my %map_info;
201 222
202 # first pass, gather face stacking order, border and corner info 223 # first pass, gather face stacking order, border and corner info
203 for my $x (0 .. $mapx - 1) { 224 for my $x (0 .. $mapx - 1) {
204 my $col = $map->[$x]; 225 my $col = $map->[$x];
205 for my $y (0 .. $mapy - 1) { 226 for my $y (0 .. $mapy - 1) {
212 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 233 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
213 234
214 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; 235 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
215 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; 236 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
216 my $level = $smoothlevel ? $smoothlevel 237 my $level = $smoothlevel ? $smoothlevel
217 : $is_floor ? 0 238 : $is_floor ? $layer - 1000
218 : 256 + $layer; 239 : $layer + 1000;
219 240
220 while ($o) { 241 while ($o) {
221 my $face = $a->{face} || $o->{face}; 242 my $face = $a->{face} || $o->{face};
222 243
223 my $pb = tile $face 244 my $pb = tile $face
229 last if 0 > $mx || $mx >= $mapx 250 last if 0 > $mx || $mx >= $mapx
230 || 0 > $my || $my >= $mapy; 251 || 0 > $my || $my >= $mapy;
231 252
232 # this is very ugly (some tiles are 32x33 or worse) 253 # this is very ugly (some tiles are 32x33 or worse)
233 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; 254 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2;
255
256 my $dx = $bigface ? $o->{x} : 0;
257 my $dy = $bigface ? $o->{y} : 0;
258
259 push @{ $map_info{$level}{$mx, $my} }, $a;
260
261 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
234 262
235 if (my $sface = $smooth->{$face}) { 263 if (my $sface = $smooth->{$face}) {
236 $bigface and die "can't handle bigfaces with smoothing ($face)\n"; 264 $bigface and die "can't handle bigfaces with smoothing ($face)\n";
237 265
238 # full tile 266 # full tile
249 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200; 277 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200;
250 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 278 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
251 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 279 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
252 } 280 }
253 281
254 my $dx = $bigface ? $o->{x} : 0;
255 my $dy = $bigface ? $o->{y} : 0;
256
257 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
258
259 $o = $o->{more}; 282 $o = $o->{more};
260 } 283 }
261 } 284 }
262 } 285 }
263 } 286 }
264 287
265 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T 288 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T
266 or die; 289 or die;
267 $map_pb->fill (0x00000000); 290 $map_pb->fill (0xffffff00);
268 291
269 # second pass, render all the stuff 292 # second pass, render the map
270 for my $level (sort { $a <=> $b } keys %draw_info) { 293 for my $level (sort { $a <=> $b } keys %draw_info) {
271 my $v = $draw_info{$level}; 294 my $v = $draw_info{$level};
272 while (my ($sface, $info) = each %$v) { 295 while (my ($sface, $info) = each %$v) {
273 my $pb = tile $sface 296 my $pb = tile $sface
274 or die "no smooth face $sface\n"; 297 or die "no smooth face $sface\n";
319 255 342 255
320 ) if $corner; 343 ) if $corner;
321 } 344 }
322 } 345 }
323 } 346 }
347 }
348
349 # third pass, gather meta info
350 for my $level (sort { $a <=> $b } keys %map_info) {
351 my $info = $map_info{$level};
352
353 while (my ($xy, $as) = each %$info) {
354 my ($x, $y) = split $;, $xy;
355
356 next if $x < 0 || $x >= $mapx
357 || $y < 0 || $y >= $mapy;
358
359 push @{ $meta{map}[$x][$y] }, $_ for @$as;
360 }
324 } 361 }
325 362
326 ($map_pb, \%meta) 363 ($map_pb, \%meta)
327} 364}
328 365

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines