/// <summary> Searches a keybinding from the file </summary> /// <param name="inp"> The name of the binding </param> /// <param name="source"> The source datastructure (where to search)</param> /// <returns> The "KeyBinding" Object </returns> private KeyBinding Get(string inp, DataStructure source) { KeyBinding res; if (source.Contains <ushort[]>(inp)) { res = GetFromString(source.Get <ushort[]>(inp), inp); } else { res = GetFromString(source.Get <ushort>(inp), inp); } if (binding_dict.ContainsKey(source.Name)) { binding_dict [source.Name].Add(res); } else { binding_dict.Add(source.Name, new List <KeyBinding>() { res }); } return(res); }
public Consideration(DataStructure data) { //Debug.Log("build consideration"); List <ulong> code_list = new List <ulong>() { 0x0100000001010000 }; if (data.Contains <string>("code")) { code_list.AddRange(NMS.OS.OperatingSystem.CompileNMS(data.Get <string>("code"))); } else { code_list.AddRange(GetValue(data.Get <string>("value"))); foreach (DataStructure child in data.AllChildren) { switch (child.Name) { case "Process": code_list.AddRange(Process(child)); break; case "ReturnBool": code_list.AddRange(ReturnBool(child)); break; default: break; } } //Debug.Log(string.Join("\n", System.Array.ConvertAll(code_list.ToArray(), x => x.ToString("x0000000000000000")))); } compiled_code = code_list.ToArray(); }
public static void Main() { string input; DataStructure <string> customList = new DataStructure <string>(); while ((input = Console.ReadLine()) != "END") { string[] elements = input.Split(); string command = elements[0]; switch (command) { case "Add": customList.Add(elements[1]); break; case "Remove": customList.Remove(int.Parse(elements[1])); break; case "Contains": Console.WriteLine(customList.Contains(elements[1])); break; case "Swap": customList.Swap(int.Parse(elements[1]), int.Parse(elements[2])); break; case "Greater": Console.WriteLine(customList.CountGreaterThan(elements[1])); break; case "Max": Console.WriteLine(customList.Max()); break; case "Min": Console.WriteLine(customList.Min()); break; case "Print": foreach (var item in customList) { Console.WriteLine(item); } break; } } }
public void Initialize(int pregiven_id = -1) { //Read the data DataStructure data = data_ == null ? data_ = DataStructure.Load(config_path, "data", null) : data_; // Variables used to place weapons Dictionary <string, Turret[]> weapon_arrays = new Dictionary <string, Turret[]> (); //First set up some basic things Ship own_ship = new Ship(gameObject, friendly, data.Get <string>("name"), pregiven_id); ShipControl ship_control = Loader.EnsureComponent <ShipControl> (gameObject); RCSFiring rcs_comp = Loader.EnsureComponent <RCSFiring> (gameObject); own_ship.control_script = ship_control; own_ship.rcs_script = rcs_comp; own_ship.config_path = config_path; own_ship.TurretAim = own_ship.Target = Target.None; ship_control.myship = own_ship; // AI LowLevelAI ai = Loader.EnsureComponent <LowLevelAI>(gameObject); ai.Start_(); ai.HasHigherAI = !player; HighLevelAI high_ai = own_ship.high_ai; //high_ai.Load(child.GetChild("ai data")); high_ai.low_ai = ai; // Instantiates normal UI marker TgtMarker.Instantiate(own_ship, 1); foreach (KeyValuePair <string, DataStructure> child_pair in data_.children) { // Do this for each "command" in the datafile DataStructure child = child_pair.Value; string comp_name = child.Name; DataStructure part_data; if (child.Contains <string>("part")) { string part_name = child.Get <string>("part"); part_data = Globals.parts.Get <DataStructure>(part_name); } else { part_data = child; } switch (comp_name) { case "rcs": ship_control.RCS_ISP = child.Get <float>("isp"); rcs_comp.rcs_mesh = child.Get <GameObject>("mesh"); rcs_comp.strength = child.Get <float>("thrust"); rcs_comp.angular_limitation = child.Get <float>("angular limitation", 1); rcs_comp.positions = child.Get <Vector3[]>("positions"); rcs_comp.directions = child.Get <Quaternion[]>("orientations"); break; case "ship": if (rcs_comp != null) { rcs_comp.center_of_mass = child.Get <Vector3>("centerofmass"); } own_ship.offset = child.Get <Vector3>("centerofmass"); break; case "AI": high_ai.Load(child.GetChild("ai data")); break; case "engine": if (!include_parts) { break; } Engine.GetFromDS(part_data, child, transform); break; case "tank": if (!include_parts) { break; } FuelTank.GetFromDS(part_data, child, transform); break; case "fix weapon": if (!include_parts) { break; } Weapon.GetFromDS(part_data, child, transform); break; case "ammobox": if (!include_parts) { break; } AmmoBox.GetFromDS(part_data, child, transform); break; case "missiles": if (!include_parts) { break; } MissileLauncher.GetFromDS(part_data, child, transform); break; case "armor": if (!include_parts) { break; } Armor.GetFromDS(child, own_ship); break; default: if (comp_name.StartsWith("turr-")) { if (!include_parts) { break; } var tg = TurretGroup.Load(child, own_ship); weapon_arrays [comp_name.Substring(5)] = tg.TurretArray; ship_control.turretgroup_list.Add(new TurretGroup(Target.None, tg.TurretArray, tg.name) { own_ship = own_ship }); } break; } } // Initializes parts foreach (BulletCollisionDetection part in GetComponentsInChildren <BulletCollisionDetection>()) { part.Initialize(); } ship_control.turrets = weapon_arrays; }
public static TurretGroup Load(DataStructure specific_data, Ship parent) { string name = specific_data.Name.Substring(5); DataStructure[] parts_data; if (specific_data.Contains <string[]>("parts")) { string[] part_names = specific_data.Get <string[]>("parts"); parts_data = System.Array.ConvertAll(part_names, x => Globals.parts.Get <DataStructure>(x)); } else { parts_data = System.Array.FindAll(specific_data.AllChildren, x => x.Name.StartsWith("description")); } int count = specific_data.Get <Vector3[]>("positions").Length; Vector3 [] weapon_pos = specific_data.Get <Vector3[]>("positions"); Quaternion [] weapon_rot = specific_data.Get("rotations", new Quaternion[count]); float [] heats = specific_data.Get("heat", new float[count], quiet: true); float [] ooo_times = specific_data.Get("ooo time", new float[count], quiet: true); bool [] enabled_s = specific_data.Get("enabled", new bool[count], quiet: true); Quaternion [] barrel_rotations = specific_data.Get("barrel rotation", new Quaternion[count], quiet: true); Turret [] weapon_array = new Turret[count]; //This is for each weapon in it for (int i = 0; i < count; i++) { DataStructure part_data = parts_data[i]; // Range float [] range = new float[4] { -1f, -1f, -1f, -1f }; if (part_data.Contains <float[]>("horizontal range")) { range [0] = Mathf.Abs(Mathf.Min(part_data.Get <float[]>("horizontal range"))); range [1] = Mathf.Abs(Mathf.Max(part_data.Get <float[]>("horizontal range"))); } if (part_data.floats32_arr.ContainsKey("vertical range")) { range [2] = Mathf.Abs(Mathf.Min(part_data.Get <float[]>("vertical range"))); range [3] = Mathf.Abs(Mathf.Max(part_data.Get <float[]>("vertical range"))); } float horizontal_rate = part_data.Get <float>("horizontal rotating rate"); float vertical_rate = part_data.Get <float>("vertical rotating rate"); //uint ammo = part_data.short_integers["ammunition"]; float reload_speed = part_data.Get <float>("reload speed"); float muzzle_velocity = part_data.Get <float>("muzzle velocity"); Vector3 [] muzzle_positions = part_data.Get <Vector3[]>("barrels"); GameObject pref_weapon = part_data.Get <GameObject>("source"); Vector3 guns_p = parent.Position + parent.Orientation * weapon_pos[i]; Quaternion guns_rot = parent.Orientation * weapon_rot[i]; GameObject turret_object = Object.Instantiate(pref_weapon, guns_p, guns_rot); turret_object.transform.SetParent(parent.Transform); turret_object.name = string.Format("{0} ({1})", name, i.ToString()); Turret turret_instance = new Turret(range, turret_object, new float[2] { horizontal_rate, vertical_rate }, part_data.Get <float>("mass"), part_data.Get <System.UInt16>("hp")) { name = turret_object.name, //ammo_count = ammo, //full_ammunition = ammo, reload_speed = reload_speed, muzzle_velocity = muzzle_velocity, sound_name = part_data.Get <string>("sound"), ammo_type = Globals.ammunition_insts[part_data.Get <string>("ammotype")], muzzle_positions = muzzle_positions, description_ds = part_data, heat = heats[i], ooo_time = ooo_times[i], Enabled = enabled_s[i], }; weapon_array [i] = turret_instance; BulletCollisionDetection turret_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(turret_object); turret_behaviour.Part = turret_instance; } return(new TurretGroup(Target.None, weapon_array, name) { own_ship = parent }); }
// Here are all the Functions #region executable methods private Result Text() { if (d01 == 0) { if (!data.Contains <string>("text")) { parent_conv.LogError("Needs component \"text\"(chr)"); return(Result.error); } string text = data.Get <string>("text"); parent_conv.DisplayText(text); d01 = 1; } return(parent_conv.console.typing ? Result.running : Result.finished); }
public static void Load(string path) { DataStructure saved = DataStructure.Load(path); DataStructure general_information = saved.GetChild("GeneralInformation"); DataStructure original_file = DataStructure.Load(general_information.Get <string>("original_path"), is_general: true); FileReader.FileLog("Begin Loading", FileLogType.loader); GameObject placeholder = GameObject.Find("Placeholder"); GeneralExecution general = placeholder.GetComponent <GeneralExecution>(); general.battle_path = path; // Initiate Operating system general.os = new NMS.OS.OperatingSystem(Object.FindObjectOfType <ConsoleBehaviour>(), null); // Initiate mission core Loader partial_loader = new Loader(original_file); general.mission_core = new MissionCore(general.console, partial_loader); general.mission_core.in_level_progress = (short)general_information.Get <int>("in level progress"); general.mission_core.in_stage_progress = (short)general_information.Get <int>("in stage progress"); DeveloppmentTools.Log("start loading"); partial_loader.LoadEssentials(); DataStructure objects = saved.GetChild("ObjectStates"); Debug.Log(objects); foreach (DataStructure child in objects.AllChildren) { int id = child.Get <ushort>("type", 1000, quiet: true); switch (id) { case 0: // Ship Dictionary <string, Turret[]> weapon_arrays = new Dictionary <string, Turret[]>(); string config_path = child.Get <string>("config path"); bool is_friendly = child.Get <bool>("friendly"); bool is_player = child.Get <bool>("player"); int given_id = child.Get <int>("id"); GameObject ship_chassis = Loader.SpawnShip(config_path, is_friendly, is_player, false, pre_id: given_id); //LowLevelAI ai = Loader.EnsureComponent<LowLevelAI>(ship_chassis); //ai.HasHigherAI = !is_player; ShipControl ship_control = ship_chassis.GetComponent <ShipControl>(); Ship ship = ship_control.myship; //ship.control_script.ai_low = ai; //ship.low_ai = ai; int netID = child.Get("parent network", is_friendly ? 1 : 2); if (SceneObject.TotObjectList.ContainsKey(netID) && SceneObject.TotObjectList [netID] is Network) { ship.high_ai.Net = SceneObject.TotObjectList [netID] as Network; } ship.Position = child.Get <Vector3>("position"); ship.Orientation = child.Get <Quaternion>("orientation"); ship.Velocity = child.Get <Vector3>("velocity"); ship.AngularVelocity = child.Get <Vector3>("angular velocity"); foreach (DataStructure child01 in child.AllChildren) { switch (child01.Get <ushort>("type", 9, quiet:true)) { case 1: // weapon Weapon.GetFromDS(child01.GetChild("description"), child01, ship.Transform); break; case 3: // fuel tank FuelTank.GetFromDS(child01.GetChild("description"), child01, ship.Transform); break; case 4: // engine Engine.GetFromDS(child01.GetChild("description"), child01, ship.Transform); break; case 10: // ammo box AmmoBox.GetFromDS(child01.GetChild("description"), child01, ship.Transform); break; case 11: // missile launcher MissileLauncher.GetFromDS(child01.GetChild("description"), child01, ship.Transform); break; case 12: // armor Armor.GetFromDS(child01, ship); break; default: if (child01.Name.StartsWith("turr-")) { var tg = TurretGroup.Load(child01, ship); weapon_arrays [child01.Name.Substring(5)] = tg.TurretArray; ship_control.turretgroup_list.Add(new TurretGroup(Target.None, tg.TurretArray, tg.name) { own_ship = ship }); } break; } } // Initializes parts foreach (BulletCollisionDetection part in ship_chassis.GetComponentsInChildren <BulletCollisionDetection>()) { part.Initialize(); } ship_control.turrets = weapon_arrays; ship.os.cpu.Execute(child.Get <ulong []>("code")); if (is_player) { SceneGlobals.Player = ship; SceneGlobals.ui_script.Start_(); } break; case 1: // Missile Missile.SpawnFlying(child); break; case 2: // Bullet Bullet.Spawn( Globals.ammunition_insts [child.Get <string>("ammunition")], child.Get <Vector3>("position"), Quaternion.FromToRotation(Vector3.forward, child.Get <Vector3>("velocity")), child.Get <Vector3>("velocity"), child.Get <bool>("is_friend") ); break; case 3: // Destroyable target DestroyableTarget.Load(child); break; case 4: // Explosion break; } } general.os.Attached = SceneGlobals.Player; ReferenceSystem ref_sys; if (general_information.Contains <Vector3>("RS position")) { ref_sys = new ReferenceSystem(general_information.Get <Vector3>("RS position")); } else { int parent_id = general_information.Get <int>("RS parent"); if (SceneObject.TotObjectList.ContainsKey(parent_id)) { ref_sys = new ReferenceSystem(SceneObject.TotObjectList [parent_id]); } else { ref_sys = new ReferenceSystem(Vector3.zero); } ref_sys.Offset = general_information.Get <Vector3>("RS offset"); } SceneGlobals.ReferenceSystem = ref_sys; }