/// <summary> /// Appends this <see cref="TruckSound"/> to an open <see cref="SiiFileBuilder"/> object /// </summary> public override void AppendTo(SiiFileBuilder builder, string objectName, SoundPackage package) { // Begin the accessory builder.WriteStructStart("sound_data", objectName); // Write attributes builder.WriteAttribute("name", GetParsedFileNamePath(package)); builder.WriteAttribute("looped", this.Looped); if (this.Is2D) { builder.WriteAttribute("is_2d", true); } if (this.Volume != 1.0) { builder.WriteAttribute("volume", this.Volume); } // Close Accessory builder.WriteStructEnd(); }
/// <summary> /// Appends this <see cref="EngineSound"/> to an open <see cref="SiiFileBuilder"/> object /// </summary> public override void AppendTo(SiiFileBuilder builder, string objectName, SoundPackage package) { // Begin the accessory builder.WriteStructStart("sound_engine_data", objectName); // Write attributes builder.WriteAttribute("name", GetParsedFileNamePath(package)); builder.WriteAttribute("looped", this.Looped); if (this.Is2D) { builder.WriteAttribute("is_2d", true); } if (this.PitchReference > 0) { builder.WriteAttribute("pitch_reference", this.PitchReference); } if (this.MinRpm > 0) { builder.WriteAttribute("min_rpm", (decimal)this.MinRpm); } if (this.MaxRpm > 0) { builder.WriteAttribute("max_rpm", (decimal)this.MaxRpm); } if (this.Volume != 1.0) { builder.WriteAttribute("volume", this.Volume); } // Close Accessory builder.WriteStructEnd(); }
/// <summary> /// Serializes this transmission into SII format, and returns the result /// </summary> /// <returns></returns> public string ToSiiFormat(string truckName) { // Create local variables var series = this.Series; var builder = new SiiFileBuilder(); var name = $"{this.UnitName}.{truckName}.transmission"; var hasNames = Gears.Any(x => !String.IsNullOrWhiteSpace(x.Name)); // Make sure we have a file comment if (Comment == null || Comment.Length == 0) { Comment = new string[] { "Generated with the ATS Engine Generator Tool by Wilson212" } } ; // Write file intro builder.WriteStartDocument(); // Write file comment builder.WriteCommentBlock(Comment); // Begin the engine accessory builder.WriteStructStart("accessory_transmission_data", name); // Generic Info builder.WriteAttribute("name", this.Name); builder.WriteAttribute("price", this.Price, "Transmission price", 1); builder.WriteAttribute("unlock", this.Unlock, "Unlocks @ Level", 2); builder.WriteAttribute("icon", series.Icon); builder.WriteLine(); // Add names if we have them if (hasNames) { builder.WriteLine("# Transmission gear names"); builder.WriteAttribute("transmission_names", ".names", false); builder.WriteLine(); } // Diff Ratio builder.WriteLine("# Differential Ratio: 2.64, 2.85, 2.93, 3.08, 3.25, 3.36, 3.40?, 3.42, 3.55, 3.58(single) 3.70, 3.73?, 3.78, 3.91, 4.10"); builder.WriteAttribute("differential_ratio", this.DifferentialRatio); builder.WriteLine(); // Add Retarder if (Retarder > 0) { builder.WriteLine("# Retarder"); builder.WriteAttribute("retarder", Retarder); builder.WriteLine(); } if (StallTorqueRatio > 0.0m) { builder.WriteLine("# Torque Converter: 2.42, 2.34, 1.9, 1.79, 1.58"); builder.WriteAttribute("stall_torque_ratio", StallTorqueRatio); builder.WriteLine(); } // Create gear lists var reverseGears = new List <TransmissionGear>(this.Gears.Where(x => x.IsReverse)); var forwardGears = new List <TransmissionGear>(this.Gears.Where(x => !x.IsReverse)); // Reverse Gears int i = 0; builder.WriteLine($"# reverse gears"); foreach (var gear in reverseGears) { builder.WriteAttribute($"ratios_reverse[{i++}]", gear.Ratio); } builder.WriteLine(); // Forward Gears i = 0; builder.WriteLine($"# forward gears"); foreach (var gear in forwardGears) { builder.WriteAttribute($"ratios_forward[{i++}]", gear.Ratio); } // Write the default[]... if (Defaults != null && Defaults.Length > 0) { builder.WriteLine(); builder.WriteLine("# Attachments"); foreach (string line in Defaults) { builder.WriteAttribute("defaults[]", line); } } // Define is we output suitible_for and conflict_with for engines bool writeSuitables = Program.Config.CompileOption == CompileOption.TransmissionOnly || Program.Config.CompileOption == CompileOption.Both; var conflicts = this.EngineConflicts.ToList(); var suitables = this.SuitableEngines.ToList(); // Write the conflict_with[]... if (conflicts.Count > 0 || (Conflicts != null && Conflicts.Length > 0)) { builder.WriteLine(); builder.WriteLine("# Conflicts"); // Engines foreach (string eng in conflicts.Select(x => x.Engine.UnitName)) { builder.WriteAttribute("conflict_with[]", $"{eng}.{truckName}.engine"); } // Other Conflicts if (Conflicts != null) { foreach (string line in Conflicts) { builder.WriteAttribute("conflict_with[]", line); } } } // Write the conflict_with[]... if ((writeSuitables && suitables.Count > 0) || (SuitableFor != null && SuitableFor.Length > 0)) { builder.WriteLine(); builder.WriteLine("# Suitables"); // Engines? if (writeSuitables) { foreach (string eng in suitables.Select(x => x.Engine.UnitName)) { builder.WriteAttribute("suitable_for[]", $"{eng}.{truckName}.engine"); } } // Other Suitables if (SuitableFor != null) { foreach (string line in SuitableFor) { builder.WriteAttribute("suitable_for[]", line); } } } // Close brackets builder.WriteStructEnd(); // Do we have gear names? if (hasNames) { builder.WriteLine(); builder.WriteStructStart("transmission_names", ".names"); // Neutral always first builder.WriteAttribute("neutral", "N"); // Forward Gears i = 0; // Reset builder.WriteLine(); builder.WriteLine("# Forward Gear Names"); foreach (var gear in forwardGears) { name = GetGearNameAtIndex(i, gear, forwardGears); builder.WriteAttribute($"forward[{i++}]", name); } // Reverse Gears i = 0; // Reset builder.WriteLine(); builder.WriteLine("# Reverse Gear Names"); foreach (var gear in reverseGears) { name = GetGearNameAtIndex(i, gear, reverseGears); builder.WriteAttribute($"reverse[{i++}]", name); } builder.WriteStructEnd(); } // End brace builder.WriteEndDocument(); // Define file paths return(builder.ToString().Replace("{{{NAME}}}", truckName).TrimEnd()); }
/// <summary> /// Serializes this engine into SII format, and returns the result /// </summary> /// <returns></returns> public string ToSiiFormat(string truckName) { // Create local variables EngineSeries series = this.Series; SiiFileBuilder builder = new SiiFileBuilder(); string name = $"{this.UnitName}.{truckName}.engine"; string decvalue; // Make sure we have a file comment if (Comment == null || Comment.Length == 0) { Comment = new string[] { "Generated with the ATS Engine Generator Tool by Wilson212" } } ; // Write file intro builder.WriteStartDocument(); // Write file comment builder.WriteCommentBlock(Comment); // Begin the engine accessory builder.WriteStructStart("accessory_engine_data", name); // Generic Info builder.WriteAttribute("name", this.Name); builder.WriteAttribute("price", this.Price, "Engine price", 1); builder.WriteAttribute("unlock", this.Unlock, "Unlocks @ Level", 2); builder.WriteLine(); // Horsepower line builder.WriteLine("# Engine display info"); builder.WriteAttribute("info[]", $"{Digitize(this.Horsepower)} @@hp@@ ({Digitize(this.Kilowatts)}@@kw@@)"); // Torque line builder.Write("info[]: \""); if (Program.Config.TorqueOutputUnitSystem == UnitSystem.Imperial) { builder.WriteLine($"{Digitize(this.Torque)} @@lb_ft@@ ({Digitize(this.NewtonMetres)} @@nm@@)\""); } else { builder.WriteLine($"{Digitize(this.NewtonMetres)} @@nm@@ ({Digitize(this.Torque)} @@lb_ft@@)\""); } // Rpm line builder.WriteAttribute($"info[]", $"{Digitize(this.PeakRpm)} @@rpm@@"); // Icon builder.WriteAttribute($"icon", series.EngineIcon); builder.WriteLine(); // Performance decvalue = series.Displacement.ToString("0.0", Program.NumberFormat); builder.WriteLine("# Engine Specs"); builder.WriteAttribute("torque", this.NewtonMetres, "Engine power in Newton-metres"); if (ResistanceTorque > 0) { builder.WriteAttribute("resistance_torque", ResistanceTorque.ToString("0.0", Program.NumberFormat)); } builder.WriteAttribute("volume", decvalue, false, "Engine size in liters. Used for Realistic Fuel Consumption settings"); builder.WriteLine(); // Torque Curves var ratios = TorqueRatios.OrderBy(x => x.RpmLevel).ToArray(); if (ratios.Length > 0) { builder.WriteLine("# Torque Curves"); foreach (TorqueRatio ratio in ratios) { decvalue = ratio.Ratio.ToString(Program.NumberFormat); builder.WriteAttribute($"torque_curve[]", $"({ratio.RpmLevel}, {decvalue})", false); } builder.WriteLine(); } // RPM datas builder.WriteLine("# RPM Data"); builder.WriteAttribute("rpm_idle", this.IdleRpm, "RPM at idle", 3); builder.WriteAttribute("rpm_limit", this.RpmLimit, "Governed RPM limit", 3); builder.WriteAttribute("rpm_limit_neutral", this.RpmLimitNeutral, "RPM limit in neutral gear"); if (this.MaxRpmRange_LowGear > 0) { builder.WriteAttribute("rpm_range_low_gear", $"({this.MinRpmRange_LowGear}, {this.MaxRpmRange_LowGear})", false); } if (this.MaxRpmRange_HighGear > 0) { builder.WriteAttribute("rpm_range_high_gear", $"({this.MinRpmRange_HighGear}, {this.MaxRpmRange_HighGear})", false); } if (this.HighRpmRange_PowerBoost > 0 || this.LowRpmRange_PowerBoost > 0) { builder.WriteAttribute("rpm_range_power_boost", $"({this.LowRpmRange_PowerBoost}, {this.HighRpmRange_PowerBoost})", false); } if (HighRpmRange_EngineBrake > 0) { builder.WriteAttribute("rpm_range_engine_brake", $"({this.LowRpmRange_EngineBrake}, {this.HighRpmRange_EngineBrake})", false); } // Engine Brake string val = this.BrakeDownshift ? "1" : "0"; decvalue = this.BrakeStrength.ToString("0.0", Program.NumberFormat); builder.WriteLine(); builder.WriteLine("# Engine Brake data"); builder.WriteAttribute("engine_brake", decvalue, false, "Engine Brake Strength", 3); builder.WriteAttribute("engine_brake_downshift", val, false, "Enable automatic downshift for Engine Brake"); builder.WriteAttribute("engine_brake_positions", this.BrakePositions, "The number of engine brake intensities"); builder.WriteLine(); // AdBlue / Fuel consumption if (this.AdblueConsumption > 0.00m || this.NoAdbluePowerLimit > 0.00m || this.FuelConsumption != 1.00m) { builder.WriteLine("# Adblue / Fuel consumption Settings"); if (this.FuelConsumption != 1.00m) { builder.WriteAttribute("consumption_coef", this.FuelConsumption); } if (this.AdblueConsumption > 0.00m) { builder.WriteAttribute("adblue_consumption", this.AdblueConsumption); } if (this.NoAdbluePowerLimit > 0.00m) { builder.WriteAttribute("no_adblue_power_limit", this.NoAdbluePowerLimit); } builder.WriteLine(); } // Sound Data SoundPackage sound = series.SoundPackage; builder.WriteLine("# Sound Data"); builder.WriteAttribute("overrides[]", $"/def/vehicle/truck/{truckName}/sound/{sound.InteriorFileName}"); builder.WriteAttribute("overrides[]", $"/def/vehicle/truck/{truckName}/sound/{sound.ExteriorFileName}"); // Write the overrides[]... if (Overrides != null && Overrides.Length > 0) { builder.WriteLine(); builder.WriteLine("# Overrides"); foreach (string line in Overrides) { builder.WriteAttribute($"overrides[]", line); } } // Write the default[]... if (Defaults != null && Defaults.Length > 0) { builder.WriteLine(); builder.WriteLine("# Attachments"); foreach (string line in Defaults) { builder.WriteAttribute($"defaults[]", line); } } // Define is we output suitible_for and conflict_with for transmissions bool writeSuitables = Program.Config.CompileOption == CompileOption.EngineOnly || Program.Config.CompileOption == CompileOption.Both; var conflicts = this.TransmissionConflicts.ToList(); var suitables = this.SuitableTransmissions.ToList(); // Write the conflict_with[]... if (conflicts.Count > 0 || (Conflicts != null && Conflicts.Length > 0)) { builder.WriteLine(); builder.WriteLine("# Conflicts"); // Transmissions foreach (string line in conflicts.Select(x => x.Transmission.UnitName)) { builder.WriteAttribute("conflict_with[]", $"{line}.{truckName}.transmission"); } // Other Conflicts if (Conflicts != null) { foreach (string line in Conflicts) { builder.WriteAttribute("conflict_with[]", line); } } } // Write the suitable_for[]... if ((writeSuitables && suitables.Count > 0) || (SuitableFor != null && SuitableFor.Length > 0)) { builder.WriteLine(); builder.WriteLine("# Suitables"); // Transmissions? if (writeSuitables) { foreach (string trans in suitables.Select(x => x.Transmission.UnitName)) { builder.WriteAttribute("suitable_for[]", $"{trans}.{truckName}.transmission"); } } // Other Suitables if (SuitableFor != null) { foreach (string line in SuitableFor) { builder.WriteAttribute("suitable_for[]", line); } } } // Close brackets builder.WriteEndDocument(); // Define file paths return(builder.ToString().Replace("{{{NAME}}}", truckName).TrimEnd()); }