Пример #1
0
    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);
    }
Пример #2
0
 public Vector3 GetTgtDir(Turret t)
 {
     if (follow_target)
     {
         // Aimed at moving target
         if (target.Exists)
         {
             // Ship Part
             if (target is ShipPart)
             {
                 ShipPart part = target as ShipPart;
                 return(own_ship.control_script.Predicted(t, part.Position, part.ParentShip.Velocity) - t.MidPos);
             }
             // Ship Part Offset
             else if (target is PartOffsetAim)
             {
                 PartOffsetAim aim = (PartOffsetAim)target;
                 return(own_ship.control_script.Predicted(t, aim.Position, aim.ParentPart.ParentShip.Velocity) - t.MidPos);
             }
             // Ship
             else if (target is Ship)
             {
                 Ship shp = target as Ship;
                 return(own_ship.control_script.Predicted(t, shp.Position, shp.Velocity) - t.MidPos);
             }
             // Destroyable Target
             else if (target is DestroyableTarget)
             {
                 DestroyableTarget tgt = target as DestroyableTarget;
                 return(own_ship.control_script.Predicted(t, tgt.Position, tgt.Velocity) - t.MidPos);
             }
             // PhysicsOffsetAim
             else if (target is PhysicsOffsetAim)
             {
                 PhysicsOffsetAim aim = (PhysicsOffsetAim)target;
                 return(own_ship.control_script.Predicted(t, aim.Position, aim.ParentPhysicsObject.Velocity) - t.MidPos);
             }
             return(target.Position - t.MidPos);
         }
         else
         {
             return(DefaultTgtPosition);
         }
     }
     if (direction)
     {
         return(target_dir);
     }
     return(target_pos - Position);
 }
Пример #3
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;
    }
Пример #4
0
    private void Update()
    {
        transform.position = Input.mousePosition + offset;
        if (Shown)
        {
            Ray        screenray = SceneGlobals.map_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit currenthit;
            if (Physics.Raycast(screenray, out currenthit))
            {
                IAimable aimable = GetAimable(currenthit.transform);
                ShipPart part    = (ShipPart)aimable;
                if (part != null)
                {
                    // If target is part
                    Object    = new PartOffsetAim(currenthit.point, part);
                    text.text = part.Name();
                }
                else
                {
                    DestroyableTarget dest_tgt = (DestroyableTarget)aimable;
                    if (dest_tgt != null)
                    {
                        // If target is destroyable target
                        Object    = new PhysicsOffsetAim(currenthit.point, dest_tgt);
                        text.text = part.Name();
                    }
                    else
                    {
                        // void
                        text.text = currenthit.transform.name;
                    }
                }
            }
            else
            {
                Object = null;
                foreach (MapTgtMarker marker in MapTgtMarker.marker_list)
                {
                    if (marker.RectTransform.rect.Contains((Vector2)Input.mousePosition - marker.Position))
                    {
                        // If target is ship
                        Object    = marker.LinkedObject;
                        text.text = marker.LinkedObject.Name;
                        //Debug.DrawLine(Vector3.zero, Object.Position, Color.red, 100);
                    }
                }
                if (Object == null)
                {
                    // If no object selected
                    text.text = "";
                }
            }

            // Mousebutton unleashed
            if (!Input.GetMouseButton(0) && Dragging)
            {
                Dragging = false;
                switch (Context)
                {
                default:
                case PinContext.turret:
                    break;

                case PinContext.selector:
                    MapCore.Active.selector_event_system.DraggedTo(Object);
                    break;
                }
                Context = PinContext.none;
            }
        }
    }
Пример #5
0
    public static void Save()
    {
        GeneralExecution general = SceneGlobals.general;

        System.DateTime t0 = System.DateTime.Now;
        DataStructure   save_datastructure = new DataStructure();

        DataStructure general_information = new DataStructure("GeneralInformation", save_datastructure);

        general_information.Set("original_path", general.battle_path);
        general_information.Set("in level progress", (int)general.mission_core.in_level_progress);
        general_information.Set("in stage progress", (int)general.mission_core.in_stage_progress);

        ReferenceSystem ref_sys = SceneGlobals.ReferenceSystem;

        if (ref_sys.HasParent)
        {
            general_information.Set("RS offset", ref_sys.Offset);
            general_information.Set("RS parent", ref_sys.ref_obj.ID);
        }
        else
        {
            general_information.Set("RS position", ref_sys.Position);
        }

        SceneObject[]       scene_array     = new SceneObject[SceneObject.TotObjectList.Count];
        Explosion[]         explosion_array = new Explosion[SceneGlobals.explosion_collection.Count];
        Bullet[]            bullet_array    = new Bullet[SceneGlobals.bullet_collection.Count];
        DestroyableTarget[] target_array    = new DestroyableTarget[SceneGlobals.destroyables.Count];

        SceneObject.TotObjectList.Values.CopyTo(scene_array, 0);
        SceneGlobals.bullet_collection.CopyTo(bullet_array);
        SceneGlobals.destroyables.CopyTo(target_array);

        scene_array = System.Array.FindAll(scene_array,
                                           x =>
                                           !(x is Missile && !(x as Missile).Released) &&
                                           !(x is Network && (x as Network).Name == "\"friendly rogue\"-Network" | (x as Network).Name == "\"hostile rogue\"-Network") &&
                                           !(x is Target)
                                           );

        ISavable[] savable_objects = new ISavable[scene_array.Length +
                                                  explosion_array.Length +
                                                  bullet_array.Length +
                                                  target_array.Length];

        int indx = 0;

        System.Array.ConvertAll(scene_array, x => x as ISavable).CopyTo(savable_objects, indx);
        indx += scene_array.Length;
        System.Array.ConvertAll(explosion_array, x => x as ISavable).CopyTo(savable_objects, indx);
        indx += explosion_array.Length;
        System.Array.ConvertAll(bullet_array, x => x as ISavable).CopyTo(savable_objects, indx);
        indx += bullet_array.Length;
        System.Array.ConvertAll(target_array, x => x as ISavable).CopyTo(savable_objects, indx);

        DataStructure object_states = new DataStructure("ObjectStates", save_datastructure);

        foreach (ISavable obj in savable_objects)
        {
            if (obj != null)
            {
                DataStructure ds = new DataStructure(obj.Name, object_states);
                obj.Save(ds);
            }
        }

        //save_datastructure.Save("saved/Saves/" + System.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss"));
        save_datastructure.Save("saved/Saves/def_save");
        DeveloppmentTools.LogFormat("Saved: {0} ms", (System.DateTime.Now - t0).Milliseconds.ToString());
    }