コード例 #1
0
    /// <summary> should be called, if mouse enter/exits over a button referring to a turret </summary>
    /// <param name="button_id"> The ID of the concerned button </param>
    /// <param name="enter"> True, if mouse enters the button; False, if it exits it</param>
    public void TurretButtonHover(uint button_id, bool enter)
    {
        if (enter)
        {
            float plus_value = scroll_bar.value * ((Screen.height - 250) / handle_size_ratio[0] - (Screen.height - 250));
            turret_menu.rectTransform.position = new Vector3(Screen.width - 170, Screen.height - 100 - button_id * 50 + plus_value);
            selected_turret = new List <Turret>(TurretGraphs.Values) [(int)button_id];

            int group_number = 0;
            List <Dropdown.OptionData> opts = new List <Dropdown.OptionData>();
            for (int i = 0; i < player_script.turretgroup_list.Count; i++)
            {
                TurretGroup tg = player_script.turretgroup_list[i];
                opts.Add(new Dropdown.OptionData(tg.name));
                if (selected_turret.Group == tg)
                {
                    group_number = i;
                }
            }

            Dropdown group_select = turret_menu.GetComponentInChildren <Dropdown>();
            group_select.options = opts;
            group_select.value   = group_number;

            turret_selected = true;
        }
        else
        {
            turret_selected      = false;
            HighlightingPosition = new Vector3(-200, -200);
        }
    }
コード例 #2
0
 public static AIActionCommand ShootTG(TurretGroup group, IAimable target)
 {
     return(new AIActionCommand(CommandType.shoot_tgs)
     {
         target = target
     });
 }
コード例 #3
0
    private void ShipStatsUpdate()
    {
        // Writes information in the bottem_left corner
        float relative_vel = SceneGlobals.ReferenceSystem.RelativeVelocity(PlayerShip.Velocity).magnitude;

        texts["velocity_indicator"].text         = (Mathf.Round(relative_vel * 100f) / 100f).ToString() + " m/s";
        texts["angular_momentum_indicator"].text = (Mathf.Round(PlayerShip.AngularVelocity.magnitude * Mathf.Deg2Rad * 100f) / 100f).ToString() + " rad/s";

        // Points to one turret
        if (turret_selected)
        {
            HighlightingPosition = MainCam.WorldToScreenPoint(selected_turret.Position);
        }

        if (HighlightingPosition == Vector3.zero)
        {
            pointers ["turret_position"].transform.position = new Vector3(-200, -200, 0);
        }
        else
        {
            Vector3 screen_pos = HighlightingPosition;
            screen_pos.z = 0f;
            pointers ["turret_position"].transform.position = HighlightingPosition;
            pointers ["turret_position"].transform.Rotate(0, 0, Time.deltaTime * 90);
        }

        // Updates stuff
        SliderUpdate();
        TurretSliderUpdate();

        if (Input.mouseScrollDelta.y > 0 && (selected_turret != null || selected_group != null))
        {
            // up
            scroll_bar.value -= .05f;
        }
        if (Input.mouseScrollDelta.y < 0 && (selected_turret != null || selected_group != null))
        {
            // down
            scroll_bar.value += .05f;
        }

        mouse_on_menu = !GroupSwitch?turret_menu.rectTransform.rect.Contains(Input.mousePosition - turret_menu.rectTransform.position) :
                            group_menu.rectTransform.rect.Contains(Input.mousePosition - group_menu.rectTransform.position);

        if (!mouse_on_menu && !turret_selected)
        {
            turret_menu.rectTransform.position = new Vector3(-200, -200, 0);
            selected_turret = null;
        }
        if (!mouse_on_menu && !group_selected)
        {
            group_menu.rectTransform.position = new Vector3(-100, -200, 0);
            selected_group = null;
        }
    }
コード例 #4
0
    /// <summary> Aims one specific turretgroup at a given position </summary>
    /// <param name="group"> The turretgroup to aim </param>
    /// <param name="tgtpos"> The target position in world space </param>
    public void AimOneTurretGroup(TurretGroup group, Vector3 tgtpos)
    {
        if (group.Count > 0)
        {
            group.ShootSafe();

            group.follow_target = false;
            group.direction     = false;
            Vector3 tgt_dir = tgtpos;
            group.target_pos = tgt_dir;
        }
    }
コード例 #5
0
 public void TurretGroupAimCursor()
 {
     if (selected_group == null)
     {
         return;
     }
     selected_group.follow_target = false;
     selected_group.direction     = true;
     group_follows_cursor         = !group_follows_cursor;
     selected_group.SetTgtDir(direction);
     selected_group.direction = true;
     current_group            = selected_group;
 }
