ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/png2world
Revision: 1.1
Committed: Sat Sep 2 15:48:27 2006 UTC (17 years, 9 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

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 desert => "#cc0",
19 steppe => "#880",
20
21 marsh => "#0f8",
22 grass => "#0f0",
23 desert => "#cc0",
24
25 darkforest => "#040",
26 evergreen => "#0a0",
27 woods => "#080",
28
29 swamp => "#660",
30 deep_swamp => "#440",
31
32 jungle_1 => "#084",
33
34 hills_rocky => "#aa8",
35 hills => "#aa4",
36 mountain => "#ccc",
37 mountain5 => "#ddd",
38 );
39
40 for my $k (keys %type) {
41 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1), 255;
42 $color{$v} = $k;
43 }
44
45 my $maps = Storable::retrieve "worldmaps.pst";
46
47 for my $X (100..129) {
48 print "$X\n";#d#
49 for my $Y (100..129) {
50 my $map = delete $maps->[$X][$Y];
51 {
52 my $X = ($X - 100) * 50;
53 my $Y = ($Y - 100) * 50;
54 for my $x (0..49) {
55 for my $y (0..49) {
56 my $ofs = (($Y + $y)* 1500 + $X + $x) * 4;
57
58 my $mask = substr $mask, $ofs, 4;
59 my $type = substr $type, $ofs, 4;
60
61 next if $mask eq "\xff\x00\x00\xff";
62
63 if (my $k = $color{$type}) {
64 $map->{map}[$x][$y] = [{
65 _name => "$k",
66 }];
67 }
68 }
69 }
70 }
71 if ((my $pid = fork)) {
72 push @pids, $pid;
73 waitpid shift @pids, 0 if @pids > 3;
74 } else {
75 eval { $map->write_file ("maps/world/world_$X\_$Y") };
76 warn $@ if $@;
77 POSIX::_exit 0;
78 }
79 }
80 }
81