| 1 |
root |
1.1 |
#!/opt/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
root |
1.2 |
no utf8; |
| 5 |
root |
1.1 |
|
| 6 |
root |
1.12 |
use Deliantra::Map; |
| 7 |
root |
1.1 |
use Storable; |
| 8 |
|
|
use POSIX; |
| 9 |
|
|
use File::Compare; |
| 10 |
|
|
|
| 11 |
|
|
use Gtk2 -init; |
| 12 |
|
|
|
| 13 |
elmex |
1.8 |
my %type; |
| 14 |
root |
1.1 |
|
| 15 |
elmex |
1.4 |
my ($part_x, $part_y); |
| 16 |
|
|
|
| 17 |
elmex |
1.8 |
if ($ARGV[0] eq 'pixel2map') { |
| 18 |
elmex |
1.4 |
my ($x, $y) = ($ARGV[1], $ARGV[2]); |
| 19 |
|
|
$x = int ($x / 50); |
| 20 |
|
|
$y = int ($y / 50); |
| 21 |
|
|
$x += 100; |
| 22 |
|
|
$y += 100; |
| 23 |
|
|
print "gce $ENV{CROSSFIRE_LIBDIR}/maps/world/world_${x}_${y}\n"; |
| 24 |
|
|
exit |
| 25 |
|
|
} elsif ($ARGV[0] eq 'partial') { |
| 26 |
|
|
($part_x, $part_y) = ($ARGV[1], $ARGV[2]); |
| 27 |
elmex |
1.6 |
} elsif ($ARGV[0] =~ m/-*?he?l?p?/) { |
| 28 |
elmex |
1.4 |
print <<USAGE; |
| 29 |
|
|
gen_worldmap [<mode>] |
| 30 |
|
|
possible modes are: |
| 31 |
|
|
- pixel2map takes 2 further arguments representing coordinates in |
| 32 |
|
|
world.png and returns the world map file where the coordinate |
| 33 |
|
|
points to. |
| 34 |
|
|
- partial takes 2 further arguments that should be X and Y coordinates |
| 35 |
|
|
of the worldmap (starting at 100/100 and ending at 129/129). |
| 36 |
|
|
it will only generate that particular worldmap. |
| 37 |
|
|
(no overlay png is generated in this mode) |
| 38 |
|
|
without any mode the complete world is regenerated from the world.png and |
| 39 |
|
|
the overlay png is written. |
| 40 |
|
|
USAGE |
| 41 |
elmex |
1.6 |
exit |
| 42 |
elmex |
1.3 |
} |
| 43 |
|
|
|
| 44 |
root |
1.12 |
Deliantra::load_archetypes; |
| 45 |
elmex |
1.3 |
|
| 46 |
root |
1.11 |
chdir ".." unless -d "world-precomposed/."; |
| 47 |
|
|
-d "maps/world/." and -d "world-precomposed/." |
| 48 |
|
|
or die "need maps/world and world-precomposed in ."; |
| 49 |
elmex |
1.8 |
|
| 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 |
|
|
|
| 63 |
|
|
open my $png, "convert $WORLD_FILE -depth 8 rgb:- |" |
| 64 |
elmex |
1.3 |
or die "convert :$!"; |
| 65 |
elmex |
1.8 |
|
| 66 |
elmex |
1.3 |
1500*1500*3 == read $png, my $world, 1500*1500*3 or die; |
| 67 |
elmex |
1.4 |
|
| 68 |
|
|
my $mask; |
| 69 |
|
|
my $maskfh; |
| 70 |
|
|
unless (defined $part_x) { |
| 71 |
elmex |
1.8 |
open my $mmaskfh, "| convert -depth 8 -size 1500x1500 rgba:- $MASK_FILE" |
| 72 |
elmex |
1.4 |
or die "convert2: $!"; |
| 73 |
elmex |
1.5 |
$maskfh = $mmaskfh; |
| 74 |
elmex |
1.4 |
$mask = "\x00\x00\x00\x00" x (1500*1500); |
| 75 |
|
|
} |
| 76 |
elmex |
1.3 |
|
| 77 |
root |
1.1 |
my %color; |
| 78 |
|
|
my @pids; |
| 79 |
|
|
|
| 80 |
|
|
for my $k (keys %type) { |
| 81 |
|
|
my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1); |
| 82 |
|
|
$color{$v} = $k; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
root |
1.2 |
for my $Y (100..129) { |
| 86 |
elmex |
1.4 |
next if defined $part_y and $Y != $part_y; |
| 87 |
|
|
|
| 88 |
root |
1.2 |
print "$Y\n";#d# |
| 89 |
elmex |
1.4 |
|
| 90 |
root |
1.2 |
for my $X (100..129) { |
| 91 |
elmex |
1.4 |
next if defined $part_x and $X != $part_x; |
| 92 |
|
|
|
| 93 |
root |
1.1 |
my $mapname = sprintf "world_%03d_%03d", $X, $Y; |
| 94 |
root |
1.12 |
my $map = new_from_file Deliantra::Map "maps/world/$mapname.map" |
| 95 |
root |
1.10 |
or die "maps/world/$mapname.map: $!"; |
| 96 |
root |
1.1 |
|
| 97 |
|
|
{ |
| 98 |
|
|
my $X = ($X - 100) * 50; |
| 99 |
|
|
my $Y = ($Y - 100) * 50; |
| 100 |
root |
1.2 |
for my $y (0..49) { |
| 101 |
|
|
for my $x (0..49) { |
| 102 |
|
|
my $ofs = (($Y + $y)* 1500 + $X + $x); |
| 103 |
|
|
|
| 104 |
elmex |
1.4 |
if (defined $mask) { |
| 105 |
|
|
substr $mask, $ofs * 4, 4, |
| 106 |
|
|
$map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00"; |
| 107 |
|
|
} |
| 108 |
root |
1.2 |
|
| 109 |
root |
1.12 |
unless (grep $Deliantra::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) { |
| 110 |
elmex |
1.8 |
|
| 111 |
root |
1.2 |
my $type = substr $world, $ofs * 3, 3; |
| 112 |
|
|
|
| 113 |
|
|
if (my $k = $color{$type}) { |
| 114 |
|
|
unshift @{ $map->{map}[$x][$y] }, { |
| 115 |
|
|
_name => "$k", |
| 116 |
|
|
}; |
| 117 |
|
|
} else { |
| 118 |
|
|
die sprintf "colour '%s' not defined at %s+%s+%s", |
| 119 |
|
|
(unpack "H*", $type), $mapname, $x, $y, |
| 120 |
|
|
} |
| 121 |
root |
1.1 |
} |
| 122 |
|
|
} |
| 123 |
|
|
} |
| 124 |
|
|
} |
| 125 |
|
|
|
| 126 |
|
|
if ((my $pid = fork)) { |
| 127 |
|
|
push @pids, $pid; |
| 128 |
|
|
waitpid shift @pids, 0 if @pids >= 3; |
| 129 |
|
|
} else { |
| 130 |
root |
1.11 |
$map->write_file ("world-precomposed/$mapname.map~"); |
| 131 |
|
|
if (File::Compare::cmp "world-precomposed/$mapname.map", "world-precomposed/$mapname.map~") { |
| 132 |
|
|
print "replacing world-precomposed/$mapname.map\n"; |
| 133 |
|
|
rename "world-precomposed/$mapname.map~", "world-precomposed/$mapname.map"; |
| 134 |
root |
1.1 |
} else { |
| 135 |
root |
1.11 |
unlink "world-precomposed/$mapname.map~"; |
| 136 |
root |
1.1 |
} |
| 137 |
|
|
warn $@ if $@; |
| 138 |
|
|
POSIX::_exit 0; |
| 139 |
|
|
} |
| 140 |
|
|
} |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
elmex |
1.4 |
print $maskfh $mask if defined $mask; |
| 144 |
root |
1.2 |
|
| 145 |
|
|
waitpid shift @pids, 0 if @pids >= 1; |
| 146 |
root |
1.1 |
|
| 147 |
root |
1.11 |
system "chmod -R u=rwX,go=rX world-precomposed"; |
| 148 |
root |
1.12 |
system "rsync -avz world-precomposed/. rain:/var/www/maps.deliantra.net/world-precomposed/."; |