5 $balance_sheet = "ship_balance.txt";
6 $comp_sheet = "crafted_component_balance.txt";
8 #$template_path = "C:\Projects\swg\current\exe\win32\TemplateCompiler.exe
9 $server_prefix = "\\swg\\current\\dsrc\\sku.0\\sys.server\\compiled\\game\\object\\draft_schematic\\space";
10 $shared_prefix = "\\swg\\current\\dsrc\\sku.0\\sys.shared\\compiled\\game\\object\\draft_schematic\\space";
11 $shared_bin_prefix = "\\swg\\current\\data\\sku.0\\sys.shared\\compiled\\game\\object\\draft_schematic\\space";
17 # Read our balance sheet.
18 print "\nbalance_space_crafted process started\n";
20 if ( $ARGV[0] ne undef )
27 calculateCoreBalance
();
32 # Overall function for reading the balance sheet.
37 open BALANCE
, "<$balance_sheet";
43 if ( /Core Balance Data/ )
47 elsif ( /Player Baseline/ )
51 elsif ( /Player Factor/ )
53 @player_factor = @fields;
61 # sub calculateCoreBalance
64 sub calculateCoreBalance
66 for ( my $i=0; $i<@header; $i++ )
73 for ( my $tier=1; $tier<6; $tier++ )
76 my $name = $key . "_tier" . $tier;
78 # Modify by the player tier factor.
82 @factor = split /!/, $player_factor[$i];
86 for ( my $x=1; $x<$tier; $x++ )
92 $f = sprintf( "%.2f", $f );
93 $balancedata{$name} = $f;
99 # sub readCraftedChunks
102 sub readCraftedChunks
104 # Read balance data from the loot sheet.
105 open CRAFTED_COMPONENTS
, "<$comp_sheet";
106 while ( <CRAFTED_COMPONENTS
> )
112 /Mass Distribution/ and do { $massb = readBaseline
( $line, $massb, \
$massindex ); next; };
113 /Reactor Drain Distribution/ and do { $reactorb = readBaseline
( $line, $reactorb, \
$reactorindex ); next; };
115 # Chassis mass distribution.
116 /Chassis/ and do { processChassis
( $line ); next; };
121 processComponentChunk
( $line );
125 @cfields = split /\t/, $line;
126 $chunk = $cfields[0];
127 $directory = $cfields[1];
128 $varmod = $cfields[2];
131 close CRAFTED_COMPONENTS
;
140 my ($line, $var, $index) = @_;
142 # Check for end of chunk.
152 @fields = split /\t/, $line;
153 if ( $fields[0] ne "BASELINE" )
171 # Check for end of chunk.
179 # Write chassis mass values to the chassis draft schematics.
181 @fields = split /\t/, $line;
182 if ( $fields[0] eq "Name" )
188 my $filename = $shared_prefix . "\\chassis\\shared_" . $fields[0] . ".tpf";
189 $filename =~ s/\\/\//g
;
190 my $p4name = $filename;
191 my $filename = $shared_prefix . "\\chassis\\shared_" . $fields[0] . ".tpf";
193 # Calculate the mass range for this chassis.
194 @mass = split /\t/, $massb;
195 $medmass = $fields[1] * $mass[0];
196 $massvar = $fields[2] * $mass[0];
197 $mass_min = $medmass - ($massvar/2);
198 $mass_max = $medmass + ($massvar/2);
200 # Check out the file to be edited.
201 system( "p4 edit //depot" . $p4name );
203 # Read the schematic.
204 open CHASSIS
, "<$filename";
206 while ( my $z = <CHASSIS
> )
208 # Read the file into a buffer.
213 # Dump the modified schematic.
214 open CHASSIS
, ">$filename";
215 for ( my $i=0; $i<@lines; $i++ )
217 if ( $lines[$i] =~ m/\"massMax\"/ )
219 $lines[$i] =~ s/(\d*)\.\.(\d*)/$mass_min\.\.$mass_max/;
221 print CHASSIS
$lines[$i];
226 # Check out the .iff.
227 my $sfilename = $shared_bin_prefix . "\\chassis\\shared_" . $fields[0] . ".iff";
228 $sfilename =~ s/\\/\//g
;
229 my $sp4name = $sfilename;
230 system( "p4 edit //depot" . $sp4name );
232 # Compile the freaking file.
233 system( "templatecompiler -compile $filename" );
238 # sub processComponentChunk
241 sub processComponentChunk
245 # Check for end of chunk.
246 if ( $line =~ m/^\s*\n$/ )
254 @fields = split /\t/, $line;
256 if ( ($argtype ne undef) && ($directory ne $argtype) )
261 # Read the chunk header.
264 @categories = @fields;
268 elsif ( $header == 1 )
270 @bal_cat_names = @fields;
274 elsif ( $header == 2 )
276 @var_names = @fields;
280 elsif ( $header == 3 )
282 @exp_names = @fields;
286 elsif ( $header == 4 )
293 # Read a component chunk entry.
295 my $filename = "$shared_prefix\\$directory\\shared_$fields[0].tpf";
296 $filename =~ s/\\/\//g
;
297 my $p4name = $filename;
298 my $filename = "$shared_prefix\\$directory\\shared_$fields[0].tpf";
300 print $filename . "\n";
302 # Check out the file to be edited.
303 system( "p4 edit //depot" . $p4name );
305 # Read the schematic.
306 open SCHEMATIC
, "<$filename";
308 while ( my $z = <SCHEMATIC
> )
310 # Read the file into a buffer.
315 # Write out our changes.
316 open SCHEMATIC
, ">$filename";
317 for ( my $i=0; $i<@lines; $i++ )
319 $lines[$i] =~ m/\"crafting\" \"(\w*)\", exp/;
323 print SCHEMATIC
$lines[$i];
327 foreach $str (@var_names)
331 # print "var: $var\n";
333 # Find our cert level.
334 if ( $categories[1] eq "Cert" )
344 $tier = sprintf( "%.0f", $cert/2 );
345 $step = ($fields[1] % 2) == 0;
352 # We want to calculate the correct range for this crafting variable.
353 # >>>>>> THIS IS THE MEAT OF THIS CODE
354 # print " exp: $exp_names[$x]\n";
356 $balcat = $bal_cat_names[$x];
357 if ( $balcat =~ m/None/ )
359 # Just use this range as stated in the balance line.
360 $range_min = $fields[$x];
361 $range_max = $fields[$x];
363 elsif ( $balcat =~ m/Var/ )
365 # Just use this range as stated in the balance line, with variance.
366 $variance = $fields[$x] * 0.15 * $varmod;
367 $range_min = $fields[$x] - ($variance/2);
368 $range_max = $fields[$x] + ($variance/2);
370 elsif ( $balcat =~ m/Mass/ )
372 # Mass is derived from the mass baseline for this object type.
373 @massindexf = split /\t/, $massindex;
374 @massf = split /\t/, $massb;
375 for ( my $y=0; $y<@massindexf; $y++ )
377 if ( $massindexf[$y] eq $directory )
379 $basemass = $massf[$y] * $massf[0] * $fields[$x];
380 $variance = $basemass * 0.15 * $varmod;
381 $range_min = $basemass - ($variance/2);
382 $range_max = $basemass + ($variance/2);
387 elsif ( $balcat =~ m/ReactorDrain/ )
389 # Reactor drain is derived from the reactor baseline for this object type.
390 @drainindexf = split /\t/, $reactorindex;
391 @drainf = split /\t/, $reactorb;
392 for ( my $y=0; $y<@drainindexf; $y++ )
394 if ( $drainindexf[$y] eq $directory )
396 $basedrain = $drainf[$y] * $drainf[0] * $fields[$x];
397 $variance = $basedrain * 0.15 * $varmod;
398 $range_min = $basedrain - ($variance/2);
399 $range_max = $basedrain + ($variance/2);
404 elsif ( $balcat =~ m/ReactorGen/ )
406 # Reactor gen is specific to the crafted object balance sheet.
407 $data = $baseline[$x] * $fields[$x];
408 $variance = $data * 0.15 * $varmod;
409 $range_min = $data - ($variance/2);
410 $range_max = $data + ($variance/2);
412 elsif ( $balcat =~ m/CompArmor/ )
414 # Armor on components is half normal component value.
415 $data = $balancedata{"Component_tier".$tier} * $fields[$x] * $mod;
417 $variance = $data * 0.15 * $varmod;
418 $range_min = $data - ($variance/2);
419 $range_max = $data + ($variance/2);
421 elsif( ($balcat =~ m/WeaponRate/) || ($balcat =~ m/WeaponEffShield/) || ($balcat =~ m/WeaponEffArmor/) || ($balcat =~ m/ShieldRegen/) )
423 # These entries must be scaled up.
424 $data = $balancedata{$bal_cat_names[$x]."_tier".$tier} * $fields[$x] * $mod * 1000;
425 $variance = $data * 0.15 * $varmod;
426 $range_min = $data - ($variance/2);
427 $range_max = $data + ($variance/2);
432 $data = $balancedata{$bal_cat_names[$x]."_tier".$tier} * $fields[$x] * $mod;
433 $variance = $data * 0.15 * $varmod;
434 $range_min = $data - ($variance/2);
435 $range_max = $data + ($variance/2);
438 # Maintain left-to-right relationship.
439 if ( $range_max < $range_min )
441 my $temp = $range_max;
442 $range_max = $range_min;
446 # Format into integers.
447 $range_min = sprintf( "%.0f", $range_min );
448 $range_max = sprintf( "%.0f", $range_max );
450 # print " range: $range_min..$range_max\n";
452 $lines[$i] =~ m/^(.*=\s*)-?\d+\.\.-?\d+(].*)$/;
455 $lines[$i] = $1 . $range_min . ".." . $range_max . $2 . "\n";
456 # print $lines[$i] . "\n";
464 print SCHEMATIC
$lines[$i];
470 # Check out the .iff.
471 my $sfilename = "$shared_bin_prefix\\$directory\\shared_$fields[0].iff";
472 $sfilename =~ s/\\/\//g
;
473 my $sp4name = $sfilename;
474 system( "p4 edit //depot" . $sp4name );
476 # Compile the freaking file.
477 system( "templatecompiler -compile $filename" );