Пример #1
0
    /**
     * Returns the number of world state properties that are different from the world state input
     * @param the other world state to check against the current world state
     */
    //获取未满足的属性数量
    public int GetNumUnsatisfiedWorldStateProps(WorldState otherState)
    {
        int count = 0;

        for (E_PropKey i = 0; i < E_PropKey.E_COUNT; i++)
        {
            //自身该属性没有设置跳出
            if (IsWSPropertySet(i) == false)
            {
                continue;
            }
            //其他角色该属性没有设置,自身设置了,count++
            if (!otherState.IsWSPropertySet(i))
            {
                count++;
            }

            //自身和其他角色该属性不相等,count++
            if (!(GetWSProperty(i) == otherState.GetWSProperty(i))) //test
            {
                count++;
            }
        }
        return(count);
    }
Пример #2
0
 public void ResetWSProperty(E_PropKey key)
 {
     //Debug.Log("Reset WS property " + key.ToString());
     if (IsWSPropertySet(key))
     {
         WorldStatePropFactory.Return(WorldStateProperties[(int)key]);
         WorldStateProperties[(int)key] = null;
     }
 }
Пример #3
0
 public void CopyWorldState(WorldState otherState)
 {
     Reset();
     for (E_PropKey i = 0; i < E_PropKey.E_COUNT; i++)
     {
         if (otherState.GetPropBitSet().Get((int)i) == true)
         {
             SetWSProperty(otherState.GetWSProperty(i));
         }
     }
 }
Пример #4
0
 public void SetWSProperty(E_PropKey key, E_CoverState value)
 {
     if (IsWSPropertySet(key))
     {
         WorldStatePropFactory.Return(WorldStateProperties[(int)key]);
         WorldStateProperties[(int)key] = WorldStatePropFactory.Create(key, value);
     }
     else
     {
         WorldStateProperties[(int)key] = WorldStatePropFactory.Create(key, value);
     }
 }
Пример #5
0
 public void SetWSProperty(E_PropKey key, UnityEngine.Vector3 value)
 {
     if (IsWSPropertySet(key))
     {
         WorldStatePropFactory.Return(WorldStateProperties[(int)key]);
         WorldStateProperties[(int)key] = WorldStatePropFactory.Create(key, value);
     }
     else
     {
         WorldStateProperties[(int)key] = WorldStatePropFactory.Create(key, value);
     }
 }
Пример #6
0
    public void SetWSProperty(E_PropKey key, UnityEngine.Vector3 value)
    {
        int index = (int)key;

        if (m_PropState[index] != null)
        {
            WorldStatePropFactory.Return(m_PropState[index]);
        }

        m_PropState[index] = WorldStatePropFactory.Create(key, value);
        m_PropBitSet.Set(index, true);         // set info that key is set
    }
Пример #7
0
    public void SetWSProperty(E_PropKey key, AgentOrder.E_OrderType value)
    {
        int index = (int)key;

        if (m_PropState[index] != null)
        {
            WorldStatePropFactory.Return(m_PropState[index]);
        }

        m_PropState[index] = WorldStatePropFactory.Create(key, value);
        m_PropBitSet.Set(index, true);         // set info that key is set
    }
Пример #8
0
    public void ResetWSProperty(E_PropKey key)
    {
        //Debug.Log("Reset WS property " + key.ToString());
        int i = (int)key;

        if (m_PropState[i] != null)
        {
            WorldStatePropFactory.Return(m_PropState[i]);
            m_PropState[i] = null;
            m_PropBitSet.Set(i, false);
        }
    }
Пример #9
0
    public override string ToString()
    {
        string s = "World state : ";

        for (E_PropKey i = E_PropKey.Idling; i < E_PropKey.Count; i++)
        {
            if (IsWSPropertySet(i))
            {
                s += " " + GetWSProperty(i).ToString();
            }
        }

        return(s);
    }
Пример #10
0
    public override string ToString()
    {
        string s = "World state : ";

        for (E_PropKey i = E_PropKey.E_ORDER; i < E_PropKey.E_COUNT; i++)
        {
            if (IsWSPropertySet(i))
            {
                s += " " + GetWSProperty(i).ToString();
            }
        }

        return(s);
    }
