ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/gen_worldmap
(Generate patch)

Comparing deliantra/util/gen_worldmap (file contents):
Revision 1.1 by root, Sun Dec 17 17:42:56 2006 UTC vs.
Revision 1.5 by elmex, Sun Dec 17 22:46:27 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use strict; 3use strict;
4no utf8;
4 5
5use Crossfire::Map; 6use Crossfire::Map;
6use Storable; 7use Storable;
7use POSIX; 8use POSIX;
8use File::Compare; 9use File::Compare;
9 10
10use Gtk2 -init; 11use Gtk2 -init;
11
12Crossfire::load_archetypes;
13
14open my $png, "convert world.png -depth 8 rgb:- |"
15 or die "convert :$!";
161500*1500*3 == read $png, my $world, 1500*1500*3 or die;
17
18chdir ".." unless -d "maps/.";
19-d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in .";
20 12
21my %type = ( 13my %type = (
22 deep_sea => "#006", 14 deep_sea => "#006",
23 sea => "#008", 15 sea => "#008",
24 shallow_sea => "#00a", 16 shallow_sea => "#00a",
38 desert => "#cc0", 30 desert => "#cc0",
39 31
40 darkforest => "#040", 32 darkforest => "#040",
41 evergreens => "#0a0", 33 evergreens => "#0a0",
42 woods => "#080", 34 woods => "#080",
43 35
44 swamp => "#660", 36 swamp => "#660",
45 deep_swamp => "#440", 37 deep_swamp => "#440",
46 38
47 jungle_1 => "#084", 39 jungle_1 => "#084",
48 40
49 flagstone => "#bbb", 41 flagstone => "#bbb",
50 istone => "#bbc", 42 istone => "#bbc",
51 43
63 drifts => "#eef", 55 drifts => "#eef",
64 snow => "#eff", 56 snow => "#eff",
65 cobblestones => "#ea2", 57 cobblestones => "#ea2",
66); 58);
67 59
60my ($part_x, $part_y);
61
62if ($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') {
85 my ($x, $y) = ($ARGV[1], $ARGV[2]);
86 $x = int ($x / 50);
87 $y = int ($y / 50);
88 $x += 100;
89 $y += 100;
90 print "gce $ENV{CROSSFIRE_LIBDIR}/maps/world/world_${x}_${y}\n";
91 exit
92} elsif ($ARGV[0] eq 'partial') {
93 ($part_x, $part_y) = ($ARGV[1], $ARGV[2]);
94} elsif ($ARGV[0] =~ m/-*?:he?l?p?/) {
95 print <<USAGE;
96gen_worldmap [<mode>]
97 possible modes are:
98 - palette generates the palette.png for drawing world.png
99 - pixel2map takes 2 further arguments representing coordinates in
100 world.png and returns the world map file where the coordinate
101 points to.
102 - 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).
104 it will only generate that particular worldmap.
105 (no overlay png is generated in this mode)
106without any mode the complete world is regenerated from the world.png and
107the overlay png is written.
108USAGE
109}
110
111Crossfire::load_archetypes;
112
113open my $png, "convert world.png -depth 8 rgb:- |"
114 or die "convert :$!";
1151500*1500*3 == read $png, my $world, 1500*1500*3 or die;
116
117my $mask;
118my $maskfh;
119unless (defined $part_x) {
120 open my $mmaskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png"
121 or die "convert2: $!";
122 $maskfh = $mmaskfh;
123 $mask = "\x00\x00\x00\x00" x (1500*1500);
124}
125
126chdir ".." unless -d "maps/.";
127-d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in .";
128
68my %color; 129my %color;
69my @pids; 130my @pids;
70 131
71for my $k (keys %type) { 132for my $k (keys %type) {
72 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1); 133 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1);
73 $color{$v} = $k; 134 $color{$v} = $k;
74} 135}
75 136
76for my $X (100..129) { 137for my $Y (100..129) {
138 next if defined $part_y and $Y != $part_y;
139
77 print "$X\n";#d# 140 print "$Y\n";#d#
141
78 for my $Y (100..129) { 142 for my $X (100..129) {
143 next if defined $part_x and $X != $part_x;
144
79 my $mapname = sprintf "world_%03d_%03d", $X, $Y; 145 my $mapname = sprintf "world_%03d_%03d", $X, $Y;
80 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname" 146 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname"
81 or die "maps/world-overlay/$mapname: $!"; 147 or die "maps/world-overlay/$mapname: $!";
82 148
83 { 149 {
84 my $X = ($X - 100) * 50; 150 my $X = ($X - 100) * 50;
85 my $Y = ($Y - 100) * 50; 151 my $Y = ($Y - 100) * 50;
86 for my $x (0..49) { 152 for my $y (0..49) {
87 for my $y (0..49) { 153 for my $x (0..49) {
88 next if grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }; 154 my $ofs = (($Y + $y)* 1500 + $X + $x);
89 155
90 my $ofs = (($Y + $y)* 1500 + $X + $x) * 3; 156 if (defined $mask) {
157 substr $mask, $ofs * 4, 4,
158 $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00";
91 159 }
92 my $type = substr $world, $ofs, 3;
93 160
161 unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) {
162
163 my $type = substr $world, $ofs * 3, 3;
164
94 if (my $k = $color{$type}) { 165 if (my $k = $color{$type}) {
95 unshift @{ $map->{map}[$x][$y] }, { 166 unshift @{ $map->{map}[$x][$y] }, {
96 _name => "$k", 167 _name => "$k",
97 }; 168 };
98 } else { 169 } else {
99 die sprintf "colour '%s' not defined at %s+%s+%s", 170 die sprintf "colour '%s' not defined at %s+%s+%s",
100 (unpack "H*", $type), $mapname, $x, $y, 171 (unpack "H*", $type), $mapname, $x, $y,
172 }
101 } 173 }
102# delete $map->{map}[$x][$y];
103 } 174 }
104 } 175 }
105 } 176 }
106 177
107 if ((my $pid = fork)) { 178 if ((my $pid = fork)) {
119 POSIX::_exit 0; 190 POSIX::_exit 0;
120 } 191 }
121 } 192 }
122} 193}
123 194
124POSIX::_exit 0; 195print $maskfh $mask if defined $mask;
125 196
197waitpid shift @pids, 0 if @pids >= 1;
198

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines