/// <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> /// /// </summary> /// <param name="package"></param> /// <returns></returns> protected string GetParsedFileNamePath(SoundPackage package) { // Figure out file path string file = this.FileName; if (this.FileName.StartsWith("@")) { string directive = this.FileName.Substring(1, 2); switch (directive.ToUpperInvariant()) { case "SP": case "CP": case "EP": file = this.FileName.Replace($"@{directive}", package.PackageGamePath); break; default: file = this.FileName.Replace($"@{directive}", "/sound/truck/default"); break; } } return(file); }
/// <summary> /// Appends this <see cref="Sound"/> to an open <see cref="SiiFileBuilder"/> object /// </summary> public abstract void AppendTo(SiiFileBuilder builder, string objectName, SoundPackage package);
/// <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()); }