ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/adm/mapslitter.pl
Revision: 1.1
Committed: Fri Feb 3 07:14:16 2006 UTC (18 years, 5 months ago) by root
Content type: text/plain
Branch point for: UPSTREAM, MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3     # This script will write (to stdout) all the needed exits to connect maps
4     # in a tiled fashion. The variables at the start will need to be set
5     # for things to work.
6    
7     # Set these as appropriate to the maps it should connect to. If one is left
8     # blank, then exits for that direction will not be created.
9    
10     $MAPNAME=$ARGV[0];
11     $XM=$ARGV[1];
12     $YM=$ARGV[2];
13     $WIDTH=$ARGV[3];
14     $HEIGHT=$ARGV[4];
15     #$SPLITMAP=$ARGV[5];
16    
17     if ($MAPNAME eq "") {
18     die "Usage: connect.pl <basename> <x maps> <y maps> <width> <height>";
19     }
20     if ($WIDTH==0) {
21     $WIDTH=42;
22     }
23     if ($HEIGHT==0) {
24     $HEIGHT=34;
25     }
26    
27     # DELTA What the overlap is - it should always be 5 for smooth transitions
28     $DELTA=5;
29     $xc=1;
30     $yc=1;
31    
32     print STDOUT "Creating connection maps.\n";
33    
34     while ($xc<=$XM) {
35     $yc=1;
36     while ($yc<=$YM) {
37     $NORTH="";
38     $NORTHWEST="";
39     $WEST="";
40     $SOUTHWEST="";
41     $SOUTH="";
42     $SOUTHEAST="";
43     $EAST="";
44     $NORTHEAST="";
45     if ($yc>1){
46     $NORTH=$MAPNAME."_".$xc."_".($yc-1);
47     }
48     if ($yc>1 || $xc>1) {
49     $NORTHWEST=$MAPNAME."_".($xc-1)."_".($yc-1);
50     }
51     if ($xc>1) {
52     $WEST=$MAPNAME."_".($xc-1)."_".$yc;
53     }
54     if ($xc>1 || $yc<$YM) {
55     $SOUTHWEST=$MAPNAME."_".($xc-1)."_".($yc+1);
56     }
57     if ($yc<$YM) {
58     $SOUTH=$MAPNAME."_".$xc."_".($yc+1);
59     }
60     if ($yc<$YM || $xc<$XM) {
61     $SOUTHEAST=$MAPNAME."_".($xc+1)."_".($yc+1);
62     }
63     if ($xc<$XM) {
64     $EAST=$MAPNAME."_".($xc+1)."_".$yc;
65     }
66     if ($xc<$XM || $yc>1) {
67     $NORTHEAST=$MAPNAME."_".($xc+1)."_".($yc-1);
68     }
69     $THISMAP=$MAPNAME."_".$xc."_".$yc;
70     open (MAP, ">$THISMAP") or die "unable to open mapfile.";
71     print MAP "arch map\n";
72     print MAP "name $MAPNAME\n";
73     print MAP "msg\n";
74     print MAP "Creator: splitmap.pl\n";
75     print MAP "Email: azzie\@tellutec.se\n";
76     print MAP "Date: Wed Oct 27 10:59:23 1993\n";
77     print MAP "endmsg\n";
78     print MAP "hp ".($DELTA+1)."\n";
79     print MAP "sp $DELTA\n";
80     print MAP "x $WIDTH\n";
81     print MAP "y $HEIGHT\n";
82     print MAP "end\n";
83     print $MAPNAME."_".$xc."_".$yc."\n";
84     # print "XC=".$xc."\n";
85     # print "YC=".$yc."\n";
86     #$NORTHWEST="";
87     #$WEST="";
88     #$SOUTHWEST="";
89     #$SOUTH="world_a3";
90     #$SOUTHEAST="world_b3";
91     #$EAST="world_b2";
92     #$NORTHEAST="world_b1";
93     # End of configurable options.
94     # Quick reminder - hp is the destination x, sp is the destination y
95    
96     # Lets do the corners first
97     if ($NORTHWEST ne "") {
98     print MAP "arch exit\n";
99     print MAP "slaying $NORTHWEST\n";
100     print MAP "x ".($DELTA-1)."\n";
101     print MAP "y ".($DELTA-1)."\n";
102     print MAP "hp ".($WIDTH-$DELTA-1)."\n";
103     print MAP "sp ".($HEIGHT-$DELTA-1)."\n";
104     print MAP "end\n";
105     }
106     if ($SOUTHWEST ne "") {
107     print MAP "arch exit\n";
108     print MAP "slaying $SOUTHWEST\n";
109     print MAP "x ".($DELTA-1)."\n";
110     print MAP "y ".($HEIGHT-$DELTA)."\n";
111     print MAP "hp ".($WIDTH-$DELTA-1)."\n";
112     print MAP "sp ".($DELTA)."\n";
113     print MAP "end\n";
114     }
115     if ($SOUTHEAST ne "") {
116     print MAP "arch exit\n";
117     print MAP "slaying $SOUTHEAST\n";
118     print MAP "x ".($WIDTH-$DELTA)."\n";
119     print MAP "y ".($HEIGHT-$DELTA)."\n";
120     print MAP "hp ".($DELTA)."\n";
121     print MAP "sp ".($DELTA)."\n";
122     print MAP "end\n";
123     }
124     if ($NORTHEAST ne "") {
125     print MAP "arch exit\n";
126     print MAP "slaying $NORTHEAST\n";
127     print MAP "x ".($WIDTH-$DELTA)."\n";
128     print MAP "y ".($DELTA-1)."\n";
129     print MAP "hp ".($DELTA)."\n";
130     print MAP "sp ".($HEIGHT-$DELTA-1)."\n";
131     print MAP "end\n";
132     }
133    
134     # Now lets do the edges.
135    
136     if ($NORTH ne "") {
137     $x=$DELTA;
138     while ($x < ($WIDTH-$DELTA)) {
139     print MAP "arch exit\n";
140     print MAP "slaying $NORTH\n";
141     print MAP "x ".$x."\n";
142     print MAP "y ".($DELTA-1)."\n";
143     print MAP "hp ".$x."\n";
144     print MAP "sp ".($HEIGHT-$DELTA-1)."\n";
145     print MAP "end\n";
146     $x=$x+1;
147     }
148     }
149    
150     if ($SOUTH ne "") {
151     $x=$DELTA;
152     while ($x < ($WIDTH-$DELTA)) {
153     print MAP "arch exit\n";
154     print MAP "slaying $SOUTH\n";
155     print MAP "x ".$x."\n";
156     print MAP "y ".($HEIGHT-$DELTA)."\n";
157     print MAP "hp ".$x."\n";
158     print MAP "sp ".($DELTA)."\n";
159     print MAP "end\n";
160     $x=$x+1;
161     }
162     }
163    
164    
165     if ($WEST ne "") {
166     $y=$DELTA;
167     while ($y < ($HEIGHT-$DELTA)) {
168     print MAP "arch exit\n";
169     print MAP "slaying $WEST\n";
170     print MAP "x ".($DELTA-1)."\n";
171     print MAP "y ".$y."\n";
172     print MAP "hp ".($WIDTH-$DELTA-1)."\n";
173     print MAP "sp ".$y."\n";
174     print MAP "end\n";
175     $y=$y+1;
176     }
177     }
178    
179    
180     if ($EAST ne "") {
181     $y=$DELTA;
182     while ($y < ($HEIGHT-$DELTA)) {
183     print MAP "arch exit\n";
184     print MAP "slaying $EAST\n";
185     print MAP "x ".($WIDTH-$DELTA)."\n";
186     print MAP "y ".$y."\n";
187     print MAP "hp ".($DELTA)."\n";
188     print MAP "sp ".$y."\n";
189     print MAP "end\n";
190     $y=$y+1;
191     }
192     }
193     close MAP;
194     $yc=$yc+1;
195     }
196     $xc=$xc+1;
197     }
198    
199     # Second pass. Connected maps opened and primary map superimposed.
200    
201     print STDOUT "Done with connecting, now superimposing split map.\n";
202     $xc=1;
203     $yc=1;
204     while ($xc<=$XM) {
205     $yc=1;
206     while ($yc<=$YM) {
207     $NEWMAP=$MAPNAME."_".$xc."_".$yc.".new";
208     $THISMAP=$MAPNAME."_".$xc."_".$yc;
209     open (MAP, ">>$THISMAP") or die "unable to open new mapfile.";
210     # open (CONMAP, "$THISMAP") or die "unable to open connected mapfile.";
211     open (IMPMAP, "$MAPNAME") or die "unable to open superimposed mapfile.";
212     $currentline=<IMPMAP>;
213     print STDOUT "Now superimposing on map ".$THISMAP."\n";
214     # Discard header
215     $headscan=1;
216     while ($headscan) {
217     if ($currentline=~/end\n/) {
218     $headscan=0;
219     }
220     $currentline=<IMPMAP>;
221     }
222     # Read rest of file
223     while ($currentline) {
224     # print STDOUT $currentline;
225     # Scan for and buffer archs within bounds.
226     while ($currentline ne "end\n" && $currentline) {
227    
228     if ($currentline=~/x /) {
229     ($florp, $px) = split //,$currentline,2;
230     $currentline="x ".($px-(($xc-1)*$WIDTH)+(($xc-1)*$DELTA*2))."\n";
231     }
232     if ($currentline=~/y /) {
233     ($florp, $py)=split //,$currentline,2;
234     $currentline="y ".($py-(($yc-1)*$HEIGHT)+(($yc-1)*$DELTA*2))."\n";
235     }
236     if ($currentline ne "x 0\n" && $currentline ne "y 0\n"){
237     $buf=$buf.$currentline;
238     }
239     $currentline=<IMPMAP>;
240     }
241     $buf=$buf.$currentline;
242     # print STDOUT $px.$py;
243     if ($px >= (($xc-1)*$WIDTH)-(($xc-1)*$DELTA*2) && $px < ($xc*$WIDTH)-(($xc-1)*$DELTA*2) && $py >= (($yc-1)*$HEIGHT)-(($yc-1)*$DELTA*2) && $py < ($yc*$HEIGHT)-(($yc-1)*$DELTA*2)) {
244     # print STDOUT "In map: ".$THISMAP."\n";
245     print MAP $buf;
246     # print STDOUT ".";
247    
248     }
249     # else {
250     # print STDOUT "-";
251     # }
252     $px=0;
253     $py=0;
254     $buf="";
255     $currentline=<IMPMAP>;
256     }
257     close MAP;
258     close CONMAP;
259     close IMPMAP;
260     $yc=$yc+1;
261     # print STDOUT "\n";
262     }
263     $xc=$xc+1;
264     }
265    
266    
267    
268    
269    
270    
271    
272    
273    
274    
275