コード例 #6
0
ファイル: TurretButton.cs プロジェクト: bionick7/4040Machines
    /// <summary>
    ///		Like an initializer
    /// </summary>
    /// <param name="ui"> GUI_sript, thid belongs to </param>
    /// <param name="num"> ID number of the button </param>
    /// <param name="turret"> The turretgroup, the button is referring to </param>
    public void Initiate(GUIScript ui, uint num, TurretGroup group)
    {
        script        = ui;
        number        = num;
        single_turret = false;
        in_add_menu   = false;

        gameObject.name = group.name;

        img = GetComponent <Image>();
        own_rect_transform = GetComponent <RectTransform>();
        reload_indicator   = transform.GetChild(2).GetComponent <RectTransform>();
        OwnTurretGroup     = group;

        SetUp();
    }
コード例 #7
0
 /// <summary> Calls the turretgroup menu group </summary>
 /// <param name="is_edit"> True if the turretgroup should just be edited </param>
 public void CallGroupMenu(bool is_edit)
 {
     if (is_edit && selected_group == null)
     {
         return;
     }
     add_group_menu.Edit = is_edit;
     if (is_edit)
     {
         add_group_menu.group = selected_group;
         current_group        = selected_group;
     }
     else
     {
         add_group_menu.preselected_turrets = selected_turrets;
     }
     add_group_menu.Enabled = true;
 }
コード例 #8
0
    /// <summary> Initializer </summary>
    /// <param name="ranges">
    ///		rotating limitations of the turret, first min,
    ///		the max, first horizontal, then vertical, no limitation is written
    ///		as -1
    /// </param>
    /// <param name="obj"> UnityEngine.GameObject, that representates the turret </param>
    /// <param name="turning_rates">
    ///		how fast to turs in °/s horiontal first, then vertical
    ///	</param>
    public Turret(float [] ranges, GameObject obj, float [] turning_rates, float mass, float init_hp = 10f) : base(init_hp, obj, mass)
    {
        min_range_horizontal = ranges [0];
        max_range_horizontal = ranges [1];
        min_range_vertical   = ranges [2];
        max_range_vertical   = ranges [3];

        group = TurretGroup.Trashbin;

        sockel  = Transform.GetChild(0);
        body    = sockel.GetChild(0);
        barrels = body.GetChild(0);

        horizontal_rotating_rate = turning_rates [0];
        vertical_rotating_rate   = turning_rates [1];

        compens_rot = Quaternion.Inverse(body.rotation * Quaternion.Inverse(sockel.rotation)) * Quaternion.Euler(0, 90, 90);
        Enabled     = true;

        anim = obj.GetComponent <Animator>();
    }
コード例 #9
0
ファイル: AddGroupMenu.cs プロジェクト: bionick7/4040Machines
 public void Finish()
 {
     if (Edit)
     {
         for (int i = 0; i < group.Count; i++)
         {
             group.TurretArray[i].Group = TurretGroup.Trashbin;
         }
         foreach (Turret turr in selected_turrets)
         {
             turr.Group = group;
         }
         group.name = name_input.text;
     }
     else
     {
         group = new TurretGroup(Target.None, selected_turrets.ToArray(), name_input.text)
         {
             own_ship = SceneGlobals.Player
         };
         gui_script.AddTurretGroup(group);
     }
     Enabled = false;
 }
コード例 #10
0
    /// <summary>
    ///		This should be called, if a turretgroup should be added.
    /// </summary>
    public void AddTurretGroup(TurretGroup tg)
    {
        // Adds the group to the playerobjects main script
        player_script.turretgroup_list.Add(tg);

        int groups_num = player_script.turretgroup_list.Count;

        // Adds new buttons
        GameObject obj = Instantiate(GameObject.Find("turr_slide"));

        obj.transform.SetParent(main_canvas);
        obj.transform.position = new Vector3(Screen.width + 50, Screen.height - 75 - (groups_num * 50));
        obj.transform.SetAsFirstSibling();
        Text txt = obj.transform.GetChild(0).GetComponent <Text>();

        txt.text = tg.name;
        TurretButton button = obj.GetComponent <TurretButton>();

        TurretGroupGraphs.Add(button, tg);

        obj.GetComponent <TurretButton>().Initiate(this, (uint)groups_num - 1u, tg);

        handle_size_ratio [1] = Mathf.Min(1, ((float)Screen.height - 250f) / (50f * (float)groups_num));
    }
