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.3 by elmex, Sun Dec 17 18:23:28 2006 UTC vs.
Revision 1.4 by elmex, Sun Dec 17 20:26:25 2006 UTC

55 drifts => "#eef", 55 drifts => "#eef",
56 snow => "#eff", 56 snow => "#eff",
57 cobblestones => "#ea2", 57 cobblestones => "#ea2",
58); 58);
59 59
60my ($part_x, $part_y);
61
60if ($ARGV[0] eq 'palette') { 62if ($ARGV[0] eq 'palette') {
61 mkdir "/tmp/$$.palette" 63 mkdir "/tmp/$$.palette"
62 or die "Couldn't make /tmp/$$.palette"; 64 or die "Couldn't make /tmp/$$.palette";
63 65
64 for (keys %type) { 66 for (keys %type) {
75 ) 77 )
76 . " palette.png" 78 . " palette.png"
77 ); 79 );
78 80
79 system ("rm -r /tmp/$$.palette"); 81 system ("rm -r /tmp/$$.palette");
80 exit; 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
81} 109}
82 110
83Crossfire::load_archetypes; 111Crossfire::load_archetypes;
84 112
85open my $png, "convert world.png -depth 8 rgb:- |" 113open my $png, "convert world.png -depth 8 rgb:- |"
86 or die "convert :$!"; 114 or die "convert :$!";
871500*1500*3 == read $png, my $world, 1500*1500*3 or die; 1151500*1500*3 == read $png, my $world, 1500*1500*3 or die;
116
117my $mask;
118my $maskfh;
119unless (defined $part_x) {
88open my $maskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png" 120 open \*maskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png"
89 or die "convert2: $!"; 121 or die "convert2: $!";
90my $mask = "\x00\x00\x00\x00" x (1500*1500); 122 $mask = "\x00\x00\x00\x00" x (1500*1500);
123}
91 124
92chdir ".." unless -d "maps/."; 125chdir ".." unless -d "maps/.";
93-d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in ."; 126-d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in .";
94 127
95my %color; 128my %color;
99 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1); 132 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1);
100 $color{$v} = $k; 133 $color{$v} = $k;
101} 134}
102 135
103for my $Y (100..129) { 136for my $Y (100..129) {
137 next if defined $part_y and $Y != $part_y;
138
104 print "$Y\n";#d# 139 print "$Y\n";#d#
140
105 for my $X (100..129) { 141 for my $X (100..129) {
142 next if defined $part_x and $X != $part_x;
143
106 my $mapname = sprintf "world_%03d_%03d", $X, $Y; 144 my $mapname = sprintf "world_%03d_%03d", $X, $Y;
107 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname" 145 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname"
108 or die "maps/world-overlay/$mapname: $!"; 146 or die "maps/world-overlay/$mapname: $!";
109 147
110 { 148 {
112 my $Y = ($Y - 100) * 50; 150 my $Y = ($Y - 100) * 50;
113 for my $y (0..49) { 151 for my $y (0..49) {
114 for my $x (0..49) { 152 for my $x (0..49) {
115 my $ofs = (($Y + $y)* 1500 + $X + $x); 153 my $ofs = (($Y + $y)* 1500 + $X + $x);
116 154
155 if (defined $mask) {
117 substr $mask, $ofs * 4, 4, 156 substr $mask, $ofs * 4, 4,
118 $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00"; 157 $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00";
158 }
119 159
120 unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) { 160 unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) {
121 161
122 my $type = substr $world, $ofs * 3, 3; 162 my $type = substr $world, $ofs * 3, 3;
123 163
149 POSIX::_exit 0; 189 POSIX::_exit 0;
150 } 190 }
151 } 191 }
152} 192}
153 193
154print $maskfh $mask; 194print $maskfh $mask if defined $mask;
155 195
156waitpid shift @pids, 0 if @pids >= 1; 196waitpid shift @pids, 0 if @pids >= 1;
157 197

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines