ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/gen_worldmap
Revision: 1.12
Committed: Thu May 1 14:16:50 2008 UTC (16 years ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +5 -5 lines
Log Message:
fix gen_worldmap, update gen_weorldmap, build road towards tower of stars

File Contents

# Content
1 #!/opt/bin/perl
2
3 use strict;
4 no utf8;
5
6 use Deliantra::Map;
7 use Storable;
8 use POSIX;
9 use File::Compare;
10
11 use Gtk2 -init;
12
13 my %type;
14
15 my ($part_x, $part_y);
16
17 if ($ARGV[0] eq 'pixel2map') {
18 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 } elsif ($ARGV[0] =~ m/-*?he?l?p?/) {
28 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 exit
42 }
43
44 Deliantra::load_archetypes;
45
46 chdir ".." unless -d "world-precomposed/.";
47 -d "maps/world/." and -d "world-precomposed/."
48 or die "need maps/world and world-precomposed 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
63 open my $png, "convert $WORLD_FILE -depth 8 rgb:- |"
64 or die "convert :$!";
65
66 1500*1500*3 == read $png, my $world, 1500*1500*3 or die;
67
68 my $mask;
69 my $maskfh;
70 unless (defined $part_x) {
71 open my $mmaskfh, "| convert -depth 8 -size 1500x1500 rgba:- $MASK_FILE"
72 or die "convert2: $!";
73 $maskfh = $mmaskfh;
74 $mask = "\x00\x00\x00\x00" x (1500*1500);
75 }
76
77 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 for my $Y (100..129) {
86 next if defined $part_y and $Y != $part_y;
87
88 print "$Y\n";#d#
89
90 for my $X (100..129) {
91 next if defined $part_x and $X != $part_x;
92
93 my $mapname = sprintf "world_%03d_%03d", $X, $Y;
94 my $map = new_from_file Deliantra::Map "maps/world/$mapname.map"
95 or die "maps/world/$mapname.map: $!";
96
97 {
98 my $X = ($X - 100) * 50;
99 my $Y = ($Y - 100) * 50;
100 for my $y (0..49) {
101 for my $x (0..49) {
102 my $ofs = (($Y + $y)* 1500 + $X + $x);
103
104 if (defined $mask) {
105 substr $mask, $ofs * 4, 4,
106 $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00";
107 }
108
109 unless (grep $Deliantra::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) {
110
111 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 }
122 }
123 }
124 }
125
126 if ((my $pid = fork)) {
127 push @pids, $pid;
128 waitpid shift @pids, 0 if @pids >= 3;
129 } else {
130 $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 } else {
135 unlink "world-precomposed/$mapname.map~";
136 }
137 warn $@ if $@;
138 POSIX::_exit 0;
139 }
140 }
141 }
142
143 print $maskfh $mask if defined $mask;
144
145 waitpid shift @pids, 0 if @pids >= 1;
146
147 system "chmod -R u=rwX,go=rX world-precomposed";
148 system "rsync -avz world-precomposed/. rain:/var/www/maps.deliantra.net/world-precomposed/.";