Пример #11
0
    /**
     * Sets the plans WS preconditions. Takes in the goal and sets its WS to be the preconditions
     * @param the agents ai
     * @param the goal state
     */
    public void SetPlanWSPreconditions(WorldState goalState)
    {
        WorldStateProp precond;

        for (E_PropKey i = 0; i < E_PropKey.E_COUNT; i++)          //Go through the action's preconditions and set the goal state's properties to be equal to the precondition properties
        {
            precond = WorldPreconditions.GetWSProperty(i);

            //If the precondition isn't invalid
            if (precond != null)
            {
                goalState.SetWSProperty(precond);
            }
        }
    }
Пример #12
0
    /**
     * Applies the actions world state effects to the current world state
     * @param the current world state
     * @param the goal state
     */

    public void ApplyWSEffects(WorldState currentState, WorldState goalState)
    {
        WorldStateProp effect;

        for (E_PropKey i = 0; i < E_PropKey.Count; i++)
        {
            effect = WorldEffects.GetWSProperty(i);

            //If effect is valid
            if (effect != null)
            {
                currentState.SetWSProperty(effect);
            }
        }
    }
Пример #13
0
    }                                                                                     // only bool now

    public void SetWSProperty(E_PropKey key, bool value)
    {
        int index = (int)key;

        if (m_PropState[index] != null)
        {
            WorldStatePropFactory.Return(m_PropState[index]);
        }

        m_PropState[index] = WorldStatePropFactory.Create(key, value);
        m_PropBitSet.Set(index, true);         // set info that key is set


        //for (int i = 0; i < m_PropBitSet.Count; i++)
        //{
        //    Debug.Log("m_PropBitSet[" + i + "].GetHashCode()=" + m_PropBitSet[i].GetHashCode());
        //}
    }
Пример #14
0
    public void MergeStates(AgentHuman ai, WorldState currentState, WorldState goalState)
    {
        for (E_PropKey iProp = 0; iProp < E_PropKey.Count; ++iProp)
        {
            // Continue if property already exists in current
            // world state.

            if ((!goalState.IsWSPropertySet(iProp)) || // if not set in goal
                (currentState.IsWSPropertySet(iProp))) //if already set
            {
                continue;                              // then continue
            }

            // and set real property from Agent to current
            WorldStateProp prop = ai.WorldState.GetWSProperty((E_PropKey)iProp);
            currentState.SetWSProperty(prop);
        }
    }
Пример #15
0
    static public WorldStateProp Create(E_PropKey key, float state)
    {
        WorldStateProp p;

        if (m_UnusedProps.Count > 0)
        {
            p           = m_UnusedProps.Dequeue();
            p.PropKey   = key;
            p.PropValue = new ValueFloat(state);
        }
        else
        {
            p = new WorldStateProp(state);
        }

        p.Time     = UnityEngine.Time.timeSinceLevelLoad;
        p.PropType = E_PropType.E_FLOAT;
        return(p);
    }
Пример #16
0
    static public WorldStateProp Create(E_PropKey key, UnityEngine.Vector3 vector)
    {
        WorldStateProp p = null;

        if (m_UnusedProps.Count > 0)
        {
            p           = m_UnusedProps.Dequeue();
            p.PropValue = new ValueVector(vector);
            p.PropType  = E_PropType.E_VECTOR;
        }
        else
        {
            p = new WorldStateProp(vector);
        }

        p.Time    = UnityEngine.Time.timeSinceLevelLoad;
        p.PropKey = key;
        return(p);
    }
Пример #17
0
    static public WorldStateProp Create(E_PropKey key, bool state)
    {
        WorldStateProp p = null;

        if (m_UnusedProps.Count > 0)
        {
            p           = m_UnusedProps.Dequeue();
            p.PropValue = new ValueBool(state);
            p.PropType  = E_PropType.E_BOOL;
        }
        else
        {
            p = new WorldStateProp(state);
        }

        p.Time    = UnityEngine.Time.timeSinceLevelLoad;
        p.PropKey = key;
        return(p);
    }
