3 # Author: Brandon Reinhart
6 # Converts armor_templates from version 0 to version 1.
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.
15 # print " --> \[$_[0]\]\n";
17 # Cull files that are not .tpfs.
24 # Open the file and our target file.
26 open NEWFILE
, ">$_[0].new";
43 if ( $printline == 1 )
45 if ( $linetoprint =~ /type/ )
47 /effectiveness\s*=(\d*)/;
49 if ( /type/ && $effnum > 1 )
60 print NEWFILE
$linetoprint . "\n";
65 # Convert class entry.
66 s/class\s*armor_template\s*0/class armor_template 1/;
68 # Convert specialProtection.
76 /type\s*=\s*(.*),\s*elemental/;
78 if ( $pretype =~ /elemental/ || $pretype =~ /environmental/ )
80 # Get elemental subtype.
81 /elementalType\s*=\s*EDT(.*),\s*effect/;
86 /effectiveness\s*=(\d*)/;
88 if ( $effnum == 0 || $effnum == 1 )
90 $vullist .= " \| $pretype";
96 $_ = " [type = $pretype, effectiveness = $effnum]]";
100 # Convert encumberance.
101 if ( /encumberance/ )
106 /AT_strength]\s*=\s*(\d*)/;
107 $_ = "encumbrance [0] = $1";
109 elsif ( /AT_quickness/ )
111 /AT_quickness]\s*=\s*(\d*)/;
112 $_ = "encumbrance [1] = $1";
116 /AT_focus]\s*=\s*(\d*)/;
117 $_ = "encumbrance [2] = $1";
125 # Put contents of line into new file.
126 if ( $printline == 1 )
133 print NEWFILE
$linetoprint;
135 # Add the vulnerability line.
136 print NEWFILE
"vulnerability = $vullist\n";
143 rename $_[0], "$_[0].old";
144 rename "$_[0].new", $_[0];
148 open NEWFILE
, ">$_[0].new";
156 if ( $printline == 1 )
158 # On the second pass, remove any empty sp blocks.
159 if ( $linetoprint =~ /specialProtection/ )
163 print NEWFILE
$linetoprint . "\n";
167 print NEWFILE
"specialProtection = []\n";
172 print NEWFILE
$linetoprint . "\n";
181 print NEWFILE
$linetoprint;
188 rename "$_[0].new", $_[0];
193 rename "$_[0].old", $_[0];
196 # Open all files in a directory and convert them. Called recursively.
199 print "OPENING \[$_[0]\]\n";
200 opendir THISDIR
, $_[0] or die "I could not open $_[0]: $!\n";
201 my @allfiles = grep !/^\.\.?$/, readdir THISDIR
;
205 foreach $file (@allfiles)
210 chdir( ".." ) or die "Can't change to .. $!\n";