ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/compile-gridmap
Revision: 1.2
Committed: Sat Jan 27 23:59:29 2007 UTC (17 years, 3 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
- implement per-space regions

File Contents

# Content
1 #!/opt/bin/perl
2
3 use strict;
4 no utf8;
5 use bytes;
6
7 use Storable;
8
9 my %type = (
10 deep_sea => "#006",
11 sea => "#008",
12 shallow_sea => "#00a",
13
14 beach => "#aa0",
15 dunes => "#bb0",
16 desert => "#cc0",
17 steppe => "#880",
18 steppelight => "#dd7",
19 small_stones => "#eeb",
20
21 marsh => "#0f8",
22 grass => "#0f0",
23 grassmedium => "#0e0",
24 grassbrown => "#851",
25 grassdark => "#274",
26 desert => "#cc0",
27
28 darkforest => "#040",
29 evergreens => "#0a0",
30 woods => "#080",
31
32 swamp => "#660",
33 deep_swamp => "#440",
34
35 jungle_1 => "#084",
36
37 flagstone => "#bbb",
38 istone => "#bbc",
39
40 hills_rocky => "#aa8",
41 treed_hills => "#6a4",
42 hills => "#aa4",
43 mountain => "#ccc",
44 mountain2 => "#cdd",
45 # mountain3 => "#ddc",
46 mountain4 => "#ddb",
47 mountain5 => "#ddd",
48 s_mountain => "#dff",
49
50 wasteland => "#ddf",
51 drifts => "#eef",
52 snow => "#eff",
53 cobblestones => "#ea2",
54 );
55
56 my $world = {
57 version => 1,
58
59 minx => 100,
60 miny => 100,
61 maxx => 129,
62 maxy => 129,
63 tilew => 50,
64 tileh => 50,
65 arch => ["blocked"],
66 };
67
68 open my $png, "convert world.png -depth 8 rgb:- |"
69 or die "convert :$!";
70 1500*1500*3 == read $png, my $data, 1500*1500*3 or die;
71
72 my $type = "\x00" x (1500*1500);
73
74 my %color;
75
76 for my $k (keys %type) {
77 my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1);
78 $color{$v} = @{$world->{arch}};
79 push @{$world->{arch}}, $k;
80 }
81
82 for my $Y (0 .. $world->{maxy} - $world->{miny}) {
83 print "$Y "; $| = 1;
84
85 for my $X (0 .. $world->{maxx} - $world->{minx}) {
86 my $X = $X * $world->{tilew};
87 my $Y = $Y * $world->{tileh};
88 for my $y (0 .. $world->{tileh} - 1) {
89 for my $x ( 0.. $world->{tilew} - 1) {
90 my $ofs = (($Y + $y)* 1500 + $X + $x);
91
92 my $pix = substr $data, $ofs * 3, 3;
93
94 if (my $k = $color{$pix}) {
95 substr $type, $ofs, 1, chr $k;
96 } else {
97 die sprintf "colour '%s' not defined at +%d+%d",
98 (unpack "H*", $pix), $X + $x, $Y + $y;
99 }
100 }
101 }
102 }
103 }
104
105 print "\n";
106
107 $world->{data} = $type;
108
109 Storable::nstore $world, "world.pst";
110