Пример #1
0
    /// <summary> Saves the character as a text-file </summary>
    /// <example> <c>
    ///		Characte Ivan = new Character(ivan_ds, "characters/ivan");
    ///		Ivan.level++;
    ///		Ivan.Save();
    /// </c> </example>
    public void Save()
    {
        DataStructure polit = datastr.GetChild("political");

        polit.Set("cap", politics[0]);
        polit.Set("auth", politics[1]);
        polit.Set("nat", politics[2]);
        polit.Set("trad", politics[3]);

        DataStructure skilldata = datastr.GetChild("skills");

        skilldata.Set("pilot", skills [Skills.pilot]);
        skilldata.Set("computer", skills [Skills.computer]);
        skilldata.Set("engineering", skills [Skills.engineering]);
        skilldata.Set("trade", skills [Skills.trade]);
        skilldata.Set("diplomacy", skills [Skills.diplomacy]);

        DataStructure general = datastr.GetChild("stats");

        general.Set("forename", forename);
        general.Set("aftername", aftername);

        DataStructure progress = datastr.GetChild("progress");

        progress.Set("level", story_stage);
        progress.Set("chapter", chapter);

        datastr.Save(file_name, true);
    }
Пример #2
0
    /// <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");
    }
Пример #3
0
    /// <param name="pdata"> The datastruncture of the file, where the keybindings are saved </param>
    public KeyBindingCollection(string datapath)
    {
        path = datapath;
        DataStructure data = DataStructure.Load(datapath, "keybindings");

        keydata  = data.GetChild("keys");
        general  = keydata.GetChild("general");
        map      = keydata.GetChild("map");
        movement = keydata.GetChild("movement");
        engine   = keydata.GetChild("engine");
        Load();
    }
Пример #4
0
    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");
    }
Пример #5
0
    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);
        }
    }
Пример #6
0
    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++;
    }
Пример #7
0
    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;
    }
Пример #8
0
    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;
    }