README.md edited online with Bitbucket
[swg-src.git] / dsrc / sku.0 / sys.server / compiled / game / abstract / armor_statistics / armorconvert.pl
blobcd2139b8cb0570fe3bb430f7b2327947927787e7
1 #!/usr/bin/perl
3 # Author: Brandon Reinhart
4 # Date: 04/10/03
6 # Converts armor_templates from version 0 to version 1.
8 use Cwd;
10 print "Converting armor statistics files to new format.\n";
12 # Test to make sure the file is a .tpf and convert it to the new format.
13 sub convertFile
15 # print " --> \[$_[0]\]\n";
17 # Cull files that are not .tpfs.
18 $_ = $_[0];
19 if ( !/\.tpf$/ )
21 return;
24 # Open the file and our target file.
25 open CURFILE, $_[0];
26 open NEWFILE, ">$_[0].new";
28 # Convert this file.
29 $vullist = "0";
30 $linetoprint = "";
31 $printline = 0;
32 while( <CURFILE> )
34 if ( /\n$/ )
36 chop;
38 if ( /\r$/ )
40 chop;
43 if ( $printline == 1 )
45 if ( $linetoprint =~ /type/ )
47 /effectiveness\s*=(\d*)/;
48 $effnum = $1;
49 if ( /type/ && $effnum > 1 )
51 chop($linetoprint);
52 $linetoprint .= ",";
54 else
56 chop($linetoprint);
57 $linetoprint .= "]";
60 print NEWFILE $linetoprint . "\n";
61 $linetoprint = "";
63 $printline = 1;
65 # Convert class entry.
66 s/class\s*armor_template\s*0/class armor_template 1/;
68 # Convert specialProtection.
69 if ( /type/ )
71 # Get endchar.
72 /(.).$/;
73 $endchar = $1;
75 # Get type.
76 /type\s*=\s*(.*),\s*elemental/;
77 $pretype = $1;
78 if ( $pretype =~ /elemental/ || $pretype =~ /environmental/ )
80 # Get elemental subtype.
81 /elementalType\s*=\s*EDT(.*),\s*effect/;
82 $pretype .= $1;
85 # Get effectiveness.
86 /effectiveness\s*=(\d*)/;
87 $effnum = $1;
88 if ( $effnum == 0 || $effnum == 1 )
90 $vullist .= " \| $pretype";
91 $printline = 0;
93 else
95 # Write the new line.
96 $_ = " [type = $pretype, effectiveness = $effnum]]";
100 # Convert encumberance.
101 if ( /encumberance/ )
103 # Get health.
104 if ( /AT_strength/ )
106 /AT_strength]\s*=\s*(\d*)/;
107 $_ = "encumbrance [0] = $1";
109 elsif ( /AT_quickness/ )
111 /AT_quickness]\s*=\s*(\d*)/;
112 $_ = "encumbrance [1] = $1";
114 elsif ( /AT_focus/ )
116 /AT_focus]\s*=\s*(\d*)/;
117 $_ = "encumbrance [2] = $1";
119 else
121 $printline = 0;
125 # Put contents of line into new file.
126 if ( $printline == 1 )
128 $linetoprint = $_;
132 # Add final line.
133 print NEWFILE $linetoprint;
135 # Add the vulnerability line.
136 print NEWFILE "vulnerability = $vullist\n";
138 # Close the file.
139 close CURFILE;
140 close NEWFILE;
142 # Rename the file.
143 rename $_[0], "$_[0].old";
144 rename "$_[0].new", $_[0];
146 # Go through again.
147 open CURFILE, $_[0];
148 open NEWFILE, ">$_[0].new";
149 $printline = 0;
150 while ( <CURFILE> )
152 if ( /\n$/ )
154 chop;
156 if ( $printline == 1 )
158 # On the second pass, remove any empty sp blocks.
159 if ( $linetoprint =~ /specialProtection/ )
161 if ( /type/ )
163 print NEWFILE $linetoprint . "\n";
165 else
167 print NEWFILE "specialProtection = []\n";
170 else
172 print NEWFILE $linetoprint . "\n";
176 $printline = 1;
177 $linetoprint = $_;
180 # Add final line.
181 print NEWFILE $linetoprint;
183 # Close the files.
184 close CURFILE;
185 close NEWFILE;
187 # Rename the file.
188 rename "$_[0].new", $_[0];
191 sub fileRename
193 rename "$_[0].old", $_[0];
196 # Open all files in a directory and convert them. Called recursively.
197 sub convertDir
199 print "OPENING \[$_[0]\]\n";
200 opendir THISDIR, $_[0] or die "I could not open $_[0]: $!\n";
201 my @allfiles = grep !/^\.\.?$/, readdir THISDIR;
202 closedir THISDIR;
203 chdir( $_[0] );
205 foreach $file (@allfiles)
207 if ( -d $file )
209 convertDir($file);
210 chdir( ".." ) or die "Can't change to .. $!\n";
212 else
214 convertFile($file);
215 #fileRename($file);
220 convertDir ".";