ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/gen_worldmap
Revision: 1.3
Committed: Sun Dec 17 18:23:28 2006 UTC (17 years, 5 months ago) by elmex
Branch: MAIN
Changes since 1.2: +37 -14 lines
Log Message:
added palette generation by script call 'gen_worldmap palette' to generate
a palette.

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3     use strict;
4 root 1.2 no utf8;
5 root 1.1
6     use Crossfire::Map;
7     use Storable;
8     use POSIX;
9     use File::Compare;
10    
11     use Gtk2 -init;
12    
13     my %type = (
14     deep_sea => "#006",
15     sea => "#008",
16     shallow_sea => "#00a",
17    
18     beach => "#aa0",
19     dunes => "#bb0",
20     desert => "#cc0",
21     steppe => "#880",
22     steppelight => "#dd7",
23     small_stones => "#eeb",
24    
25     marsh => "#0f8",
26     grass => "#0f0",
27     grassmedium => "#0e0",
28     grassbrown => "#851",
29     grassdark => "#274",
30     desert => "#cc0",
31    
32     darkforest => "#040",
33     evergreens => "#0a0",
34     woods => "#080",
35 elmex 1.3
36 root 1.1 swamp => "#660",
37     deep_swamp => "#440",
38 elmex 1.3
39 root 1.1 jungle_1 => "#084",
40    
41     flagstone => "#bbb",
42     istone => "#bbc",
43    
44     hills_rocky => "#aa8",
45     treed_hills => "#6a4",
46     hills => "#aa4",
47     mountain => "#ccc",
48     mountain2 => "#cdd",
49     mountain3 => "#ddc",
50     mountain4 => "#ddb",
51     mountain5 => "#ddd",
52     s_mountain => "#dff",
53    
54     wasteland => "#ddf",
55     drifts => "#eef",
56     snow => "#eff",
57     cobblestones => "#ea2",
58     );
59    
60 elmex 1.3 if ($ARGV[0] eq 'palette') {
61     mkdir "/tmp/$$.palette"
62     or die "Couldn't make /tmp/$$.palette";
63    
64     for (keys %type) {
65     my $color = $type{$_};
66     $color =~ s/^#//;
67     system ("convert -size 300x30 xc:\\#$color -pointsize 32 -fill \"red\" -gravity east -draw \"text 0,0 \\\"$_\\\"\" /tmp/$$.palette/$color.png");
68     }
69    
70     system ("convert -append "
71     . join (' ',
72     map {
73     my $c = $_; $c =~ s/^#//; "/tmp/$$.palette/$c.png"
74     } sort values %type
75     )
76     . " palette.png"
77     );
78    
79     system ("rm -r /tmp/$$.palette");
80     exit;
81     }
82    
83     Crossfire::load_archetypes;
84    
85     open my $png, "convert world.png -depth 8 rgb:- |"
86     or die "convert :$!";
87     1500*1500*3 == read $png, my $world, 1500*1500*3 or die;
88     open my $maskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png"
89     or die "convert2: $!";
90     my $mask = "\x00\x00\x00\x00" x (1500*1500);
91    
92     chdir ".." unless -d "maps/.";
93     -d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in .";
94    
95 root 1.1 my %color;
96     my @pids;
97    
98     for my $k (keys %type) {
99     my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1);
100     $color{$v} = $k;
101     }
102    
103 root 1.2 for my $Y (100..129) {
104     print "$Y\n";#d#
105     for my $X (100..129) {
106 root 1.1 my $mapname = sprintf "world_%03d_%03d", $X, $Y;
107     my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname"
108     or die "maps/world-overlay/$mapname: $!";
109    
110     {
111     my $X = ($X - 100) * 50;
112     my $Y = ($Y - 100) * 50;
113 root 1.2 for my $y (0..49) {
114     for my $x (0..49) {
115     my $ofs = (($Y + $y)* 1500 + $X + $x);
116    
117     substr $mask, $ofs * 4, 4,
118     $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00";
119    
120     unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) {
121    
122     my $type = substr $world, $ofs * 3, 3;
123    
124     if (my $k = $color{$type}) {
125     unshift @{ $map->{map}[$x][$y] }, {
126     _name => "$k",
127     };
128     } else {
129     die sprintf "colour '%s' not defined at %s+%s+%s",
130     (unpack "H*", $type), $mapname, $x, $y,
131     }
132 root 1.1 }
133     }
134     }
135     }
136    
137     if ((my $pid = fork)) {
138     push @pids, $pid;
139     waitpid shift @pids, 0 if @pids >= 3;
140     } else {
141     $map->write_file ("maps/world/$mapname~");
142     if (File::Compare::cmp "maps/world/$mapname", "maps/world/$mapname~") {
143     print "replacing maps/world/$mapname\n";
144     rename "maps/world/$mapname~", "maps/world/$mapname";
145     } else {
146     unlink "maps/world/$mapname~";
147     }
148     warn $@ if $@;
149     POSIX::_exit 0;
150     }
151     }
152     }
153    
154 root 1.2 print $maskfh $mask;
155    
156     waitpid shift @pids, 0 if @pids >= 1;
157 root 1.1