Пример #18
0
    public static WorldStateProp Create(E_PropKey key, AgentHuman state)
    {
        WorldStateProp p = null;

        if (m_UnusedProps.Count > 0)
        {
            p          = m_UnusedProps.Dequeue();
            p.Agent    = state;
            p.PropType = E_PropType.Agent;
        }
        else
        {
            p = new WorldStateProp(state);
        }

        p.Time    = UnityEngine.Time.timeSinceLevelLoad;
        p.PropKey = key;
        return(p);
    }
Пример #19
0
    static public WorldStateProp Create(E_PropKey key, AgentOrder.E_OrderType orderType)
    {
        WorldStateProp p = null;

        if (m_UnusedProps.Count > 0)
        {
            p           = m_UnusedProps.Dequeue();
            p.PropValue = new ValueOrder(orderType);
            p.PropType  = E_PropType.E_EVENT;
        }
        else
        {
            p = new WorldStateProp(orderType);
        }

        p.Time    = UnityEngine.Time.timeSinceLevelLoad;
        p.PropKey = key;
        return(p);
    }
Пример #20
0
    /**
     * Returns the number of world state properties that are different from the world state input
     * @param the other world state to check against the current world state
     */

    public int GetNumUnsatisfiedWorldStateProps(WorldState otherState)
    {
        int count = 0;

        for (E_PropKey i = 0; i < E_PropKey.Count; i++)
        {
            if (IsWSPropertySet(i) == false)
            {
                continue;
            }

            if (!otherState.IsWSPropertySet(i))
            {
                count++;
            }

            if (!(GetWSProperty(i) == otherState.GetWSProperty(i)))             //test
            {
                count++;
            }
        }
        return(count);
    }
