Example #1
0
    /// <summary>
    /// Advance _chance amount of alive cells to _nextsState
    /// </summary>
    /// <returns><c>true</c> There was transition happening <c>false</c> There wasn't any transition happening </returns>
    /// <param name="_nextState"> The state in which the squad child advances to </param>
    /// <param name="_chance"> The chance in which the squad child cell will advance </param>
    public static bool AdvanceSquadPercentage(SCState _nextState, float _chance)
    {
        // if: All the alive child is the _nextstate state
        if (SquadChildFSM.AliveCount() == SquadChildFSM.StateCount(_nextState))
        {
            return(false);
        }

        // for: Checksthrough all the child in the array
        for (int i = 0; i < s_array_SquadChildFSM.Length; i++)
        {
            if (s_array_SquadChildFSM[i].EnumState != SCState.Dead)
            {
                // if: the current cell type is NOT the targeted cell type, as transition would be useless
                if (s_array_SquadChildFSM[i].EnumState != _nextState)
                {
                    // if: The it is within the chance range
                    if (UnityEngine.Random.value <= _chance)
                    {
                        s_array_SquadChildFSM[i].Advance(_nextState);
                    }
                }
            }
        }
        return(true);
    }
    public ChrStateMachine()
    {
        CurrentState  = new SCState();
        previousState = new SCState();

        //StaticStates.Instance.Init();
    }
Example #3
0
        private void CreateUndo(bool ForHistory = true)
        {
            SCState history = new SCState(pixels, chars, actions);

            undo.Insert(0, history);

            if (ForHistory)
            {
                if (undo.Count > 32)
                {
                    var itm = undo[undo.Count - 1];
                    itm.Dispose();
                    undo.RemoveAt(undo.Count - 1);
                }

                foreach (var itm in redo)
                {
                    itm.Dispose();
                }

                redo.Clear();

                if (HistoryChanged != null)
                {
                    HistoryChanged(this, EventArgs.Empty);
                }
            }
        }
Example #4
0
    /// <summary>
    /// Advance all squad in the state _currentState to _nextState by a certain amount of _chance
    /// </summary>
    /// <param name="_currentState"> the state of squad child which would be advancing </param>
    /// <param name="_nextState"> The state that the squad child cell will advance towards </param>
    /// <param name="_chance"> The chance of which the squad child cell will advance </param>
    public static bool AdvanceSquadPercentage(SCState _currentState, SCState _nextState, float _chance)
    {
        if (_currentState == _nextState)
        {
            return(false);
        }
        else if (SquadChildFSM.StateCount(_currentState) == 0)
        {
            return(false);
        }

        // for: Checks through all the child in the array
        for (int i = 0; i < s_array_SquadChildFSM.Length; i++)
        {
            // if: The current cell type is the trageted cell type
            if (s_array_SquadChildFSM[i].EnumState == _currentState)
            {
                // if: The it is within the chance range
                if (UnityEngine.Random.value <= _chance)
                {
                    s_array_SquadChildFSM[i].Advance(_nextState);
                }
            }
        }
        return(true);
    }
Example #5
0
 private void SetDefaults()
 {
     ControlStyle     = SCStyle.Normal;
     ControlType      = SCType.Active;
     ControlBorder    = SCBorder.None;
     ControlState     = SCState.Design;
     ControlText      = "";
     BaseIconFileName = "NoImage";
     DisplayMode      = true;
 }
Example #6
0
        public SkyControllerGlobal(SkyControllerPlugin plugin) : base(plugin)
        {
            Console.WriteLine("Starting net receiver...");

            listener.JoinMulticastGroup(IPAddress.Parse("230.0.0.1"));
            Console.WriteLine("Waiting for data on 230.0.0.1:8899...");

            data = listener.Receive(ref ep);
            Console.WriteLine("Receiving from " + ep.Address.ToString() + ":" + ep.Port.ToString() + "...");

            deviceState = new SCState();
        }
 public void ChangeState(Character chr, SCState newState)
 {
     if (newState != null)
     {
         CurrentState.Exit(chr);
         previousState = CurrentState;
         CurrentState  = newState;
         newState.Enter(chr);
     }
     else
     {
         Debug.Log("ChrStateMachine - New State not found!");
     }
 }
