ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/adm/map_expand.pl
Revision: 1.1.1.1 (vendor branch)
Committed: Fri Feb 3 07:14:15 2006 UTC (18 years, 3 months ago) by root
Content type: text/plain
Branch: UPSTREAM, MAIN
CVS Tags: LAST_C_VERSION, rel-2_82, rel-2_81, rel-2_80, UPSTREAM_2006_03_15, rel-3_1, rel-3_0, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_2, rel-2_3, 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, rel-2_52, rel-2_53, rel-2_32, UPSTREAM_2006_02_22, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, UPSTREAM_2006_02_03, difficulty_fix_merge_060810_2300, rel-2_43, rel-2_42, rel-2_41, HEAD
Branch point for: difficulty_fix
Changes since 1.1: +0 -0 lines
Log Message:
initial import

File Contents

# Content
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 }