Пример #21
0
    void DrawBase()
    {
        AgentDebugInfo debugInfo = target as AgentDebugInfo;
        AgentHuman     agent     = debugInfo.GetComponent <AgentHuman>();

        if (agent.Transform == null)
        {
            return;
        }

        BlackBoard bb = agent.BlackBoard;

        GUILayout.BeginVertical();
        //GUILayout.Label("Base Settings", "OL Title" );
        ShowBase = EditorGUILayout.Foldout(ShowBase, "Base Setings ");

        if (ShowBase && agent.WeaponComponent)
        {
            EditorGUILayout.FloatField("Health ", bb.Health, GUILayout.Width(250), GUILayout.ExpandWidth(false));
            EditorGUILayout.EnumPopup("Weapon", agent.WeaponComponent.CurrentWeapon, GUILayout.Width(250), GUILayout.ExpandWidth(false));

            EditorGUILayout.ObjectField("Melee Target ", bb.Desires.MeleeTarget, typeof(GameObject), true, GUILayout.Width(250), GUILayout.ExpandWidth(false));
        }

        GUILayout.Space(10);
        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        MoveInfo = EditorGUILayout.Foldout(MoveInfo, "Move info ");

        if (MoveInfo)
        {
            EditorGUILayout.EnumPopup("Motion", agent.BlackBoard.MotionType, GUILayout.Width(250), GUILayout.ExpandWidth(false));
            EditorGUILayout.EnumPopup("Move", agent.BlackBoard.MoveType, GUILayout.Width(250), GUILayout.ExpandWidth(false));
            EditorGUILayout.FloatField("Speed ", agent.BlackBoard.Speed, GUILayout.Width(250), GUILayout.ExpandWidth(false));
            EditorGUILayout.Vector3Field("Rotation", agent.Forward, GUILayout.Width(250), GUILayout.ExpandWidth(false));
            EditorGUILayout.Vector3Field("Fire Dir", agent.BlackBoard.FireDir, GUILayout.Width(250), GUILayout.ExpandWidth(false));
        }

        GUILayout.Space(10);
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        ShowGoap = EditorGUILayout.Foldout(ShowGoap, "Goap Manager ");

        if (ShowGoap)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Name", "OL Title", GUILayout.Width(100));
            GUILayout.Label("Relevancy", "OL Title", GUILayout.Width(60));
            GUILayout.Label("Enabled", "OL Title", GUILayout.Width(60));
            GUILayout.EndHorizontal();

            foreach (E_GOAPGoals key in System.Enum.GetValues(typeof(E_GOAPGoals)))
            {
                GOAPGoal goal = agent.GetGOAPGoal(key);
                if (goal == null)
                {
                    continue;
                }

                GUILayout.BeginHorizontal();

                if (goal.Active)
                {
                    GUILayout.Label(goal.GoalType.ToString(), EditorStyles.whiteLabel, GUILayout.Width(100), GUILayout.ExpandWidth(false));
                }
                else
                {
                    GUILayout.Label(goal.GoalType.ToString(), GUILayout.Width(100), GUILayout.ExpandWidth(false));
                }

                EditorGUILayout.LabelField(goal.GoalRelevancy.ToString(), "", GUILayout.Width(60), GUILayout.ExpandWidth(false));
                EditorGUILayout.LabelField((goal.IsDisabled() == false).ToString(), "", GUILayout.Width(60), GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();
            }
        }
        GUILayout.Space(10);

        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        ShowWorldState = EditorGUILayout.Foldout(ShowWorldState, "World States ");

        if (ShowWorldState && agent.WorldState != null)
        {
            for (E_PropKey key = E_PropKey.Start; key < E_PropKey.Count; key++)
            {
                if (agent.WorldState == null)
                {
                    continue;
                }

                WorldStateProp prop = agent.WorldState.GetWSProperty(key);

                if (prop == null)
                {
                    continue;
                }

                switch (prop.PropType)
                {
                case E_PropType.Bool:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetBool().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                case E_PropType.Int:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetBool().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                case E_PropType.Float:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetFloat().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                case E_PropType.Vector:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetVector().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                case E_PropType.Agent:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetAgent().name, GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                case E_PropType.CoverState:
                    EditorGUILayout.LabelField(prop.PropName, prop.GetCoverState().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false));
                    break;

                default:
                    Debug.LogError("Unknow prop type " + prop.PropType);
                    break;
                }
            }
        }
        GUILayout.Space(10);
        GUILayout.EndVertical();

        GUILayout.BeginVertical();

        ShowAnim = EditorGUILayout.Foldout(ShowAnim, "Animations");

        if (ShowAnim && agent.AnimComponent != null)
        {
            EditorGUILayout.LabelField("Current State: ", agent.AnimComponent.CurrentAnimState != null? agent.AnimComponent.CurrentAnimState.ToString() : " none", GUILayout.Width(250), GUILayout.ExpandWidth(false));


            GUILayout.BeginHorizontal();
            GUILayout.Label("Name", "OL Title", GUILayout.Width(200));
            GUILayout.Label("Layer", "OL Title", GUILayout.Width(40));
            GUILayout.Label("Weight", "OL Title", GUILayout.Width(100));
            GUILayout.Label("Time", "OL Title", GUILayout.Width(100));
            GUILayout.EndHorizontal();

            if (Application.isPlaying)
            {
                foreach (AnimationState state in agent.GetComponent <Animation>())
                {
                    if (agent.GetComponent <Animation>().IsPlaying(state.clip.name) == false)
                    {
                        continue;
                    }

                    GUILayout.BeginHorizontal();

                    GUILayout.Label(state.name, GUILayout.Width(200), GUILayout.ExpandWidth(false));

                    EditorGUILayout.LabelField(state.layer.ToString(), "", GUILayout.Width(40), GUILayout.ExpandWidth(false));
                    EditorGUILayout.LabelField(state.weight.ToString(), "", GUILayout.Width(100), GUILayout.ExpandWidth(false));
                    EditorGUILayout.LabelField(state.time.ToString(), "", GUILayout.Width(100), GUILayout.ExpandWidth(false));
                    GUILayout.EndHorizontal();
                }
            }
        }
        GUILayout.Space(10);

        GUILayout.EndVertical();

