ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/Info/update_apart.pl
Revision: 1.1.1.1 (vendor branch)
Committed: Sat Feb 4 23:55:29 2006 UTC (18 years, 3 months ago) by root
Content type: text/plain
Branch: UPSTREAM, MAIN
CVS Tags: post_fixaltar, last_stable, post_fixaltar2, rel-2_82, rel-2_81, rel-2_80, pre_coinconvert, UPSTREAM_2006_03_15, rel-3_0, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_2, rel-2_0, rel-2_1, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, UPSTREAM_2006_02_01, rel-2_53, pre_material_cfarch_normalize_run, rel-2_32, pre_fixconverter, post_coinconvert, pre_fixaltar2, pre_map_rename, UPSTREAM_2006_02_22, rel-2_90, rel-2_92, rel-2_93, rel-2_78, post_fixconverter, pre_fixaltar, rel-2_61, rel-2_43, rel-2_42, rel-2_41, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Initial Import

File Contents

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