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