Example #8
0
    // Public Functions
    // Advance(): Advance to the next state, which is defined by _enumState
    public bool Advance(SCState _enumState)
    {
        if (_enumState.Equals(m_currentEnumState))
        {
            Debug.LogWarning(this.name + ".SquadChildFSM.Advance(): Tried to advance to same state! m_currentEnumState = SC.State." + m_currentEnumState.ToString());
            return(false);
        }

        // State Changing
        m_currentState.Exit();

        m_currentEnumState = _enumState;
        m_currentState     = dict_States[m_currentEnumState];

        m_currentState.Enter();
        return(true);
    }
Example #9
0
    // Public Static Functions
    /// <summary>
    /// Returns the number of squad child cells that is in the current state
    /// </summary>
    /// <param name="_enumState"> The state in which to check for </param>
    /// <returns></returns>
    public static int StateCount(SCState _enumState)
    {
        if (s_array_SquadChildFSM == null)
        {
            return(-1);
        }

        int nStateCount = 0;

        for (int i = 0; i < s_array_SquadChildFSM.Length; i++)
        {
            if (s_array_SquadChildFSM[i].EnumState == _enumState)
            {
                nStateCount++;
            }
        }
        return(nStateCount);
    }
Example #10
0
 public static string convert2MES(SCState hostMode)
 {
     if (hostMode == SCState.Init)
     {
         return(SECSConst.SCSTATE_Init);
     }
     else if (hostMode == SCState.Paused)
     {
         return(SECSConst.SCSTATE_Paused);
     }
     else if (hostMode == SCState.Auto)
     {
         return(SECSConst.SCSTATE_Auto);
     }
     else if (hostMode == SCState.Pausing)
     {
         return(SECSConst.SCSTATE_Pausing);
     }
     return(string.Empty);
 }
Example #11
0
    // Start(): Use this for initialisation
    void Start()
    {
        // Initialisation of Dictionary
        dict_States = new Dictionary <SCState, ISCState>();
        dict_States.Add(SCState.Dead, new SC_DeadState(this));
        dict_States.Add(SCState.Idle, new SC_IdleState(this));
        dict_States.Add(SCState.Attack, new SC_AttackState(this));
        dict_States.Add(SCState.Defend, new SC_DefendState(this));
        dict_States.Add(SCState.Produce, new SC_ProduceState(this));
        dict_States.Add(SCState.FindResource, new SC_FindResourceState(this));
        dict_States.Add(SCState.Avoid, new SC_AvoidState(this));

        // Initialisation
        playerPosition   = PlayerMain.Instance.transform.position;
        m_strafingVector = Vector3.up;
        mAnimate         = new Animate(transform);

        fStrafingRadius      = PlayerSquadFSM.Instance.StrafingRadius;
        fStrafingSpeed       = PlayerSquadFSM.Instance.StrafingSpeed;
        fDefenceAngle        = PlayerSquadFSM.Instance.DefenceAngle;
        fDefenceRadius       = PlayerSquadFSM.Instance.DefenceRadius;
        fDefenceSpeed        = PlayerSquadFSM.Instance.DefenceSpeed;
        fDefenceRigidity     = PlayerSquadFSM.Instance.DefenceRigidity;
        nDefenceMinimumCount = PlayerSquadFSM.Instance.DefenceMinimumCount;
        fAttackSpeed         = PlayerSquadFSM.Instance.AttackSpeed;

        mainDefenceVector = Quaternion.Euler(0f, 0f, (fDefenceAngle / 2.0f)) * Vector2.up * fDefenceRadius;

        if (s_list_EnemyLandmine == null)
        {
            s_list_EnemyLandmine = ECTracker.Instance.LandmineCells;
        }

        // Initialisation of first state
        m_currentEnumState = SCState.Dead;
        m_currentState     = dict_States[m_currentEnumState];
        m_currentState.Enter();
    }
