/// <param name="sourcedata"> The datastructure containing thedata of the player </param> /// <param name="path"> The path, where the player's data is saaved, from /configs on </param> /// <example> <c> /// DataStructure player_data = DataStructure.Load("saved/characters/ivan.txt", "ivan", null); /// Character Ivan = new Character(sourcedata: player_data, path: "saved/characters/ivan.txt"); /// </c> </example> public Character(DataStructure sourcedata, string path) { datastr = sourcedata; file_name = path; DataStructure polit = sourcedata.GetChild("political"); politics [0] = polit.Get <double>("cap"); politics [1] = polit.Get <double>("auth"); politics [2] = polit.Get <double>("nat"); politics [3] = polit.Get <double>("trad"); DataStructure skilldata = sourcedata.GetChild("skills"); skills [Skills.pilot] = skilldata.Get <ushort>("pilot"); skills [Skills.computer] = skilldata.Get <ushort>("computer"); skills [Skills.engineering] = skilldata.Get <ushort>("engineering"); skills [Skills.trade] = skilldata.Get <ushort>("trade"); skills [Skills.diplomacy] = skilldata.Get <ushort>("diplomacy"); DataStructure general = sourcedata.GetChild("stats"); forename = general.Get <string>("forename"); aftername = general.Get <string>("aftername"); DataStructure progress = sourcedata.GetChild("progress"); campagne = DataStructure.Load(progress.Get("campagne", "campagne/campagne_mars", quiet: true)); story_stage = progress.Get <ushort>("level"); chapter = progress.Get <string>("chapter"); }
/// <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); }
/// <summary> Constructor directly interprets the Data structures </summary> /// <param name="data"> The datastructure in question </param> public Chapter(DataStructure data) { //UnityEngine.Debug.Log(data); NMS.OS.OperatingSystem os = Globals.current_os; name = data.Get <string>("name", quiet: true); directory_name = "campagne/" + data.Get <string>("directory", quiet: true) + "/"; List <ChapterBattle> battle_list = new List <ChapterBattle>(); List <ChapterConversation> conversation_list = new List <ChapterConversation>(); List <ChapterJump> jump_list = new List <ChapterJump>(); foreach (DataStructure child in data.AllChildren) { switch (child.Name) { case "battle": DataStructure datastr = DataStructure.Load(directory_name + child.Get <string>("filename"), parent: child); battle_list.Add(new ChapterBattle() { AviableOn = child.Get <ushort[]>("aviable"), Name = child.Get <string>("name"), path = directory_name + child.Get <string>("filename"), own_data = datastr, planet_name = child.Get("planet", "Trantor"), progress = child.Get <ushort>("progress", 0), }); break; case "conversation": conversation_list.Add(new ChapterConversation() { AviableOn = child.Get <ushort []>("aviable"), Name = child.Get <string>("name"), own_data = child, progress = child.Get <ushort>("progress"), }); break; case "jump chapter": jump_list.Add(new ChapterJump() { AviableOn = child.Get <ushort []>("aviable"), Name = child.Get <string>("name"), new_chapter = child.Get <string>("chapter name"), }); break; } } battles = battle_list.ToArray(); conversations = conversation_list.ToArray(); jumps = jump_list.ToArray(); all_events = new IChapterEvent [battles.Length + conversations.Length + jumps.Length]; battles.CopyTo(all_events, 0); conversations.CopyTo(all_events, battles.Length); jumps.CopyTo(all_events, battles.Length + conversations.Length); }
public void TestPutDummyclassInt() { var c = new DummyClass(); dataStructureDummyClassInt.Put(c, 1); Assert.AreEqual(dataStructureDummyClassInt.Get(c), 1); }
public static void Initialize(DataStructure ds) { total = ds.Get <float>("total"); music = ds.Get <float>("music"); sfx = ds.Get <float>("spacecraft"); ui = ds.Get <float>("UIsound"); }
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 MissileLauncher GetFromDS(DataStructure part_data, DataStructure specific_data, Transform parent) { if (part_data.Get <GameObject>("source") == null) { Debug.Log(part_data); } GameObject launcher_obj = Object.Instantiate(part_data.Get <GameObject>("source")); launcher_obj.transform.position = parent.position + parent.rotation * specific_data.Get <Vector3>("position"); launcher_obj.transform.rotation = parent.rotation * specific_data.Get <Quaternion>("rotation"); launcher_obj.transform.SetParent(parent, true); MissileLauncher launcher_instance = new MissileLauncher((float)part_data.Get <ushort>("hp"), launcher_obj, part_data.Get <float>("mass")) { missile_source = part_data.Get <DSPrefab>("missile source"), missile_mass = part_data.Get <float>("missile mass"), Positions = specific_data.Get("positions", part_data.Get <Vector3[]>("positions"), quiet: true), orientation = part_data.Get <Quaternion>("orientation"), acceleration = part_data.Get <float>("acceleration"), flight_duration = part_data.Get <float>("duration"), description_ds = part_data, }; launcher_instance.HP = specific_data.Get("hp", launcher_instance.InitHP, quiet: true); launcher_instance.main_component = specific_data.Get("main component", true, quiet: true); BulletCollisionDetection launcher_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(launcher_obj); launcher_behaviour.Part = launcher_instance; launcher_instance.Spawn(); return(launcher_instance); }
public static AmmoBox GetFromDS(DataStructure part_data, DataStructure specific_data, Transform parent) { GameObject box_obj = Object.Instantiate(part_data.Get <GameObject>("source")); box_obj.transform.position = parent.position + parent.rotation * specific_data.Get <Vector3>("position"); box_obj.transform.rotation = parent.rotation * specific_data.Get <Quaternion>("rotation"); box_obj.transform.SetParent(parent, true); if (!Globals.ammunition_insts.ContainsKey(part_data.Get <string>("ammotype"))) { throw new System.Exception(string.Format("No such ammo: {0}", part_data.Get <string>("ammotype"))); } AmmoBox box_instance = new AmmoBox((float)part_data.Get <ushort>("hp"), box_obj, part_data.Get <float>("mass")) { AmmoType = Globals.ammunition_insts[part_data.Get <string>("ammotype")], Ammunition = part_data.Get <System.UInt16>("ammo"), description_ds = part_data, }; box_instance.HP = specific_data.Get("hp", box_instance.InitHP, quiet: true); box_instance.main_component = specific_data.Get("main component", true, quiet: true); box_instance.Ammunition = (uint)specific_data.Get("ammo", (int)box_instance.FullAmmunition, quiet: true); BulletCollisionDetection box_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(box_obj); box_behaviour.Part = box_instance; return(box_instance); }
public static Engine GetFromDS(DataStructure part_data, DataStructure specific_data, Transform parent) { GameObject engine_obj = Object.Instantiate(part_data.Get <GameObject>("source")); engine_obj.transform.position = parent.position + parent.rotation * specific_data.Get <Vector3>("position"); engine_obj.transform.rotation = parent.rotation * specific_data.Get <Quaternion>("rotation"); engine_obj.transform.SetParent(parent, true); float hp = (float)part_data.Get <ushort>("hp"); Engine engine_instance = new Engine(hp, engine_obj, part_data.Get <float>("mass"), part_data.Get <float>("thrust")) { SpecificImpulse = part_data.Get <float>("isp"), description_ds = part_data, }; engine_instance.HP = specific_data.Get("hp", engine_instance.InitHP, quiet: true); engine_instance.main_component = specific_data.Get("main component", true, quiet: true); engine_instance.Throttle = specific_data.Get("throttle", 0, quiet: true); BulletCollisionDetection engine_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(engine_obj); engine_behaviour.Part = engine_instance; return(engine_instance); }
public static FuelTank GetFromDS(DataStructure part_data, DataStructure specific_data, Transform parent) { GameObject tank_obj = Object.Instantiate(part_data.Get <GameObject>("source")); tank_obj.transform.position = parent.position + parent.rotation * specific_data.Get <Vector3>("position"); tank_obj.transform.rotation = parent.rotation * specific_data.Get <Quaternion>("rotation"); tank_obj.transform.SetParent(parent, true); FuelTank tank_instance = new FuelTank((float)part_data.Get <ushort>("hp"), tank_obj, part_data.Get <float>("mass")) { isrcs = part_data.Get <bool>("rcs"), ismain = part_data.Get <bool>("main"), TotFuel = part_data.Get <float>("fuel"), description_ds = part_data, }; tank_instance.Fuel = specific_data.Get("fuel amount", tank_instance.TotFuel, quiet: true); tank_instance.HP = specific_data.Get("hp", tank_instance.InitHP, quiet: true); tank_instance.main_component = specific_data.Get("main", true, quiet: true); BulletCollisionDetection tank_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(tank_obj); tank_behaviour.Part = tank_instance; return(tank_instance); }
public void UpdateVolumes() { DataStructure volumes = Globals.settings.GetChild("sound volume"); TotalVolume = volumes.Get <float>("total"); UIVolume = volumes.Get <float>("UIsound"); SpaceCraftVolume = volumes.Get <float>("spacecraft"); }
public void ChangeControl(Ship new_control) { player = new_control; DataStructure player_data = DataStructure.Load(new_control.config_path, "data", null).GetChild("player"); try { init_dpos = player_data.Get <Vector3 []>("cam pos") [0]; init_relrot = player_data.Get <Quaternion []>("cam rot") [0]; } catch { } transform.SetParent(new_control.Transform); }
/// <summary> /// Processes &101 and saves it to &x101 (always float) /// </summary> /// <param name="data"> incoming data </param> /// <returns> Compiled code </returns> public static ulong[] Process(DataStructure data) { ulong[] code = new ulong[0]; string type = data.Get <string>("type"); switch (type) { case "power": /* * ushort exponent = (ushort) data.Get<int>("value"); * code = new ulong [] { * 0x0100000001020000, * 0x3104010200010102, * 0x320a010100000101, * 0x1204010200000001, * //0x0200000000000000, * }; * code [0] += (ulong) exponent << 32; * code [2] += (ulong) exponent << 16; */ break; default: break; } return(code); }
public SelectorData(string p_path) { DataStructure data = DataStructure.Load(p_path); DataStructure sprite_sources = data.GetChild("SpriteSources"); string[] sprite_names = sprite_sources.Get <string []>("names"); Texture2D[] sprite_textures = sprite_sources.Get <Texture2D []>("images"); sprite_dict.Add("NULL", default_sprite); for (int i = 0; i < sprite_names.Length | i < sprite_textures.Length; i++) { sprite_dict.Add(sprite_names [i], Sprite.Create(sprite_textures [i], new Rect(0, 0, 30, 30), new Vector2(15, 15))); } DataStructure icons_ds = data.GetChild("Icons"); main_icon = ReadSpriteArray(icons_ds.Get <string []>("main")); reference_icons = ReadSpriteArray(icons_ds.Get <string []>("reference")); target_icons = ReadSpriteArray(icons_ds.Get <string []>("target")); info_icons = ReadSpriteArray(icons_ds.Get <string []>("info")); command_icons = ReadSpriteArray(icons_ds.Get <string []>("command")); DataStructure labels_ds = data.GetChild("Labels"); main_options = labels_ds.Get <string []>("main"); reference_options = labels_ds.Get <string []>("reference"); target_options = labels_ds.Get <string []>("target"); info_options = labels_ds.Get <string []>("info"); command_options = labels_ds.Get <string []>("command"); DataStructure flag_ds = data.GetChild("Flags"); main_flags = flag_ds.Get <int []>("main"); reference_flags = flag_ds.Get <int []>("reference"); target_flags = flag_ds.Get <int []>("target"); info_flags = flag_ds.Get <int []>("info"); command_flags = flag_ds.Get <int []>("command"); DataStructure function_ds = data.GetChild("FunctionPointers"); reference_function_pointers = function_ds.Get <int []>("reference"); target_function_pointers = function_ds.Get <int []>("target"); info_function_pointers = function_ds.Get <int []>("info"); command_function_pointers = function_ds.Get <int []>("command"); }
private void UpdateSettings() { DataStructure volumes = settings.GetChild("sound volume"); total_vol.value = volumes.Get <float>("total"); music_vol.value = volumes.Get <float>("music"); UI_vol.value = volumes.Get <float>("UIsound"); spacecraft_vol.value = volumes.Get <float>("spacecraft"); DataStructure graphics = settings.GetChild("graphics"); fullscreen.On = graphics.Get <bool>("fullscreen"); curr_quality = graphics.Get <ushort>("graphics"); for (int i = 0; i < quality.Length; i++) { quality [i].TriggerQuiet(i == curr_quality); } }
/// <summary> Spawn selected ship </summary> public void Spawn() { DataStructure ship_data = ships_data[spawn_selector.value]; GameObject instance = Instantiate(ship_data.Get <GameObject>("chassis")); Loader.EnsureComponent <Movable>(instance).correspondence = new EDShip(ship_data.Name, Vector3.zero, Vector3.zero) { }; }
public void ChapterUpdate() { if (Globals.planet_information.ContainsChild(name)) { DataStructure celestial_ds = Globals.planet_information.GetChild(name); data = new CelestialData( name, celestial_ds.Get <float>("mass"), celestial_ds.Get("radius", transform.lossyScale.x, quiet: true), celestial_ds.Get <string>("description"), CampagneManager.battle_data.ContainsKey(name) ? CampagneManager.battle_data[name] : null ); } else { data = CelestialData.None; } }
/// <param name="source"> /// The dialog datastructure which should /// be the source of the actual dialog /// </param> /// <param name="os"> /// The operating system on which this should be running. /// (Just used to get the console) /// </param> public Conversation(DataStructure source, ConsoleBehaviour p_console) { console = p_console; if (console != null) { console.current_conversation = this; } messages = InterpretDS(source); CurrentState = source.Get <ushort>("begin", 1, quiet: true); }
/// <summary> /// Compares the value of &x101 according to the data and saves 0x0000 (false) /// or 0x0001 (true) in &x100 /// </summary> /// <param name="data"> incoming data </param> /// <returns> Compiled code </returns> public static ulong[] ReturnBool(DataStructure data) { ulong[] code = new ulong[0]; string type = data.Get <string>("type"); switch (type) { case "threshhold up": ushort threshhold = NMS.RAM.Float2Short(data.Get <float>("value")); code = new ulong [] { 0x120a000001010002, 0x0100000101000000, //0x0200000000000000, }; code [0] += (ulong)threshhold << 32; break; case "threshhold down": ushort threshhold01 = NMS.RAM.Float2Short(data.Get <float>("value")); code = new ulong [] { 0x120c010100000002, 0x0100000101000000, //0x0200000000000000, }; code [0] += (ulong)threshhold01 << 16; break; case "random probability": code = new ulong [] { 0x120e002001010002, 0x0100000101000000, //0x0200000000000000, }; break; default: break; } return(code); }
/// <summary> Sets current ship as player </summary> public void SetAsPlayer() { gameObject.tag = "Player"; FileReader.FileLog("Changed/Initialized Player", FileLogType.runntime); var new_control = Loader.EnsureComponent <PlayerControl> (gameObject); SceneGlobals.ReferenceSystem = new ReferenceSystem(myship); SceneGlobals.ReferenceSystem.Update(); if (GetComponent <HighLevelAI>() != null) { GetComponent <HighLevelAI>().enabled = true; } if (SceneGlobals.Player != null) { var old_control = SceneGlobals.Player.Object.GetComponent <PlayerControl>(); new_control.positions = old_control.positions; new_control.rotations = old_control.rotations; new_control.free_rotation = old_control.free_rotation; Destroy(old_control); GameObject player_obj = SceneGlobals.Player.Object; if (player_obj.GetComponent <HighLevelAI>() != null) { player_obj.GetComponent <HighLevelAI>().enabled = true; } if (player_obj.GetComponent <AudioSource>() != null) { player_obj.tag = "Untagged"; } } else { DataStructure data = DataStructure.Load(myship.config_path, "data", null).GetChild("player"); new_control.positions = data.Get <Vector3[]>("cam pos"); new_control.rotations = data.Get <Quaternion[]>("cam rot"); new_control.free_rotation = data.Get <bool[]>("free rotate"); } }
public static Armor GetFromDS(DataStructure data, Ship parent) { ArmorMesh.ArmorGeometryData armordata = new ArmorMesh.ArmorGeometryData( data.Get <Vector3[]>("key positions"), data.Get <float[]>("radii"), data.Get <float[]>("thickness"), data.Get("sides", 32, quiet: true) ); int[] texture_size = data.Get <int[]> ("texture size"); ArmorMesh armor_mesh = new ArmorMesh(armordata, new Vector2Int(texture_size[0], texture_size[1])); GameObject armor_obj = armor_mesh.armor_obj; armor_obj.transform.SetParent(parent.Transform, false); // Provisory armor_mesh.part = new Armor(1000, armor_obj, 10, armor_mesh); BulletCollisionDetection armor_mono = Loader.EnsureComponent <BulletCollisionDetection>(armor_obj); armor_mono.Part = armor_mesh.part; return(armor_mesh.part); }
public static Missile SpawnFlying(DataStructure data) { GameObject missile_obj = UnityEngine.Object.Instantiate(data.Get <GameObject>("source")); missile_obj.transform.position = data.Get <Vector3>("position"); missile_obj.transform.rotation = data.Get <Quaternion>("orientation"); Missile missile_instance = new Missile(missile_obj, data.Get <float>("flight duration"), data.Get("mass", .01), data.Get("id", -1)) { AimTarget = Target.None, EngineAcceleration = data.Get <float>("acceleration"), Head = (Warhead)data.Get <ushort>("warhead"), Velocity = data.Get <Vector3>("velocity"), AngularVelocity = data.Get <Vector3>("angular velocity"), source = data.Get <DSPrefab>("source") }; missile_instance.Released = true; return(missile_instance); }
public static DestroyableTarget Load(DataStructure data) { DSPrefab source = data.Get <DSPrefab>("pref"); GameObject obj = Object.Instantiate(source.obj, data.Get <Vector3>("position"), data.Get <Quaternion>("orientation")); Target tgt = new Target(obj, 0, has_no_ship: true, id: data.Get <int>("id")); DestroyableTarget res = new DestroyableTarget(data.Get("hp", 1f), tgt, source); res.Velocity = data.Get <Vector3>("velocity"); res.AngularVelocity = data.Get <Vector3>("angular velocity"); return(res); }
private void LoadSounds() { DataStructure sfx_ds = DataStructure.Load(sound_path); DataStructure ui_ds = sfx_ds.GetChild("UI"); DataStructure weapons_ds = sfx_ds.GetChild("Weapons"); DataStructure computer_ds = sfx_ds.GetChild("Computer"); string ui_path = ui_ds.Get <string>("dir"); foreach (KeyValuePair <string, string> pair in ui_ds.strings) { if (pair.Key != "dir") { LoadingStuff++; StartCoroutine(LoadSoundCoroutine(string.Format("GameData/Audio/{0}/{1}", ui_path, pair.Value), pair.Key, SFXType.ui)); } } string weapon_path = weapons_ds.Get <string>("dir"); foreach (KeyValuePair <string, string> pair in weapons_ds.strings) { if (pair.Key != "dir") { LoadingStuff++; StartCoroutine(LoadSoundCoroutine(string.Format("GameData/Audio/{0}/{1}", weapon_path, pair.Value), pair.Key, SFXType.weapon)); } } string computer_path = computer_ds.Get <string>("dir"); foreach (KeyValuePair <string, string> pair in computer_ds.strings) { if (pair.Key != "dir") { LoadingStuff++; StartCoroutine(LoadSoundCoroutine(string.Format("GameData/Audio/{0}/{1}", computer_path, pair.Value), pair.Key, SFXType.computer)); } } StartCoroutine(LoadSoundCoroutine("default_sound.wav", "default", SFXType.default_)); LoadingStuff++; }
public static Weapon GetFromDS(DataStructure part_data, DataStructure specific_data, Transform parent) { GameObject weapon_obj = part_data.Get <GameObject>("source"); Vector3 position = specific_data.Get <Vector3>("position"); Quaternion rotation = specific_data.Get <Quaternion>("rotation"); GameObject act_weapon_obj = Object.Instantiate(weapon_obj); act_weapon_obj.transform.position = parent.position + parent.rotation * position; act_weapon_obj.transform.rotation = parent.rotation * rotation; act_weapon_obj.transform.SetParent(parent, true); Weapon weapon_instance = new Weapon((float)part_data.Get <ushort>("hp"), act_weapon_obj, part_data.Get <float>("mass")) { empty_hull = part_data.Get <GameObject>("hullpref"), BulletSpeed = part_data.Get <float>("bulletspeed"), HullSpeed = part_data.Get <float>("hullspeed"), ShootPos = part_data.Get <Vector3>("bulletpos"), EjectPos = part_data.Get <Vector3>("hullpos"), ReloadSpeed = part_data.Get <float>("reloadspeed"), description_ds = part_data, }; weapon_instance.HP = specific_data.Get("hp", weapon_instance.InitHP, quiet: true); weapon_instance.main_component = specific_data.Get("main component", true, quiet: true); weapon_instance.heat = specific_data.Get("heat", 0f, quiet: true); weapon_instance.ooo_time = specific_data.Get("ooo time", 0f, quiet: true); weapon_instance.reload_timer = specific_data.Get("reload timer", 0f, quiet: true); weapon_instance.shooting = specific_data.Get("shooting", false, quiet: true); BulletCollisionDetection weapon_behaviour = Loader.EnsureComponent <BulletCollisionDetection>(act_weapon_obj); weapon_behaviour.Part = weapon_instance; return(weapon_instance); }
/// <summary> Loads a battle </summary> public void LoadBattle(string battle_name) { TerminateScene(); if (!Globals.battle_list.ContainsChild(battle_name)) { return; } DataStructure battle_inforamtion = Globals.battle_list.GetChild(battle_name); string battle_file = battle_inforamtion.Get <string>("path"); DataStructure battle_data = DataStructure.Load(battle_file, "battle_data", is_general: true); if (battle_data == null) { DeveloppmentTools.Log(battle_file + " does not exist"); } SceneGlobals.is_save = false; SceneManager.LoadScene(sceneName: "battlefield"); loader = new Loader(battle_data) { path = battle_file }; }
/// <summary> /// Executes an event in the level once /// </summary> /// <param name="data"> The Datastructure containing the information about the event </param> private void StoryCommand(DataStructure data) { switch (data.Name) { case "get conversation": FileReader.FileLog("Begin Conversation", FileLogType.story); ushort id = data.Get <ushort>("ID"); new Conversation(conversations [id - 1], console) { Running = true }; console.ConsolePos = ConsolePosition.shown; break; case "spawn": string[] types = data.Get <string[]>("types"); string[] names = data.Get <string[]>("names"); if (types.Length != names.Length) { DeveloppmentTools.Log("length of \"types\" array must be the same as length of \"names\" array"); } for (int i = 0; i < types.Length; i++) { loader.Spawn(types[i], names[i]); } NextCommand(); break; case "objective": // Todo: Check compleateness Objectives obj_type; Target [] obj_targets; string [] objective_specs = data.Get <string>("objective type").Split(' '); // What to do with the target? switch (objective_specs [0]) { case "kill": obj_type = Objectives.destroy; break; case "escort": obj_type = Objectives.escort; break; case "hack": obj_type = Objectives.hack; break; default: obj_type = Objectives.none; break; } string obj_name = data.Get <string>("target name"); // Which target is it? switch (objective_specs [1]) { case "squadron": if (!squads.ContainsKey(obj_name)) { DeveloppmentTools.Log("LOADER - no such sqadron in the scene" + obj_name); } obj_targets = System.Array.ConvertAll(squads [obj_name], s => s.Associated); break; case "target": if (!single_targets.ContainsKey(obj_name)) { DeveloppmentTools.Log("LOADER - no such target in the scene: " + obj_name); } Target selected_target = single_targets[obj_name].Associated; obj_targets = new Target [1] { selected_target }; break; default: obj_targets = new Target[0]; break; } Objective objective = new Objective() { objective_type = obj_type, targets = obj_targets }; tracker.NewObjective(objective); return; case "goto": FileReader.FileLog("Go to story num " + data.Get <ushort>("stage").ToString(), FileLogType.story); in_level_progress = (short)(data.Get <ushort>("stage")); in_stage_progress = -1; NextCommand(); return; case "finish mission": bool won = data.Get <bool>("won"); SceneGlobals.general.EndBattle(won); return; } }
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); }