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 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; }