Example #1
0
    // Change current state, perform exit and enter functions
    public void ChangeState(EMState newState)
    {
        // Make sure the state we are transitioning to is not the current state
        if (newState != CurrentStateIndex)
        {
            if (m_CurrentState != null)
            {
                m_CurrentState.Exit();
            }

            m_currentStateIndex = newState;
            m_CurrentState      = m_statesDictionary [newState];
            m_CurrentState.Enter();
        }
    }
    void Start()
    {
        enemyMainObject = this.gameObject;
        #region Initialize state dictionary
        m_statesDictionary = new Dictionary<EMState, IEMState>();
        m_statesDictionary.Add (EMState.Production, new EMProductionState (this));
        m_statesDictionary.Add (EMState.Maintain, new EMMaintainState (this));
        m_statesDictionary.Add (EMState.Defend, new EMDefendState (this));
        m_statesDictionary.Add (EMState.AggressiveAttack, new EMAggressiveAttackState (this));
        m_statesDictionary.Add (EMState.CautiousAttack, new EMCautiousAttackState (this));
        m_statesDictionary.Add (EMState.Landmine, new EMLandmineState (this));
        m_statesDictionary.Add (EMState.Stunned, new EMStunnedState (this));
        m_statesDictionary.Add (EMState.Die, new EMDieState (this));
        m_statesDictionary.Add (EMState.Win, new EMWinState (this));
        #endregion

        #region Initialize the Learning Element dictionary
        m_learningDictionary = new Dictionary<EMState, float>();
        m_learningDictionary.Add (EMState.Production, 0f);
        m_learningDictionary.Add (EMState.Maintain, 0f);
        m_learningDictionary.Add (EMState.Defend, 0f);
        m_learningDictionary.Add (EMState.AggressiveAttack, 0f);
        m_learningDictionary.Add (EMState.CautiousAttack, 0f);
        m_learningDictionary.Add (EMState.Landmine, 0f);
        m_learningDictionary.Add (EMState.Stunned, 0f);
        m_learningDictionary.Add (EMState.Die, 0f);
        m_learningDictionary.Add (EMState.Win, 0f);
        #endregion

        // Initialize the default to Production
        m_CurrentState = m_statesDictionary [EMState.Production];
        m_currentStateIndex = EMState.Production;

        // Get the enemy main controller, helper class and transition class
        emController = GetComponent<EMController> ();
        emHelper = GetComponent<EMHelper> ();
        emTransition = GetComponent<EMTransition> ();

        //Initialize and refresh the point database for Enemy Child Cells
        PointDatabase.Instance.InitializeDatabase();
        PointDatabase.Instance.RefreshDatabase();
        FormationDatabase.Instance.RefreshDatabases(ECList);

        // Initialise the enemy child list
        /*
        EnemyChildFSM[] ecClasses = (EnemyChildFSM[])GameObject.FindObjectsOfType (typeof(EnemyChildFSM));
        foreach (EnemyChildFSM ecClass in ecClasses)
        {
            if (ecClass.CurrentStateEnum != ECState.Dead)
                ecList.Add (ecClass);
        }
        */
        // ecList = GameObject.FindGameObjectsWithTag("EnemyChild").Select(gameObject => gameObject.GetComponent<EnemyChildFSM>()).ToList();
        // Count the number of child cells in list
        /*
        for (int i = 0; i < ecList.Count; i++) {
            if(ecList[i].CurrentStateEnum != ECState.Dead)
                nAvailableChildNum++;
        }
        */
    }
Example #3
0
    void Start()
    {
        enemyMainObject = this.gameObject;
        #region Initialize state dictionary
        m_statesDictionary = new Dictionary <EMState, IEMState>();
        m_statesDictionary.Add(EMState.Production, new EMProductionState(this));
        m_statesDictionary.Add(EMState.Maintain, new EMMaintainState(this));
        m_statesDictionary.Add(EMState.Defend, new EMDefendState(this));
        m_statesDictionary.Add(EMState.AggressiveAttack, new EMAggressiveAttackState(this));
        m_statesDictionary.Add(EMState.CautiousAttack, new EMCautiousAttackState(this));
        m_statesDictionary.Add(EMState.Landmine, new EMLandmineState(this));
        m_statesDictionary.Add(EMState.Stunned, new EMStunnedState(this));
        m_statesDictionary.Add(EMState.Die, new EMDieState(this));
        m_statesDictionary.Add(EMState.Win, new EMWinState(this));
        #endregion

        #region Initialize the Learning Element dictionary
        m_learningDictionary = new Dictionary <EMState, float>();
        m_learningDictionary.Add(EMState.Production, 0f);
        m_learningDictionary.Add(EMState.Maintain, 0f);
        m_learningDictionary.Add(EMState.Defend, 0f);
        m_learningDictionary.Add(EMState.AggressiveAttack, 0f);
        m_learningDictionary.Add(EMState.CautiousAttack, 0f);
        m_learningDictionary.Add(EMState.Landmine, 0f);
        m_learningDictionary.Add(EMState.Stunned, 0f);
        m_learningDictionary.Add(EMState.Die, 0f);
        m_learningDictionary.Add(EMState.Win, 0f);
        #endregion

        // Initialize the default to Production
        m_CurrentState      = m_statesDictionary [EMState.Production];
        m_currentStateIndex = EMState.Production;

        // Get the enemy main controller, helper class and transition class
        emController = GetComponent <EMController> ();
        emHelper     = GetComponent <EMHelper> ();
        emTransition = GetComponent <EMTransition> ();

        //Initialize and refresh the point database for Enemy Child Cells
        PointDatabase.Instance.InitializeDatabase();
        PointDatabase.Instance.RefreshDatabase();
        FormationDatabase.Instance.RefreshDatabases(ECList);

        // Initialise the enemy child list

        /*
         *      EnemyChildFSM[] ecClasses = (EnemyChildFSM[])GameObject.FindObjectsOfType (typeof(EnemyChildFSM));
         *      foreach (EnemyChildFSM ecClass in ecClasses)
         *      {
         *              if (ecClass.CurrentStateEnum != ECState.Dead)
         *                      ecList.Add (ecClass);
         *      }
         */
        // ecList = GameObject.FindGameObjectsWithTag("EnemyChild").Select(gameObject => gameObject.GetComponent<EnemyChildFSM>()).ToList();
        // Count the number of child cells in list

        /*
         * for (int i = 0; i < ecList.Count; i++) {
         *      if(ecList[i].CurrentStateEnum != ECState.Dead)
         *              nAvailableChildNum++;
         * }
         */
    }
    // Change current state, perform exit and enter functions
    public void ChangeState(EMState newState)
    {
        // Make sure the state we are transitioning to is not the current state
        if (newState != CurrentStateIndex)
        {
            if (m_CurrentState != null)
                m_CurrentState.Exit ();

            m_currentStateIndex = newState;
            m_CurrentState = m_statesDictionary [newState];
            m_CurrentState.Enter ();
        }
    }