/*
 *      GUILayout.BeginVertical();
 *      EditorGUI.indentLevel++;
 *      GUILayout.Label("User Settings", "OL Title");
 *      interaction.EntryTransform = EditorGUILayout.ObjectField("Entry position", interaction.EntryTransform, typeof(Transform), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as Transform;
 *      interaction.LeaveTransform = EditorGUILayout.ObjectField("Leave position", interaction.LeaveTransform, typeof(Transform), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as Transform;
 *      interaction.UserAnimationClip = EditorGUILayout.ObjectField("User animation", interaction.UserAnimationClip, typeof(AnimationClip), false, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as AnimationClip;
 *      EditorGUI.indentLevel--;
 *      GUILayout.EndVertical();
 *
 *      GUILayout.BeginVertical();
 *      EditorGUI.indentLevel++;
 *      GUILayout.Label("Cutscene Settings", "OL Title");
 *      interaction.CutsceneCamera = EditorGUILayout.ObjectField("Camera", interaction.CutsceneCamera, typeof(GameObject), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as GameObject;
 *      interaction.CameraAnim = EditorGUILayout.ObjectField("Animation", interaction.CameraAnim, typeof(AnimationClip), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as AnimationClip;
 *      interaction.FadeInTime= EditorGUILayout.FloatField("Fade In", interaction.FadeInTime, GUILayout.Width(250), GUILayout.ExpandWidth(false));
 *      interaction.FadeOutTime = EditorGUILayout.FloatField("Fade out", interaction.FadeOutTime, GUILayout.Width(250), GUILayout.ExpandWidth(false));
 *      EditorGUI.indentLevel--;
 *      GUILayout.EndVertical();*/
    }
Пример #22
0
 public WorldStateProp GetWSProperty(E_PropKey key)
 {
     return((int)key < WorldStateProperties.Length ? WorldStateProperties[(int)key] : null);
 }
Пример #23
0
 public bool IsWSPropertySet(E_PropKey key)
 {
     return((int)key < WorldStateProperties.Length ? WorldStateProperties[(int)key] != null : false);
 }
Пример #24
0
 public bool IsWSPropertySet(E_PropKey key)
 {
     return(m_PropBitSet.Get((int)key));
 }
Пример #25
0
 public WorldStateProp GetWSProperty(E_PropKey key)
 {
     return(m_PropState[(int)key]);
 }
Пример #26
0
    public override int GetNumAStarNeighbours(AStarNode aStarNode)
    {
        if (aStarNode == null)         //If the node is invalid then there's no neighbours
        {
            return(0);
        }

        //New search about to occur, clear the previous neighbour records
        m_Neighbours.Clear();

        /**
         * Go through each world state property and test if it is in the goal and current state
         * If it isn't then we look through the actionEffects table and see if the actions for this effect can solve the goal state
         */
        AStarGOAPNode node = (AStarGOAPNode)aStarNode;

        WorldStateProp currProp;
        WorldStateProp goalProp;
        GOAPAction     action;

        for (E_PropKey i = 0; i < E_PropKey.Count; i++)
        {
            // First test if the effect isn't in both the goal and the current state

            if (!(node.CurrentState.IsWSPropertySet(i) && node.GoalState.IsWSPropertySet(i)))
            {
                continue;                 //If not skip this effect
            }

            /**
             * Now test if the two world state properties are the same
             * If not we continue
             */
            currProp = node.CurrentState.GetWSProperty(i);
            goalProp = node.GoalState.GetWSProperty(i);

            if (currProp != null && goalProp != null)
            {
                if (!(currProp == goalProp))
                {
                    for (int j = 0; j < m_EffectsTable[(int)i].Count; j++)
                    {
                        action = m_EffectsTable[(int)i][j];

                        //Are the context preconditions valid?
                        if (!action.ValidateContextPreconditions(node.CurrentState, true))
                        {
                            continue;
                        }

//                        UnityEngine.Debug.Log(action.ToString() + " adding to sousedi");
                        m_Neighbours.Add(action);
                    }
                }
            }
        }
        //Sort the returned neighbour actions by precedence
        PrecedenceComparer c = new PrecedenceComparer();

        m_Neighbours.Sort(c);

        return(m_Neighbours.Count);
    }