コード例 #11
0
    /// <summary> should be called, if mouse enter/exits over a button referring to a turretgroup </summary>
    /// <param name="button_id"> The ID of the concerned button </param>
    /// <param name="enter"> True, if mouse enters the button; False, if it exits it</param>
    public void GroupButtonHover(uint button_id, bool enter)
    {
        if (enter)
        {
            TurretGroup  concerned_group  = player_script.turretgroup_list [(int)button_id];
            TurretButton concerned_button = null;
            foreach (KeyValuePair <TurretButton, TurretGroup> pair in TurretGroupGraphs)
            {
                if (pair.Value == concerned_group)
                {
                    concerned_button = pair.Key;
                }
            }
            if (concerned_button == null)
            {
                throw new System.ArgumentException("Turretgroup ID does not exist");
            }
            uint button_number = 0;
            foreach (TurretButton bt in TurretGroupGraphs.Keys)
            {
                if (bt.transform.position.y > concerned_button.transform.position.y)
                {
                    button_number++;
                }
            }

            float plus_value = scroll_bar.value * ((Screen.height - 250) / handle_size_ratio[1] - (Screen.height - 250));
            group_menu.rectTransform.position = new Vector3(Screen.width - 170, Screen.height - 150 - button_number * 50 + plus_value);
            selected_group = player_script.turretgroup_list [(int)button_id];
            group_selected = true;
        }
        if (!enter)
        {
            group_selected = false;
        }
    }
コード例 #12
0
 /// <summary> Fires off one turretgroup </summary>
 /// <param name="group"> The concerned group </param>
 /// <param name="safe"> If the group shoul check, if it is aimed right </param>
 public void ShootOneTurretGroup(TurretGroup group, bool safe = true)
 {
     group.ShootSafe();
 }
コード例 #13
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;
    }
コード例 #14
0
    public void ResetPlayer(Ship p_player)
    {
        PlayerShip = p_player;

        // Initialize player related stuff
        GameObject player = PlayerShip.Object;

        player_script    = player.GetComponent <ShipControl>();
        player_transform = player.transform;

        // Reset Collections
        weapon_states.Clear();
        turret_states.Clear();

        foreach (Weapon w in PlayerShip.Parts.GetAll <Weapon>())
        {
            GameObject obj = Instantiate(GameObject.Find("tgt_point")) as GameObject;
            obj.transform.SetParent(ship_canvas);
            Image img = obj.GetComponent <Image>();
            weapon_states.Add(w, img);
        }

        foreach (Turret t in PlayerShip.Parts.GetAll <Turret>())
        {
            GameObject obj = Instantiate(GameObject.Find("tgt_point")) as GameObject;
            obj.transform.SetParent(ship_canvas);
            Image img = obj.GetComponent <Image>();
            turret_states.Add(t, img);
        }


        // Fill turret_graphs and initialize the buttons' scripts
        // -------------------------------------------------------

        TurretGraphs      = new Dictionary <TurretButton, Turret>();
        TurretGroupGraphs = new Dictionary <TurretButton, TurretGroup>();

        GameObject turr_img_instance = GameObject.Find("turr_slide");
        uint       i = 0;

        foreach (Turret [] turrs in player_script.turrets.Values)
        {
            foreach (Turret turr in turrs)
            {
                GameObject obj = Instantiate(turr_img_instance);
                obj.transform.SetParent(SceneGlobals.permanent_canvas.transform);
                obj.transform.position = new Vector3(Screen.width - 50, Screen.height - 75 - (i * 50));
                obj.transform.SetAsFirstSibling();

                TurretButton button = obj.GetComponent <TurretButton>();
                button.Initiate(this, i, turr);

                TurretGraphs.Add(button, turr);

                i++;
            }
        }

        handle_size_ratio[0] = Mathf.Min(1, ((float)Screen.height - 250f) / (50f * i));

        // Fill group_graphs and initialize the buttons' scripts
        //------------------------------------------------------

        for (int j = 0; j < player_script.turretgroup_list.Count; j++)
        {
            TurretGroup tg  = player_script.turretgroup_list[j];
            GameObject  obj = Instantiate(turr_img_instance);
            obj.transform.SetParent(SceneGlobals.permanent_canvas.transform);
            obj.transform.position = new Vector3(Screen.width + 50, Screen.height - 75 - (j * 50));
            obj.transform.SetAsFirstSibling();

            TurretButton button = obj.GetComponent <TurretButton>();
            button.Initiate(this, (uint)j, tg);

            TurretGroupGraphs.Add(button, tg);
        }

        handle_size_ratio [1] = Mathf.Min(1, ((float)Screen.height - 250f) / (50f * player_script.turretgroup_list.Count));

        ButtonLabelUpdate();
    }
コード例 #15
0
ファイル: LoadSaving.cs プロジェクト: bionick7/4040Machines
    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;
    }