ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/Info/map_sed.pl
Revision: 1.1
Committed: Sat Feb 4 23:55:19 2006 UTC (18 years, 3 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 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    
38     &maplist(".");
39    
40     while ($file = shift (@maps)) {
41     &updatemap;
42     }
43    
44    
45     exit;
46    
47     # return table containing all objects in the map
48     sub updatemap {
49     local ($m, $made_change=0);
50     $last = "";
51     $parent = "";
52    
53     # Note that $/ is the input record seperator. By changing
54     # this to \nend\n, it means that when we read from the file,
55     # we basically read an entire arch at the same time. Note that
56     # given this, $ in regexps matches this value below, and not
57     # a newline. \n should generally be used instead of $ in
58     # regexps if you really want the end of line.
59     # Similary, ^ matches start of record, which means the arch line.
60    
61     $/ = "\nend\n";
62     if (! open (IN, $file)) {
63     print "Can't open map file $file\n";
64     return;
65     }
66     $_ = <IN>;
67     if (! /^arch map\n/) {
68     print "Error: file $file isn't mapfile.\n";
69     return;
70     }
71     if (! open(OUT, ">$file.new")) {
72     print "Can't open output file $file.new\n";
73     return;
74     }
75     print OUT $_;
76     if ($VERBOSE) {
77     print "Testing $file, ";
78     print /^name (.+)$/ ? $1 : "No mapname";
79     print ", size [", /^x (\d+)$/ ? $1 : 16;
80     print ",", /^y (\d+)/ ? $1 : 16, "]";
81    
82     if (! /^msg$/) {
83     print ", No message\n";
84     } elsif (/(\w+@\S+)/) {
85     print ", $1\n";
86     } else {
87     print ", Unknown\n";
88     }
89     $printmap=0;
90     }
91     else {
92     $name= /^name (.+)$/ ? $1 : "No mapname";
93     $x= /^x (\d+)$/ ? $1 : 16;
94     $y= /^y (\d+)/ ? $1 : 16;
95     $mapname="Map $file, $name, size [$x, $y]\n" ;
96     $printmap=1;
97     }
98    
99     while (<IN>) {
100     $made_change=1 if (s/Lake_Country/lake_country/g);
101     print OUT $_;
102     } # while <IN> LOOP
103     close (IN);
104     close(OUT);
105     if ($made_change) {
106     print "$file has changed\n";
107     unlink($file);
108     rename("$file.new", $file);
109     }
110     else {
111     unlink("$file.new");
112     }
113     }
114    
115     # @maps contains all filenames
116     sub maplist {
117     local ($dir, $file, @dirs) = shift;
118    
119     opendir (DIR , $dir) || die "Can't open directory : $dir\n";
120     while ($file = readdir (DIR)) {
121     next if ($file eq "." || $file eq ".." || $file eq "CVS");
122    
123     $file = "$dir/$file";
124     push (@dirs, $file) if (-d $file);
125     push (@maps, $file) if (-f $file);
126     }
127     closedir (DIR);
128    
129     # recursive handle sub-dirs too
130     while ($_ = shift @dirs) {
131     &maplist ($_);
132     }
133     }
134