1 |
root |
1.1 |
#! /usr/bin/perl |
2 |
|
|
|
3 |
|
|
# this script takes a map (in new format, eg those that support |
4 |
|
|
# tiling and only save the head for multipart objects) and |
5 |
|
|
# expands it by some factor. Note that editing of the destination |
6 |
|
|
# file will certainly be necessary, but this may be useful instead |
7 |
|
|
# of having to re-do a scaled map by hand. |
8 |
|
|
|
9 |
|
|
$default_X_size = 16; |
10 |
|
|
$default_Y_size = 16; |
11 |
|
|
|
12 |
|
|
$expand = 2; |
13 |
|
|
$help = 0; |
14 |
|
|
$input_map = $ARGV[$#ARGV]; |
15 |
|
|
|
16 |
|
|
# argv loop |
17 |
|
|
foreach $i (0 .. $#ARGV) { |
18 |
|
|
if($ARGV[$i] =~ "-h") { $help = 1; } |
19 |
|
|
if($ARGV[$i] =~ "-e") { $expand = $ARGV[++$i]; } |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
# various help/runtime messages |
23 |
|
|
if(!$expand||!$input_map) { |
24 |
|
|
print "USAGE: $0 -e factor <input map> > <output map> \n" ; |
25 |
|
|
exit 0; |
26 |
|
|
} |
27 |
|
|
if($help) { |
28 |
|
|
print "\n$0 options:\n" ; |
29 |
|
|
print "-e\t Factor by which to expand map x,y dimensions.\n"; |
30 |
|
|
print "-h\t This help message. \n"; |
31 |
|
|
exit 0; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
#Read in input map |
35 |
|
|
open(FILE, $input_map) || die "FATAL: file $input_map not found!\n"; |
36 |
|
|
# process the map object special. This is easier than trying |
37 |
|
|
# to handle the special values it has |
38 |
|
|
|
39 |
|
|
while (<FILE>) { |
40 |
|
|
|
41 |
|
|
if (/^width (\d+)$/) { |
42 |
|
|
printf "width %d\n", $1 * $expand; |
43 |
|
|
} elsif (/^height (\d+)$/) { |
44 |
|
|
printf "height %d\n", $1 * $expand; |
45 |
|
|
} elsif (/^enter_x (\d+)$/) { |
46 |
|
|
printf "enter_x %d\n", $1 * $expand; |
47 |
|
|
} elsif (/^enter_y (\d+)$/) { |
48 |
|
|
printf "enter_y %d\n", $1 * $expand; |
49 |
|
|
} |
50 |
|
|
else { print $_; } |
51 |
|
|
last if (/^end$/); |
52 |
|
|
} |
53 |
|
|
@mapdata=<FILE>; |
54 |
|
|
close(FILE); |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
# convert map data into objects |
58 |
|
|
while ($i<=$#mapdata) { |
59 |
|
|
local(@datum) = split (' ',$mapdata[$i]); |
60 |
|
|
if($datum[0] eq "arch") { $name[$objnum] = $datum[1]; } |
61 |
|
|
elsif($datum[0] eq "end") { $objnum++; } |
62 |
|
|
elsif($datum[0] eq "x") { $x[$objnum] = $datum[1]; } |
63 |
|
|
elsif($datum[0] eq "y") { $y[$objnum] = $datum[1]; } |
64 |
|
|
else { |
65 |
|
|
push(@otherline,$mapdata[$i]); $olines_in_obj[$objnum]++; |
66 |
|
|
} |
67 |
|
|
$i++; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
#Expand the map objects 1 to $objnum |
72 |
|
|
for ($j=0; $j<$objnum; $j++) { |
73 |
|
|
&expand_obj("$j $expand $bufline"); |
74 |
|
|
$bufline += $olines_in_obj[$j]; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
# SUBROUTINES |
78 |
|
|
|
79 |
|
|
sub expand_obj { |
80 |
|
|
local($data) = @_; |
81 |
|
|
local(@temp) = split(' ',$data); |
82 |
|
|
local($obj) = $temp[0]; |
83 |
|
|
local($factor) = $temp[1]; |
84 |
|
|
local($end_buf) = $temp[2] + $olines_in_obj[$obj]; |
85 |
|
|
local($start_x) = $x[$obj] * $factor; |
86 |
|
|
local($start_y) = $y[$obj] * $factor; |
87 |
|
|
local($end_x) = $start_x + $factor; |
88 |
|
|
local($end_y) = $start_y + $factor; |
89 |
|
|
|
90 |
|
|
while($start_x<$end_x) { |
91 |
|
|
while($start_y<$end_y) { |
92 |
|
|
local($start_buf) = $temp[2]; |
93 |
|
|
if($name[$obj]) { printf("arch %s\n",$name[$obj]); } |
94 |
|
|
else { return; } |
95 |
|
|
|
96 |
|
|
printf("x %d\n",$start_x); |
97 |
|
|
printf("y %d\n",$start_y); |
98 |
|
|
|
99 |
|
|
while ($start_buf<$end_buf) { |
100 |
|
|
print "$otherline[$start_buf]"; |
101 |
|
|
$start_buf++; |
102 |
|
|
} |
103 |
|
|
print"end\n"; |
104 |
|
|
$start_y++; |
105 |
|
|
} |
106 |
|
|
$start_x++; |
107 |
|
|
$start_y = $y[$obj] * $factor; |
108 |
|
|
} |
109 |
|
|
} |