using System.Collections.Generic; using System.IO; namespace FSO.Common.Model { public class DynamicTuning { //global tuning: // city - // 0: terrain // 0: forceSnow (0/1/null) public static DynamicTuning Global; //string type/iff, int table, int index. public Dictionary>> Tuning = new Dictionary>>(); public const int CURRENT_VERSION = 0; public int Version = CURRENT_VERSION; public void SerializeInto(BinaryWriter writer) { writer.Write(CURRENT_VERSION); writer.Write(Tuning.Count); foreach (var type in Tuning) { writer.Write(type.Key); writer.Write(type.Value.Count); foreach (var table in type.Value) { writer.Write(table.Key); writer.Write(table.Value.Count); foreach (var value in table.Value) { writer.Write(value.Key); writer.Write(value.Value); } } } } public DynamicTuning(IEnumerable entries) { foreach (var entry in entries) { AddTuning(entry); } } public void AddTuning(DynTuningEntry entry) { Dictionary> tables; if (!Tuning.TryGetValue(entry.tuning_type, out tables)) { tables = new Dictionary>(); Tuning[entry.tuning_type] = tables; } Dictionary data; if (!tables.TryGetValue(entry.tuning_table, out data)) { data = new Dictionary(); tables[entry.tuning_table] = data; } data[entry.tuning_index] = entry.value; } public DynamicTuning(DynamicTuning old) { foreach (var type in Tuning) { var newType = new Dictionary>(); foreach (var table in type.Value) { var newTable = new Dictionary(); foreach (var value in table.Value) { newTable[value.Key] = value.Value; } newType[table.Key] = newTable; } Tuning[type.Key] = newType; } } public DynamicTuning(BinaryReader reader) { Version = reader.ReadInt32(); var count = reader.ReadInt32(); for (int i=0; i>(); for (int j = 0; j < count2; j++) { var key2 = reader.ReadInt32(); var count3 = reader.ReadInt32(); var newTable = new Dictionary(); for (int k=0; k GetTable(string type, int table) { Dictionary> tables; if (Tuning.TryGetValue(type, out tables)) { Dictionary data; if (tables.TryGetValue(table, out data)) { return data; } } return null; } public Dictionary> GetTables(string type) { Dictionary> tables; if (Tuning.TryGetValue(type, out tables)) { return tables; } return null; } public float? GetTuning(string type, int table, int index) { Dictionary> tables; if (Tuning.TryGetValue(type, out tables)) { Dictionary data; if (tables.TryGetValue(table, out data)) { float result; if (data.TryGetValue(index, out result)) return result; } } return null; } } }