Merge branch 'master' of https://Governor-Tarkin@bitbucket.org/Governor-Tarkin/swg...
[swg-src.git] / tools / perllib / VehicleCustomizationVariableGenerator.pm
blobb3cd3b07d924dc5ffaf0aae87d674b135c2bf5fc
1 # ======================================================================
2 # VehicleCustomizationVariableGenerator.pm
3 # Copyright 2003, Sony Online Entertainment
4 # All rights reserved.
5 # ======================================================================
7 package VehicleCustomizationVariableGenerator;
8 use strict;
10 use CustomizationVariableCollector;
11 use Perforce;
12 use TreeFile;
14 # ======================================================================
15 # VehicleCustomizationVariableGenerator public variables.
16 # ======================================================================
18 # our $relativePathName;
20 # ======================================================================
21 # Setup variables that can be imported by Exporter into user modules.
22 # ======================================================================
24 use vars qw(@ISA @EXPORT_OK $VERSION);
25 use Exporter;
26 $VERSION = 1.00;
27 @ISA = qw(Exporter);
29 # These symbols are okay to export if specifically requested.
30 #@EXPORT_OK = qw(&buildFileLookupTable &saveFileLookupTable &loadFileLookupTable &getFullPathName);
31 @EXPORT_OK = qw(&install &collectData);
33 # ======================================================================
34 # VehicleCustomizationVariableGenerator private variables.
35 # ======================================================================
37 # my %handlerByTag;
38 my $debug = 0;
39 my %variableInfoByName;
40 my %vehicleSatToSaddleAppearanceMap;
42 # ======================================================================
43 # VehicleCustomizationVariableGenerator public functions.
44 # ======================================================================
46 sub install
50 # ----------------------------------------------------------------------
52 sub loadVehicleCustomizations
54 # Process args.
55 my $customizationsFileName = shift;
57 my $fileHandle;
58 open($fileHandle, '< ' . $customizationsFileName) or die "failed to load vehicle variable customizations file [$customizationsFileName]: $!";
60 # Skip first two lines: the tab file header.
61 $_ = <$fileHandle>;
62 $_ = <$fileHandle>;
64 # Grab all variable definitions.
65 while (<$fileHandle>)
67 chomp;
68 # Pattern: <name>\t<min val>\t<max val>\t<default>\t<conversion comment>
69 if (m/([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t/)
71 my $name = $1;
72 my $minValue = $2;
73 my $maxValue = $3;
74 my $defaultValue = $4;
76 print "vehicle customization definition: var=[$name], min=[$minValue], max=[$maxValue], default=[$defaultValue].\n" if $debug;
77 $variableInfoByName{$name} = $minValue . ':' . $maxValue . ':' . $defaultValue;
78 print "assigned as [$variableInfoByName{$name}]\n" if $debug;
80 else
82 print STDERR "failed to parse vehicle customization entry [$_] in file [$customizationsFileName]\n";
86 close($fileHandle) or die "failed to close file handle for [$customizationsFileName]: $!";
89 # ----------------------------------------------------------------------
91 sub applyCustomizationsToVehicles
93 # Handle args.
94 my $appearanceTableFileName = shift;
96 my $fileHandle;
97 open($fileHandle, '< ' . $appearanceTableFileName) or die "failed to load vehicle variable customizations file [$appearanceTableFileName]: $!";
99 # Skip first two lines: the tab file header.
100 $_ = <$fileHandle>;
101 $_ = <$fileHandle>;
103 # Get keys for the vehicle info array.
104 my @variableNameArray = sort keys %variableInfoByName;
106 # Loop through all appearances.
107 my @saddleAppearanceNameArray;
109 while (<$fileHandle>)
111 chomp;
112 if (m/^(\S+)/)
114 my $appearanceName = $1;
115 print "vehicle appearance: processing [$appearanceName]\n" if $debug;
116 foreach my $variableName (@variableNameArray)
118 my $variableInfo = $variableInfoByName{$variableName};
119 my @variableInfoArray = split /:/, $variableInfo;
120 my $variableCount = scalar(@variableInfoArray);
121 die "Internal error: variableInfoArray does not contain expected 3 elements [$variableCount]" if $variableCount != 3;
123 my $minValueInclusive = $variableInfoArray[0];
124 my $maxValueExclusive = $variableInfoArray[1];
125 my $defaultValue = $variableInfoArray[2];
127 CustomizationVariableCollector::logBasicRangedIntVariable($appearanceName, $variableName, $minValueInclusive, $maxValueExclusive, $defaultValue);
130 # Link this .sat appearance name to all saddle appearances (non-sat, static)
131 # so that the top-level .sat appearance appears to expose all the customization
132 # variables exposed by the non-sat, visible vehicle saddle appearances.
133 my $nameArrayString = $vehicleSatToSaddleAppearanceMap{$appearanceName};
134 if (defined($nameArrayString))
136 @saddleAppearanceNameArray = split(/:/, $nameArrayString);
137 foreach my $saddleAppearanceName (@saddleAppearanceNameArray)
139 CustomizationVariableCollector::logAssetLink($appearanceName, $saddleAppearanceName);
146 # ----------------------------------------------------------------------
148 sub buildSatLinkageMap
150 # Setup args.
151 my $logicalSaddleNameMapFileName = shift;
152 my $saddleAppearanceMapFileName = shift;
154 # Load mapping of mount/vehicle appearance to logical saddle name.
155 # This can be a one to many mapping.
156 my %appearanceToLsmMap;
157 my $fileHandle;
158 my @columns;
160 open($fileHandle, '< ' . $logicalSaddleNameMapFileName) or die "buildSatLinkageMap(): could not open file [$logicalSaddleNameMapFileName]: $!";
162 # Skip first two lines: the tab file header.
163 $_ = <$fileHandle>;
164 $_ = <$fileHandle>;
166 # Loop through rest of file.
167 while (<$fileHandle>)
169 # Remove end of line.
170 chomp();
172 # Break line entry into array elements based on tab.
173 @columns = split(/\t/);
175 # Column 0 is sat_or_skt_name
176 # Column 1 is logical_saddle_name
177 my $appearanceName = $columns[0];
178 my $logicalSaddleName = $columns[1];
180 # Add mapping.
181 if (exists $appearanceToLsmMap{$appearanceName})
183 $appearanceToLsmMap{$appearanceName} .= ':' . $logicalSaddleName;
185 else
187 $appearanceToLsmMap{$appearanceName} = $logicalSaddleName;
191 close($fileHandle) or die "buildSatLinkageMap(): could not close file [$logicalSaddleNameMapFileName]: $!";
193 # Load mapping of logical saddle name to saddle appearance name.
194 # This can be a one to many mapping.
195 my %lsmToSaddleAppearanceMap;
197 open($fileHandle, '< ' . $saddleAppearanceMapFileName) or die "buildSatLinkageMap(): could not open file [$saddleAppearanceMapFileName]: $!";
199 # Skip first two lines: the tab file header.
200 $_ = <$fileHandle>;
201 $_ = <$fileHandle>;
203 # Loop through contents.
204 while (<$fileHandle>)
206 # Remove end of line.
207 chomp();
209 # Break line entry into array elements based on tab.
210 @columns = split(/\t/);
212 # Column 0 is logical_saddle_name
213 # Column 2 is saddle_appearance_name
214 my $logicalSaddleName = $columns[0];
215 my $saddleAppearanceName = $columns[2];
217 # add mapping
218 if (exists $lsmToSaddleAppearanceMap{$logicalSaddleName})
220 $lsmToSaddleAppearanceMap{$logicalSaddleName} .= ':' . $saddleAppearanceName;
222 else
224 $lsmToSaddleAppearanceMap{$logicalSaddleName} = $saddleAppearanceName;
228 close($fileHandle) or die "buildSatLinkageMap(): could not close file [$saddleAppearanceMapFileName]: $!";
230 # Finally, build global mapping of vehicle appearance name to saddle appearance names.
231 # This is a one to many mapping.
232 my @logicalSaddleNameArray;
233 my @saddleAppearanceNameArray;
235 foreach my $vehicleAppearanceName (keys %appearanceToLsmMap)
237 my $lsmArrayString = $appearanceToLsmMap{$vehicleAppearanceName};
238 @logicalSaddleNameArray = split(/:/, $lsmArrayString);
240 foreach my $logicalSaddleName (@logicalSaddleNameArray)
242 my $appearanceArrayString = $lsmToSaddleAppearanceMap{$logicalSaddleName};
243 next if !defined($appearanceArrayString);
245 @saddleAppearanceNameArray = split(/:/, $appearanceArrayString);
246 foreach my $saddleAppearanceName (@saddleAppearanceNameArray)
248 # Add a mapping from the vehicle appearance name to this saddle appearance name.
249 if (exists $vehicleSatToSaddleAppearanceMap{$logicalSaddleName})
251 $vehicleSatToSaddleAppearanceMap{$vehicleAppearanceName} .= ':' . $saddleAppearanceName;
253 else
255 $vehicleSatToSaddleAppearanceMap{$vehicleAppearanceName} = $saddleAppearanceName;
262 # ----------------------------------------------------------------------
264 sub collectData
266 # Process args. Default the branch to "current" if not specified.
267 my $branch = shift;
268 $branch = "current" if !defined($branch);
270 # Constants.
271 my $vehicleDataP4Root = "//depot/swg/$branch/dsrc/sku.0/sys.shared/compiled/game/customization/";
273 # Load up the vehicle customizations to associate with every ridable vehicle.
274 my $customizationsFileName = Perforce::findOnDiskFileName($vehicleDataP4Root . "vehicle_customizations.tab");
275 loadVehicleCustomizations($customizationsFileName);
277 # Load up mapping of vehicle .sat appearance (invisible) to vehicle saddle appearance (visible).
278 # This is a one-to-many mapping.
279 my $saddleDataP4Root = "//depot/swg/$branch/dsrc/sku.0/sys.shared/compiled/game/datatables/mount/";
280 my $logicalSaddleNameMapFileName = Perforce::findOnDiskFileName($saddleDataP4Root . "logical_saddle_name_map.tab");
281 my $saddleAppearanceMapFileName = Perforce::findOnDiskFileName($saddleDataP4Root . "saddle_appearance_map.tab");
282 buildSatLinkageMap($logicalSaddleNameMapFileName, $saddleAppearanceMapFileName);
284 # Add appropriate variable declarations for each vehicle appearance listed in the vehicle appearances table.
285 my $appearanceTableFileName = Perforce::findOnDiskFileName($vehicleDataP4Root . "vehicle_appearances.tab");
286 applyCustomizationsToVehicles($appearanceTableFileName);
289 # ======================================================================