ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/png2world
Revision: 1.5
Committed: Mon Sep 4 20:31:24 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
evergreen => evergreens

File Contents

# Content
1 #!/opt/bin/perl
2
3 use Crossfire::Map;
4 use Storable;
5 use POSIX;
6
7 use Gtk2 -init;
8
9 { open my $fh, "<:raw", "mask.bin" or die; sysread $fh, $mask, 1500*1500*4 or die }
10 { open my $fh, "<:raw", "type.bin" or die; sysread $fh, $type, 1500*1500*4 or die }
11
12 my %type = (
13 deep_sea => "#006",
14 sea => "#008",
15 shallow_sea => "#00a",
16
17 beach => "#aa0",
18 dunes => "#bb0",
19 desert => "#cc0",
20 steppe => "#880",
21 steppelight => "#dd7",
22 steppelight => "#eeb",
23
24 marsh => "#0f8",
25 grass => "#0f0",
26 grassdark => "#274",
27 desert => "#cc0",
28
29 darkforest => "#040",
30 evergreens => "#0a0",
31 woods => "#080",
32
33 swamp => "#660",
34 deep_swamp => "#440",
35
36 jungle_1 => "#084",
37
38 hills_rocky => "#aa8",
39 treed_hills => "#6a4",
40 hills => "#aa4",
41 mountain => "#ccc",
42 mountain4 => "#cdd",
43 mountain5 => "#ddd",
44
45 cobblestones => "#ea2",
46 );
47
48 for my $k (keys %type) {
49 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1), 255;
50 $color{$v} = $k;
51 }
52
53 my $maps = Storable::retrieve "worldmaps.pst";
54
55 for my $X (100..129) {
56 print "$X\n";#d#
57 for my $Y (100..129) {
58 my $map = delete $maps->[$X][$Y];
59 {
60 my $X = ($X - 100) * 50;
61 my $Y = ($Y - 100) * 50;
62 for my $x (0..49) {
63 for my $y (0..49) {
64 my $ofs = (($Y + $y)* 1500 + $X + $x) * 4;
65
66 my $mask = substr $mask, $ofs, 4;
67 my $type = substr $type, $ofs, 4;
68
69 next if $mask eq "\xff\x00\x00\xff";
70
71 if (my $k = $color{$type}) {
72 $map->{map}[$x][$y] = [{
73 _name => "$k",
74 }];
75 }
76 }
77 }
78 }
79 if ((my $pid = fork)) {
80 push @pids, $pid;
81 waitpid shift @pids, 0 if @pids > 3;
82 } else {
83 eval { $map->write_file ("../maps/world/world_$X\_$Y") };
84 warn $@ if $@;
85 POSIX::_exit 0;
86 }
87 }
88 }
89