1 |
#!/usr/bin/perl |
2 |
# |
3 |
# This script goes through and updates the exits for maps. |
4 |
# First pass, so a lot of the options need to be set in this |
5 |
# script. It will search all directories in and below your current |
6 |
# working directory, so run from the directory you want to update. |
7 |
|
8 |
# Written by Mark Wedel (mwedel@sonic.net) |
9 |
# This borrows some amount of code from the map_info script written |
10 |
# by Tero Haatanen <Tero.Haatanen@lut.fi> |
11 |
|
12 |
# Name of the old map that we update exits on |
13 |
# Note that this can be a regexp. |
14 |
|
15 |
# OLD_MAP_STARTX/Y and OLD_MAP_ENDX/Y determine the range for the |
16 |
# updates. For example, scorn/city was broken up on two of the |
17 |
# map tiles, so this gets used to correspond that properly. |
18 |
# you can use very large END values just to make sure the entire |
19 |
# map is covered |
20 |
|
21 |
# The list of values here are locations to update to and |
22 |
# from. I set it up this way with explicity value settings |
23 |
# instead of initializing each as an array - I think this format |
24 |
# makes it easier to see how everything relates. |
25 |
# |
26 |
# OLD_MAP_NAME: This is the path it tries to match in the slaying field. |
27 |
# It can be a regexp. When updating within a specific directory of |
28 |
# a town, including the relative entries is possible. |
29 |
# OLD_MAP_STARTX/Y and OLD_MAP_ENDX/Y is the range of spaces |
30 |
# that we process. If the location is not in this range, it is unchanged. |
31 |
# Note that you can have multiple entries with the same OLD_MAP_NAME |
32 |
# value as long as they have different START and END coordinates. |
33 |
# NEW_MAP_NAME is the name that will be put into the slaying field. |
34 |
# NEW_MAP_OFFX/Y is the modification to the target location in |
35 |
# the exit. |
36 |
|
37 |
$OLD_MAP_NAME[0]=".*/santo_dominion/town"; |
38 |
# Many maps are just called 'town', so this is only useful if you know |
39 |
# 'town' is really referring to santo dominion. |
40 |
#$OLD_MAP_NAME[0]="(/santo_dominion/town|town|.+/town)"; |
41 |
$OLD_MAP_STARTX[0]=3; |
42 |
$OLD_MAP_STARTY[0]=12; |
43 |
$OLD_MAP_ENDX[0]=27; |
44 |
$OLD_MAP_ENDY[0]=100; |
45 |
$NEW_MAP_NAME[0]="/world/world_102_108"; |
46 |
$NEW_MAP_OFFX[0]=0; |
47 |
$NEW_MAP_OFFY[0]=-9; |
48 |
|
49 |
# Start of scorn updates |
50 |
$OLD_MAP_NAME[1]=".*/city/city"; |
51 |
$OLD_MAP_STARTX[1]=10; |
52 |
$OLD_MAP_STARTY[1]=0; |
53 |
$OLD_MAP_ENDX[1]=100; |
54 |
$OLD_MAP_ENDY[1]=100; |
55 |
$NEW_MAP_NAME[1]="/world/world_105_115"; |
56 |
$NEW_MAP_OFFX[1]=-10; |
57 |
$NEW_MAP_OFFY[1]=18; |
58 |
|
59 |
# Start of scorn updates |
60 |
$OLD_MAP_NAME[2]=".*/city/city"; |
61 |
$OLD_MAP_STARTX[2]=0; |
62 |
$OLD_MAP_STARTY[2]=0; |
63 |
$OLD_MAP_ENDX[2]=9; |
64 |
$OLD_MAP_ENDY[2]=100; |
65 |
$NEW_MAP_NAME[2]="/world/world_104_115"; |
66 |
$NEW_MAP_OFFX[2]=40; |
67 |
$NEW_MAP_OFFY[2]=18; |
68 |
|
69 |
# brest updates |
70 |
$OLD_MAP_NAME[3]='(.+/brest|brest)'; |
71 |
$OLD_MAP_STARTX[3]=0; |
72 |
$OLD_MAP_STARTY[3]=0; |
73 |
$OLD_MAP_ENDX[3]=100; |
74 |
$OLD_MAP_ENDY[3]=100; |
75 |
$NEW_MAP_NAME[3]="/world/world_107_123"; |
76 |
$NEW_MAP_OFFX[3]=17; |
77 |
$NEW_MAP_OFFY[3]=16; |
78 |
|
79 |
# Start of navar city - bunch of these as navar city is actually |
80 |
# spread across 4 world maps. Only navar city uses the 'city1' |
81 |
# name, so the regex is safe. |
82 |
$OLD_MAP_NAME[4]='(.+/city1|city1)'; |
83 |
$OLD_MAP_STARTX[4]=15; |
84 |
$OLD_MAP_STARTY[4]=13; |
85 |
$OLD_MAP_ENDX[4]=100; |
86 |
$OLD_MAP_ENDY[4]=100; |
87 |
$NEW_MAP_NAME[4]="/world/world_122_117"; |
88 |
$NEW_MAP_OFFX[4]=-15; |
89 |
$NEW_MAP_OFFY[4]=-13; |
90 |
|
91 |
$OLD_MAP_NAME[5]='(.+/city1|city1)'; |
92 |
$OLD_MAP_STARTX[5]=15; |
93 |
$OLD_MAP_STARTY[5]=0; |
94 |
$OLD_MAP_ENDX[5]=100; |
95 |
$OLD_MAP_ENDY[5]=12; |
96 |
$NEW_MAP_NAME[5]="/world/world_122_116"; |
97 |
$NEW_MAP_OFFX[5]=-15; |
98 |
$NEW_MAP_OFFY[5]=37; |
99 |
|
100 |
$OLD_MAP_NAME[6]='(.+/city1|city1)'; |
101 |
$OLD_MAP_STARTX[6]=0; |
102 |
$OLD_MAP_STARTY[6]=0; |
103 |
$OLD_MAP_ENDX[6]=14; |
104 |
$OLD_MAP_ENDY[6]=12; |
105 |
$NEW_MAP_NAME[6]="/world/world_121_116"; |
106 |
$NEW_MAP_OFFX[6]=35; |
107 |
$NEW_MAP_OFFY[6]=37; |
108 |
|
109 |
$OLD_MAP_NAME[7]='(.+/city1|city1)'; |
110 |
$OLD_MAP_STARTX[7]=0; |
111 |
$OLD_MAP_STARTY[7]=13; |
112 |
$OLD_MAP_ENDX[7]=14; |
113 |
$OLD_MAP_ENDY[7]=100; |
114 |
$NEW_MAP_NAME[7]="/world/world_121_117"; |
115 |
$NEW_MAP_OFFX[7]=35; |
116 |
$NEW_MAP_OFFY[7]=-13; |
117 |
|
118 |
$OLD_MAP_NAME[8]='(.+/kundi_area|kundi_area)'; |
119 |
$OLD_MAP_STARTX[8]=0; |
120 |
$OLD_MAP_STARTY[8]=0; |
121 |
$OLD_MAP_ENDX[8]=100; |
122 |
$OLD_MAP_ENDY[8]=100; |
123 |
$NEW_MAP_NAME[8]="/world/world_109_126"; |
124 |
$NEW_MAP_OFFX[8]=13; |
125 |
$NEW_MAP_OFFY[8]=17; |
126 |
|
127 |
$OLD_MAP_NAME[9]='(.+/stoneville|stoneville)'; |
128 |
$OLD_MAP_STARTX[9]=0; |
129 |
$OLD_MAP_STARTY[9]=0; |
130 |
$OLD_MAP_ENDX[9]=13; |
131 |
$OLD_MAP_ENDY[9]=100; |
132 |
$NEW_MAP_NAME[9]="/world/world_102_127"; |
133 |
$NEW_MAP_OFFX[9]=36; |
134 |
$NEW_MAP_OFFY[9]=1; |
135 |
|
136 |
$OLD_MAP_NAME[10]='(.+/stoneville|stoneville)'; |
137 |
$OLD_MAP_STARTX[10]=14; |
138 |
$OLD_MAP_STARTY[10]=0; |
139 |
$OLD_MAP_ENDX[10]=100; |
140 |
$OLD_MAP_ENDY[10]=100; |
141 |
$NEW_MAP_NAME[10]="/world/world_103_127"; |
142 |
$NEW_MAP_OFFX[10]=-14; |
143 |
$NEW_MAP_OFFY[10]=1; |
144 |
|
145 |
$OLD_MAP_NAME[11]='(.+/darcap|darcap)'; |
146 |
$OLD_MAP_STARTX[11]=0; |
147 |
$OLD_MAP_STARTY[11]=0; |
148 |
$OLD_MAP_ENDX[11]=100; |
149 |
$OLD_MAP_ENDY[11]=100; |
150 |
$NEW_MAP_NAME[11]="/world/world_116_102"; |
151 |
$NEW_MAP_OFFX[11]=18; |
152 |
$NEW_MAP_OFFY[11]=26; |
153 |
|
154 |
$OLD_MAP_NAME[12]='(.+/piratetown|piratetown)'; |
155 |
$OLD_MAP_STARTX[12]=0; |
156 |
$OLD_MAP_STARTY[12]=0; |
157 |
$OLD_MAP_ENDX[12]=100; |
158 |
$OLD_MAP_ENDY[12]=100; |
159 |
$NEW_MAP_NAME[12]="/world/world_128_109"; |
160 |
$NEW_MAP_OFFX[12]=12; |
161 |
$NEW_MAP_OFFY[12]=0; |
162 |
|
163 |
$OLD_MAP_NAME[13]='(.+/portjoseph|portjoseph)'; |
164 |
$OLD_MAP_STARTX[13]=0; |
165 |
$OLD_MAP_STARTY[13]=0; |
166 |
$OLD_MAP_ENDX[13]=100; |
167 |
$OLD_MAP_ENDY[13]=100; |
168 |
$NEW_MAP_NAME[13]="/world/world_101_114"; |
169 |
$NEW_MAP_OFFX[13]=7; |
170 |
$NEW_MAP_OFFY[13]=22; |
171 |
|
172 |
$OLD_MAP_NAME[14]='(.+/tortola|tortola)'; |
173 |
$OLD_MAP_STARTX[14]=0; |
174 |
$OLD_MAP_STARTY[14]=0; |
175 |
$OLD_MAP_ENDX[14]=100; |
176 |
$OLD_MAP_ENDY[14]=100; |
177 |
$NEW_MAP_NAME[14]="/world/world_100_116"; |
178 |
$NEW_MAP_OFFX[14]=16; |
179 |
$NEW_MAP_OFFY[14]=6; |
180 |
|
181 |
$VERBOSE=0; |
182 |
$error=0; |
183 |
for ($i=0; $i<=$#OLD_MAP_NAME; $i++) { |
184 |
if ((($OLD_MAP_STARTX[$i] + $NEW_MAP_OFFX[$i]) < 0) || |
185 |
(($OLD_MAP_STARTY[$i] + $NEW_MAP_OFFY[$i]) < 0 )) { |
186 |
print "oldmap $OLD_MAP_NAME[$i] ($OLD_MAP_STARTX[$i], $OLD_MAP_STARTX[$i] will result in negative destination coordinates.\n"; |
187 |
$error=1; |
188 |
} |
189 |
} |
190 |
# Basically, we want to check all the values and then exit. |
191 |
exit(1) if ($error); |
192 |
|
193 |
&maplist("."); |
194 |
|
195 |
while ($file = shift (@maps)) { |
196 |
&updatemap; |
197 |
} |
198 |
|
199 |
|
200 |
exit; |
201 |
|
202 |
# return table containing all objects in the map |
203 |
sub updatemap { |
204 |
local ($m, $made_change=0); |
205 |
$last = ""; |
206 |
$parent = ""; |
207 |
|
208 |
# Note that $/ is the input record seperator. By changing |
209 |
# this to \nend\n, it means that when we read from the file, |
210 |
# we basically read an entire arch at the same time. Note that |
211 |
# given this, $ in regexps matches this value below, and not |
212 |
# a newline. \n should generally be used instead of $ in |
213 |
# regexps if you really want the end of line. |
214 |
# Similary, ^ matches start of record, which means the arch line. |
215 |
|
216 |
$/ = "\nend\n"; |
217 |
if (! open (IN, $file)) { |
218 |
print "Can't open map file $file\n"; |
219 |
return; |
220 |
} |
221 |
$_ = <IN>; |
222 |
if (! /^arch map\n/) { |
223 |
print "Error: file $file isn't mapfile.\n"; |
224 |
return; |
225 |
} |
226 |
if (! open(OUT, ">$file.new")) { |
227 |
print "Can't open output file $file.new\n"; |
228 |
return; |
229 |
} |
230 |
print OUT $_; |
231 |
if ($VERBOSE) { |
232 |
print "Testing $file, "; |
233 |
print /^name (.+)$/ ? $1 : "No mapname"; |
234 |
print ", size [", /^x (\d+)$/ ? $1 : 16; |
235 |
print ",", /^y (\d+)/ ? $1 : 16, "]"; |
236 |
|
237 |
if (! /^msg$/) { |
238 |
print ", No message\n"; |
239 |
} elsif (/(\w+@\S+)/) { |
240 |
print ", $1\n"; |
241 |
} else { |
242 |
print ", Unknown\n"; |
243 |
} |
244 |
$printmap=0; |
245 |
} |
246 |
else { |
247 |
$name= /^name (.+)$/ ? $1 : "No mapname"; |
248 |
$x= /^x (\d+)$/ ? $1 : 16; |
249 |
$y= /^y (\d+)/ ? $1 : 16; |
250 |
$mapname="Map $file, $name, size [$x, $y]\n" ; |
251 |
$printmap=1; |
252 |
} |
253 |
|
254 |
while (<IN>) { |
255 |
if (($m = (@_ = /^arch \S+\s*$/g)) > 1) { |
256 |
$parent = /^arch (\S+)\s*$/; |
257 |
print OUT $_; |
258 |
|
259 |
# Object has an inventory. Just read through until we get |
260 |
# an end |
261 |
while (<IN>) { |
262 |
last if (/((.|\n)*end\n)(arch (.|\n)*\nend\n)/); |
263 |
print OUT $_; |
264 |
} |
265 |
$parent=""; |
266 |
# Objects with inventory should not contain exits, so |
267 |
# do not need to try and process them. Likewise, the objects |
268 |
# in the inventory should not contain exits. |
269 |
} else { |
270 |
for ($i=0; $i<=$#OLD_MAP_NAME; $i++) { |
271 |
if (m#\nslaying $OLD_MAP_NAME[$i]\n#) { |
272 |
$destx = /\nhp (\d+)\n/ ? $1 : 0; |
273 |
$desty = /\nsp (\d+)\n/ ? $1 : 0; |
274 |
if ($destx >= $OLD_MAP_STARTX[$i] && $destx <= $OLD_MAP_ENDX[$i] && |
275 |
$desty >= $OLD_MAP_STARTY[$i] && $desty <= $OLD_MAP_ENDY[$i]) { |
276 |
# Ok. This exit matches our criteria. Substitute in |
277 |
# the new values |
278 |
s/slaying $OLD_MAP_NAME[$i]\n/slaying $NEW_MAP_NAME[$i]\n/; |
279 |
$destx += $NEW_MAP_OFFX[$i]; |
280 |
$desty += $NEW_MAP_OFFY[$i]; |
281 |
s/\nhp \d+\n/\nhp $destx\n/; |
282 |
s/\nsp \d+\n/\nsp $desty\n/; |
283 |
$made_change=1; |
284 |
} |
285 |
} |
286 |
} |
287 |
print OUT $_; |
288 |
} # else not an object with inventory |
289 |
} # while <IN> LOOP |
290 |
close (IN); |
291 |
close(OUT); |
292 |
if ($made_change) { |
293 |
print "$file has changed\n"; |
294 |
unlink($file); |
295 |
rename("$file.new", $file); |
296 |
} |
297 |
else { |
298 |
unlink("$file.new"); |
299 |
} |
300 |
} |
301 |
|
302 |
# @maps contains all filenames |
303 |
sub maplist { |
304 |
local ($dir, $file, @dirs) = shift; |
305 |
|
306 |
opendir (DIR , $dir) || die "Can't open directory : $dir\n"; |
307 |
while ($file = readdir (DIR)) { |
308 |
next if ($file eq "." || $file eq ".." || $file eq "CVS"); |
309 |
|
310 |
$file = "$dir/$file"; |
311 |
next if (-l $file); # don't process symbolic links |
312 |
push (@dirs, $file) if (-d $file); |
313 |
push (@maps, $file) if (-f $file); |
314 |
} |
315 |
closedir (DIR); |
316 |
|
317 |
# recursive handle sub-dirs too |
318 |
while ($_ = shift @dirs) { |
319 |
&maplist ($_); |
320 |
} |
321 |
} |
322 |
|