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.3 by elmex, Sun Dec 17 18:23:28 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
60if ($ARGV[0] eq 'palette') {
61 mkdir "/tmp/$$.palette"
62 or die "Couldn't make /tmp/$$.palette";
63
64 for (keys %type) {
65 my $color = $type{$_};
66 $color =~ s/^#//;
67 system ("convert -size 300x30 xc:\\#$color -pointsize 32 -fill \"red\" -gravity east -draw \"text 0,0 \\\"$_\\\"\" /tmp/$$.palette/$color.png");
68 }
69
70 system ("convert -append "
71 . join (' ',
72 map {
73 my $c = $_; $c =~ s/^#//; "/tmp/$$.palette/$c.png"
74 } sort values %type
75 )
76 . " palette.png"
77 );
78
79 system ("rm -r /tmp/$$.palette");
80 exit;
81}
82
83Crossfire::load_archetypes;
84
85open my $png, "convert world.png -depth 8 rgb:- |"
86 or die "convert :$!";
871500*1500*3 == read $png, my $world, 1500*1500*3 or die;
88open my $maskfh, "| convert -depth 8 -size 1500x1500 rgba:- mask.png"
89 or die "convert2: $!";
90my $mask = "\x00\x00\x00\x00" x (1500*1500);
91
92chdir ".." unless -d "maps/.";
93-d "maps/world/." and -d "maps/world-overlay/." or die "need maps/world and maps/world-overlay in .";
94
68my %color; 95my %color;
69my @pids; 96my @pids;
70 97
71for my $k (keys %type) { 98for my $k (keys %type) {
72 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1); 99 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1);
73 $color{$v} = $k; 100 $color{$v} = $k;
74} 101}
75 102
76for my $X (100..129) { 103for my $Y (100..129) {
77 print "$X\n";#d# 104 print "$Y\n";#d#
78 for my $Y (100..129) { 105 for my $X (100..129) {
79 my $mapname = sprintf "world_%03d_%03d", $X, $Y; 106 my $mapname = sprintf "world_%03d_%03d", $X, $Y;
80 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname" 107 my $map = new_from_file Crossfire::Map "maps/world-overlay/$mapname"
81 or die "maps/world-overlay/$mapname: $!"; 108 or die "maps/world-overlay/$mapname: $!";
82 109
83 { 110 {
84 my $X = ($X - 100) * 50; 111 my $X = ($X - 100) * 50;
85 my $Y = ($Y - 100) * 50; 112 my $Y = ($Y - 100) * 50;
86 for my $x (0..49) { 113 for my $y (0..49) {
87 for my $y (0..49) { 114 for my $x (0..49) {
88 next if grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }; 115 my $ofs = (($Y + $y)* 1500 + $X + $x);
89 116
90 my $ofs = (($Y + $y)* 1500 + $X + $x) * 3; 117 substr $mask, $ofs * 4, 4,
91 118 $map->{map}[$x][$y] ? "\xff\x00\x00\xff" : "\xff\xff\xff\x00";
92 my $type = substr $world, $ofs, 3;
93 119
120 unless (grep $Crossfire::ARCH{$_->{_name}}{is_floor}, @{ $map->{map}[$x][$y] }) {
121
122 my $type = substr $world, $ofs * 3, 3;
123
94 if (my $k = $color{$type}) { 124 if (my $k = $color{$type}) {
95 unshift @{ $map->{map}[$x][$y] }, { 125 unshift @{ $map->{map}[$x][$y] }, {
96 _name => "$k", 126 _name => "$k",
97 }; 127 };
98 } else { 128 } else {
99 die sprintf "colour '%s' not defined at %s+%s+%s", 129 die sprintf "colour '%s' not defined at %s+%s+%s",
100 (unpack "H*", $type), $mapname, $x, $y, 130 (unpack "H*", $type), $mapname, $x, $y,
131 }
101 } 132 }
102# delete $map->{map}[$x][$y];
103 } 133 }
104 } 134 }
105 } 135 }
106 136
107 if ((my $pid = fork)) { 137 if ((my $pid = fork)) {
119 POSIX::_exit 0; 149 POSIX::_exit 0;
120 } 150 }
121 } 151 }
122} 152}
123 153
124POSIX::_exit 0; 154print $maskfh $mask;
125 155
156waitpid shift @pids, 0 if @pids >= 1;
157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines