Exemplo n.º 1
0
    public void SpawnSubSelector(SelectionClass pclass)
    {
        SelectorOptions options = new SelectorOptions(sub_options [(int)pclass], pclass);

        if (child != null)
        {
            try {
                Destroy(child.gameObject);
            } catch { }
        }
        sbyte      pos         = (sbyte)options.selection_class;
        GameObject selectorobj = Instantiate(GameObject.Find("map_subselector"));

        selectorobj.transform.SetParent(SceneGlobals.map_canvas.transform);

        SubSelector new_child = Loader.EnsureComponent <SubSelector>(selectorobj);

        new_child.targets = targets;
        new_child.options = options;
        new_child.InitSub();
        new_child.targets = targets;

        new_child.Position  = UpperLeft + new Vector2(width + new_child.width / 2, -new_child.head_height);
        new_child.draggable = false;
        new_child.transform.SetParent(transform, true);
        child = new_child;
    }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a instance of the selector with the desired options
        /// </summary>
        /// <param name="options"><see cref="SelectorOptions" /> flags for the selector</param>
        /// <param name="decimalPlaces">The maximum allowed decimal places in the items weights. All numbers after this decimal place will be ignored</param>
        public WeightedRandomSelector(
            SelectorOptions options = SelectorOptions.AllowDuplicates | SelectorOptions.IgnoreZeroWeight,
            int decimalPlaces       = 2)
        {
            _items   = new List <WeightedItem <T> >();
            _options = options;

            _cumulativeWeights     = null;
            _totalCumulativeWeight = 0;
            _cumulativeWeightsList = null;

            _integerFactor = (int)Math.Pow(10, decimalPlaces);

            _rng = new Random();

            _forceRecalculation = false;
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Creates a instance of the selector with an already made list of <see cref="WeightedItem{T}" /> and the desired
 ///     options
 ///     <seealso cref="SelectorOptions" />
 /// </summary>
 /// <param name="items">A list of <see cref="WeightedItem{T}" /></param>
 /// <param name="options"><see cref="SelectorOptions" /> flags for the selector</param>
 /// <param name="decimalPlaces">The maximum allowed decimal places in the items weights. All numbers after this decimal place will be ignored</param>
 public WeightedRandomSelector(List <WeightedItem <T> > items,
                               SelectorOptions options = SelectorOptions.AllowDuplicates | SelectorOptions.IgnoreZeroWeight,
                               int decimalPlaces       = 2) : this(options, decimalPlaces)
 {
     _items = items;
 }
 public AtawSelectorOptionCreator()
 {
     fSelectorOptions = new SelectorOptions();
     BaseOptions      = fSelectorOptions;
 }
Exemplo n.º 5
0
    public void SelectorClicked(SelectorButton button)
    {
        SubSelector concerned = button.parent as SubSelector;

        if (concerned == null)
        {
            return;
        }
        byte option = button.num;

        bool multiple = concerned.targets.Length > 1;

        for (int i = 0; i < concerned.targets.Length; i++)
        {
            // Check Flags
            if (i != 0 && (button.flags >> 1) % 2 == 0)
            {
                // single vessel only
                goto LOOPEND;
            }
            if (i == 0 && button.flags % 2 == 1)
            {
                // use pinlabel
                Debug.Log(DeveloppmentTools.LogIterable(concerned.targets));
                concerned_objects = concerned.targets;
                lasting_command   = button.function;
            }

            IMarkerParentObject parentObject = concerned.targets[i];
            var ship = parentObject as Ship;

            SelectorOptions options = concerned.options;

            switch (button.function)
            {
//  +-----------------------------------------------------------------------------------------------------------------------+
//	|									Reference																			|
//  +-----------------------------------------------------------------------------------------------------------------------+
            case 0x0c:
// Set Camera ---------------------------------------------------------------------------------------------------------------
                SceneGlobals.ReferenceSystem.Offset += parentObject.Position - SceneGlobals.ReferenceSystem.Position;
                goto LOOPEND;

            case 0x0d:
// Set Reference ------------------------------------------------------------------------------------------------------------
                SceneGlobals.map_core.CurrentSystem = new ReferenceSystem(parentObject.Position);
                goto LOOPEND;

            case 0x0e:
// Lock Reference -----------------------------------------------------------------------------------------------------------
                Vector3     offset    = Vector3.zero;
                SceneObject scene_obj = parentObject as SceneObject;
                if (parentObject is SceneObject)
                {
                    offset = SceneGlobals.ReferenceSystem.Position - scene_obj.Position;
                    SceneGlobals.ReferenceSystem = new ReferenceSystem(scene_obj);
                }
                else if (parentObject is ITargetable)
                {
                    offset = SceneGlobals.ReferenceSystem.Position - parentObject.Position;
                    Target tgt = (parentObject as ITargetable).Associated;
                    SceneGlobals.ReferenceSystem = new ReferenceSystem(tgt);
                }

                SceneGlobals.ReferenceSystem.Offset = offset;
                goto LOOPEND;

            case 0x0f:
// Lock & Set ---------------------------------------------------------------------------------------------------------------
                if (parentObject is SceneObject)
                {
                    SceneGlobals.ReferenceSystem = new ReferenceSystem(parentObject as SceneObject);
                }
                else if (parentObject is ITargetable)
                {
                    SceneGlobals.ReferenceSystem = new ReferenceSystem((parentObject as ITargetable).Associated);
                }
                goto LOOPEND;

            case 0x19:
// Match Velocity Closest ---------------------------------------------------------------------------------------------------
                if (parentObject is ITargetable)
                {
                    foreach (IMarkerParentObject impo in MapCore.Active.selection)
                    {
                        Ship ship01 = impo as Ship;
                        if (ship01 != null && ship01.Friendly)
                        {
                            ship01.low_ai.MatchVelocityNearTarget((parentObject as ITargetable).Associated);
                        }
                    }
                }
                goto LOOPEND;

            case 0x1a:
// Match Velocity -----------------------------------------------------------------------------------------------------------
                if (parentObject is IPhysicsObject)
                {
                    foreach (IMarkerParentObject impo in MapCore.Active.selection)
                    {
                        Ship ship01 = impo as Ship;
                        if (ship01 != null && ship01.Friendly)
                        {
                            ship01.low_ai.MatchVelocity((parentObject as ITargetable).Associated);
                        }
                    }
                }
                goto LOOPEND;

            case 0x1b:
// Attack -------------------------------------------------------------------------------------------------------------------
                if (parentObject is ITargetable)
                {
                    Target self_tgt = (parentObject as ITargetable).Associated;
                    foreach (IMarkerParentObject impo in MapCore.Active.selection)
                    {
                        Ship ship01 = impo as Ship;
                        if (ship01 != null && ship01.Friendly)
                        {
                            ship01.low_ai.Attack(self_tgt);
                        }
                    }
                }
                goto LOOPEND;

            case 0x1c:
// TurretAttack -------------------------------------------------------------------------------------------------------------
                if (parentObject is ITargetable)
                {
                    Target self_tgt = (parentObject as ITargetable).Associated;
                    foreach (IMarkerParentObject impo in MapCore.Active.selection)
                    {
                        Ship ship01 = impo as Ship;
                        if (ship01 != null && ship01.Friendly)
                        {
                            ship01.low_ai.TurretAttack(self_tgt);
                        }
                    }
                }
                goto LOOPEND;

            case 0x1d:
// Aim Here -----------------------------------------------------------------------------------------------------------------
                SceneGlobals.Player.TurretAim = parentObject;
                goto LOOPEND;

            case 0x1e:
// Target Part --------------------------------------------------------------------------------------------------------------

                goto LOOPEND;

            case 0x1f:
// Set Target ---------------------------------------------------------------------------------------------------------------
                if (parentObject is ITargetable)
                {
                    Target tgt = (parentObject as ITargetable).Associated;
                    SceneGlobals.Player.Target = tgt;
                }
                goto LOOPEND;

//  +-----------------------------------------------------------------------------------------------------------------------+
//  |										Info																			|
//  +-----------------------------------------------------------------------------------------------------------------------+
            case 0x2e:
// Ship Information ---------------------------------------------------------------------------------------------------------
                if (i != 0)
                {
                    goto LOOPEND;
                }
                concerned.SpawnChild("Ship Information", new string [] {
                    ship.Mass.ToString("Mass: 0.0 t"),
                    string.Format("HP: {0:0.0} / {1:0.0}", ship.HP, ship.tot_hp),
                });
                goto LOOPEND;

            case 0x2f:
// OS -----------------------------------------------------------------------------------------------------------------------
                goto LOOPEND;
//  +-----------------------------------------------------------------------------------------------------------------------+
//  |									Command																				|
//  +-----------------------------------------------------------------------------------------------------------------------+

// Match Velocity Closest ---------------------------------------------------------------------------------------------------
            case 0x29:

                goto LOOPEND;

// Match Velocity -----------------------------------------------------------------------------------------------------------
            case 0x3a:

                goto LOOPEND;

            case 0x3b:
// Flee ---------------------------------------------------------------------------------------------------------------------
                ship.low_ai.Flee();
                goto LOOPEND;

            case 0x3c:
// Idle ---------------------------------------------------------------------------------------------------------------------
                ship.low_ai.Idle();
                goto LOOPEND;

            case 0x3d:
// Attack -------------------------------------------------------------------------------------------------------------------

                goto LOOPEND;

            case 0x3e:
// TurretAttack -------------------------------------------------------------------------------------------------------------

                goto LOOPEND;

            case 0x3f:
// Control ------------------------------------------------------------------------------------------------------------------
                if (parentObject is Ship)
                {
                    SceneGlobals.Player = parentObject as Ship;
                }
                goto LOOPEND;

            default: goto LOOPEND;
            }
            LOOPEND :;
        }
    }