Example #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Setting up virtual device...");

            joystick = new vJoy();


            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id);
                break;

            case VjdStat.VJD_STAT_FREE:
                Console.WriteLine("vJoy Device {0} is free\n", id);
                break;

            case VjdStat.VJD_STAT_BUSY:
                Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                return;

                joystick.ResetVJD(id);

            case VjdStat.VJD_STAT_MISS:
                Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                return;

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
                return;
            }

            if (!(joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL0) &&
                  joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL1)
                  ))
            {
                Console.WriteLine("VJoy Device " + id + " does not support enough axes for SkyController. Make sure device has at least 8 axes");
                return;
            }

            // Test if DLL matches the driver
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
            }
            else
            {
                Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
            }


            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
            }


            deviceState = new SCState();


            Console.WriteLine("Starting net receiver...");
            UdpClient  listener = new UdpClient(8899);
            IPEndPoint ep       = null;

            byte[] data = new byte[128];

            listener.JoinMulticastGroup(IPAddress.Parse("230.0.0.1"));
            Console.WriteLine("Waiting for data on 230.0.0.1:8899...");

            data = listener.Receive(ref ep);
            Console.WriteLine("Receiving from " + ep.Address.ToString() + ":" + ep.Port.ToString() + "...");

            joystick.ResetVJD(id);

            int  CursorRow = Console.CursorTop;
            uint pId       = 0;

            long axisMax = 0;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref axisMax);

            while (true)
            {
                //System.Threading.Thread.Sleep(10);

                data = listener.Receive(ref ep);
                pId  = BitConverter.ToUInt32(data, 0);

                deviceState.Deserialize(data, 4);

                Console.CursorLeft = 0;
                Console.CursorTop  = CursorRow;

                Console.WriteLine("Received " + data.Length + " bytes. Packet ID: " + pId);
                //Console.WriteLine("Yaw: " + deviceState._axis0.ToString("0.00"));
                //Console.WriteLine("Gaz: " + deviceState._axis1.ToString("0.00"));
                //Console.WriteLine("Roll: " + deviceState._axis13.ToString("0.00"));
                //Console.WriteLine("Pitch: " + deviceState._axis2.ToString("0.00"));
                //Console.WriteLine("LThumb X: " + deviceState._axis14.ToString("0.00"));
                //Console.WriteLine("LThumb Y: " + deviceState._axis15.ToString("0.00"));
                //Console.WriteLine("RThumb X: " + deviceState._axis8.ToString("0.00"));
                //Console.WriteLine("RThumb Y: " + deviceState._axis9.ToString("0.00"));
                Console.WriteLine("Battery: " + (deviceState._axis10 * 100f).ToString("0.00") + "%");


                //joystick.SetAxis((int)(deviceState._axis0 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_X);
                //joystick.SetAxis((int)(-deviceState._axis1 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Y);
                //joystick.SetAxis((int)(deviceState._axis13 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RX);
                //joystick.SetAxis((int)(deviceState._axis2 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RY);
                //joystick.SetAxis((int)(deviceState._axis3 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Z);
                //joystick.SetAxis((int)(deviceState._axis14 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RZ);
                //joystick.SetAxis((int)(deviceState._axis8 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL0);
                //joystick.SetAxis((int)(deviceState._axis9 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL1);

                joystick.SetAxis((int)(deviceState._axis13 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_X);
                joystick.SetAxis((int)(-deviceState._axis2 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Y);
                joystick.SetAxis((int)(-deviceState._axis1 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Z);
                joystick.SetAxis((int)(deviceState._axis0 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RX);
                joystick.SetAxis((int)(deviceState._axis8 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RY);
                joystick.SetAxis((int)(deviceState._axis9 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RZ);
                joystick.SetAxis((int)(deviceState._axis3 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL0);
                joystick.SetAxis((int)(deviceState._axis14 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL1);
            }
        }
Example #13
0
        private void CreateRedo()
        {
            SCState history = new SCState(pixels, chars, actions);

            redo.Insert(0, history);
        }
Example #14
0
 public void SCS_ChangeState(SCState newState)
 {
     ChrSM.ChangeState(this, newState);
 }