… | |
… | |
8 | use POSIX; |
8 | use POSIX; |
9 | use File::Compare; |
9 | use File::Compare; |
10 | |
10 | |
11 | use Gtk2 -init; |
11 | use Gtk2 -init; |
12 | |
12 | |
13 | my %type = ( |
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 | |
|
|
36 | swamp => "#660", |
|
|
37 | deep_swamp => "#440", |
|
|
38 | |
|
|
39 | 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 | |
14 | |
60 | my ($part_x, $part_y); |
15 | my ($part_x, $part_y); |
61 | |
16 | |
62 | if ($ARGV[0] eq 'palette') { |
|
|
63 | mkdir "/tmp/$$.palette" |
|
|
64 | or die "Couldn't make /tmp/$$.palette"; |
|
|
65 | |
|
|
66 | for (keys %type) { |
|
|
67 | my $color = $type{$_}; |
|
|
68 | $color =~ s/^#//; |
|
|
69 | system ("convert -size 300x30 xc:\\#$color -pointsize 32 -fill \"red\" -gravity east -draw \"text 0,0 \\\"$_\\\"\" /tmp/$$.palette/$color.png"); |
|
|
70 | } |
|
|
71 | |
|
|
72 | system ("convert -append " |
|
|
73 | . join (' ', |
|
|
74 | map { |
|
|
75 | my $c = $_; $c =~ s/^#//; "/tmp/$$.palette/$c.png" |
|
|
76 | } sort values %type |
|
|
77 | ) |
|
|
78 | . " palette.png" |
|
|
79 | ); |
|
|
80 | |
|
|
81 | system ("rm -r /tmp/$$.palette"); |
|
|
82 | exit |
|
|
83 | |
|
|
84 | } elsif ($ARGV[0] eq 'pixel2map') { |
17 | if ($ARGV[0] eq 'pixel2map') { |
85 | my ($x, $y) = ($ARGV[1], $ARGV[2]); |
18 | my ($x, $y) = ($ARGV[1], $ARGV[2]); |
86 | $x = int ($x / 50); |
19 | $x = int ($x / 50); |
87 | $y = int ($y / 50); |
20 | $y = int ($y / 50); |
88 | $x += 100; |
21 | $x += 100; |
89 | $y += 100; |
22 | $y += 100; |
… | |
… | |
93 | ($part_x, $part_y) = ($ARGV[1], $ARGV[2]); |
26 | ($part_x, $part_y) = ($ARGV[1], $ARGV[2]); |
94 | } elsif ($ARGV[0] =~ m/-*?he?l?p?/) { |
27 | } elsif ($ARGV[0] =~ m/-*?he?l?p?/) { |
95 | print <<USAGE; |
28 | print <<USAGE; |
96 | gen_worldmap [<mode>] |
29 | gen_worldmap [<mode>] |
97 | possible modes are: |
30 | possible modes are: |
98 | - palette generates the palette.png for drawing world.png |
|
|
99 | - pixel2map takes 2 further arguments representing coordinates in |
31 | - pixel2map takes 2 further arguments representing coordinates in |
100 | world.png and returns the world map file where the coordinate |
32 | world.png and returns the world map file where the coordinate |
101 | points to. |
33 | points to. |
102 | - partial takes 2 further arguments that should be X and Y coordinates |
34 | - partial takes 2 further arguments that should be X and Y coordinates |
103 | of the worldmap (starting at 100/100 and ending at 129/129). |
35 | of the worldmap (starting at 100/100 and ending at 129/129). |
… | |
… | |
109 | exit |
41 | exit |
110 | } |
42 | } |
111 | |
43 | |
112 | Crossfire::load_archetypes; |
44 | Crossfire::load_archetypes; |
113 | |
45 | |
|
|
46 | chdir ".." unless -d "maps/world-overlay/."; |
|
|
47 | -d "maps/world/." and -d "maps/world-overlay/." |
|
|
48 | or die "need maps/world and maps/world-overlay in ."; |
|
|
49 | |
|
|
50 | my $PLT_FILE = "maps/world/gridmap.arch.plt"; |
|
|
51 | my $WORLD_FILE = "maps/world/gridmap.arch.png"; |
|
|
52 | my $MASK_FILE = "maps/world/gridmap.arch.mask.png"; |
|
|
53 | |
|
|
54 | { |
|
|
55 | open my $plt, $PLT_FILE or die "Couldn't open $PLT_FILE: $!\n"; |
|
|
56 | |
|
|
57 | for (<$plt>) { |
|
|
58 | my ($arch, $color) = split /\s+/; |
|
|
59 | $type{$arch} = "#$color" if $arch =~ /\S/; |
|
|
60 | } |
|
|
61 | } |
|
|
62 | |
114 | open my $png, "convert world.png -depth 8 rgb:- |" |
63 | open my $png, "convert $WORLD_FILE -depth 8 rgb:- |" |
115 | or die "convert :$!"; |
64 | or die "convert :$!"; |
|
|
65 | |
116 | 1500*1500*3 == read $png, my $world, 1500*1500*3 or die; |
66 | 1500*1500*3 == read $png, my $world, 1500*1500*3 or die; |
117 | |
67 | |
118 | my $mask; |
68 | my $mask; |
119 | my $maskfh; |
69 | my $maskfh; |
120 | unless (defined $part_x) { |
70 | unless (defined $part_x) { |
121 | open my $mmaskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png" |
71 | open my $mmaskfh, "| convert -depth 8 -size 1500x1500 rgba:- $MASK_FILE" |
122 | or die "convert2: $!"; |
72 | or die "convert2: $!"; |
123 | $maskfh = $mmaskfh; |
73 | $maskfh = $mmaskfh; |
124 | $mask = "\x00\x00\x00\x00" x (1500*1500); |
74 | $mask = "\x00\x00\x00\x00" x (1500*1500); |
125 | } |
75 | } |
126 | |
|
|
127 | chdir ".." unless -d "maps/world-overlay/."; |
|
|
128 | -d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in ."; |
|
|
129 | |
76 | |
130 | my %color; |
77 | my %color; |
131 | my @pids; |
78 | my @pids; |
132 | |
79 | |
133 | for my $k (keys %type) { |
80 | for my $k (keys %type) { |
… | |
… | |
158 | substr $mask, $ofs * 4, 4, |
105 | substr $mask, $ofs * 4, 4, |
159 | $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00"; |
106 | $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00"; |
160 | } |
107 | } |
161 | |
108 | |
162 | unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) { |
109 | unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) { |
163 | |
110 | |
164 | my $type = substr $world, $ofs * 3, 3; |
111 | my $type = substr $world, $ofs * 3, 3; |
165 | |
112 | |
166 | if (my $k = $color{$type}) { |
113 | if (my $k = $color{$type}) { |
167 | unshift @{ $map->{map}[$x][$y] }, { |
114 | unshift @{ $map->{map}[$x][$y] }, { |
168 | _name => "$k", |
115 | _name => "$k", |