1 # ======================================================================
2 # VehicleCustomizationVariableGenerator.pm
3 # Copyright 2003, Sony Online Entertainment
5 # ======================================================================
7 package VehicleCustomizationVariableGenerator
;
10 use CustomizationVariableCollector
;
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);
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 # ======================================================================
39 my %variableInfoByName;
40 my %vehicleSatToSaddleAppearanceMap;
42 # ======================================================================
43 # VehicleCustomizationVariableGenerator public functions.
44 # ======================================================================
50 # ----------------------------------------------------------------------
52 sub loadVehicleCustomizations
55 my $customizationsFileName = shift;
58 open($fileHandle, '< ' . $customizationsFileName) or die "failed to load vehicle variable customizations file [$customizationsFileName]: $!";
60 # Skip first two lines: the tab file header.
64 # Grab all variable definitions.
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/)
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;
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
94 my $appearanceTableFileName = shift;
97 open($fileHandle, '< ' . $appearanceTableFileName) or die "failed to load vehicle variable customizations file [$appearanceTableFileName]: $!";
99 # Skip first two lines: the tab file header.
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>)
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
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;
160 open($fileHandle, '< ' . $logicalSaddleNameMapFileName) or die "buildSatLinkageMap(): could not open file [$logicalSaddleNameMapFileName]: $!";
162 # Skip first two lines: the tab file header.
166 # Loop through rest of file.
167 while (<$fileHandle>)
169 # Remove end of line.
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];
181 if (exists $appearanceToLsmMap{$appearanceName})
183 $appearanceToLsmMap{$appearanceName} .= ':' . $logicalSaddleName;
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.
203 # Loop through contents.
204 while (<$fileHandle>)
206 # Remove end of line.
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];
218 if (exists $lsmToSaddleAppearanceMap{$logicalSaddleName})
220 $lsmToSaddleAppearanceMap{$logicalSaddleName} .= ':' . $saddleAppearanceName;
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;
255 $vehicleSatToSaddleAppearanceMap{$vehicleAppearanceName} = $saddleAppearanceName;
262 # ----------------------------------------------------------------------
266 # Process args. Default the branch to "current" if not specified.
268 $branch = "current" if !defined($branch);
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 # ======================================================================