示例#1
0
        //Planning Methods ===========-
        public void SetGoal(string variable_name, Property_GS variable)
        {
            Property_GS current_property = null;

            if (_world_state.TryGetValue(variable_name, out current_property))
            {
                //Apply the target variable operation to the current property value
                //If the variable is linked we get the current world value
                Property_GS cur_target_property = null;
                if (string.IsNullOrEmpty(variable.B_key) == false)
                {
                    _world_state.TryGetValue(variable.B_key, out cur_target_property);
                    cur_target_property.operator_type = variable.operator_type;
                }
                if (cur_target_property == null)
                {
                    current_property.ApplyPropertyEffect(variable);
                }
                else
                {
                    current_property.ApplyPropertyEffect(cur_target_property);
                }
            }
            else
            {
                Property_GS new_variable = new Property_GS(variable);
                _world_state.Add(variable_name, new_variable);
            }
        }
示例#2
0
 public Property_GS(Property_GS copy)
 {
     _variable_type  = copy.variable_type;
     _A_key          = copy.A_key;
     _operator       = copy.operator_type;
     _B_key          = copy.B_key;
     _value          = copy.value;
     _planning_value = copy._planning_value;
 }
示例#3
0
        public Property_GS GetProperty(string name)
        {
            Property_GS found_prop = null;

            if (!_world_state.TryGetValue(name, out found_prop))
            {
                Debug.LogError("Property: " + name + " not found in the world state: " + _name);
            }
            return(found_prop);
        }
示例#4
0
        //Planning Methods ============
        public float DistanceTo(Property_GS target_property, bool no_dist = false)
        {
            //Check if the target properties have the same variable type
            if (_variable_type != target_property.variable_type)
            {
                Debug.LogError("Comparsion type between variable: " + _variable_type + " and variable: " + target_property.variable_type + " not supported!");
                return(float.MaxValue);
            }

            //Check if this property value have the defined value by the target property
            //Do different operations depending of the operator type
            switch (target_property.operator_type)
            {
            case OperatorType._is_equal:
            case OperatorType._equal_equal:
            {
                switch (_variable_type)
                {
                case VariableType._string: return(string.Compare((string)_value, (string)target_property.value) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._bool: return(((bool)_value == (bool)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._char: return(((char)_value == (char)target_property.value ? 0.0f : Mathf.Abs((char)_value - (char)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value == (float)target_property.value ? 0.0f : Mathf.Abs((float)_value - (float)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)_value == (int)target_property.value ? 0.0f : Mathf.Abs((int)_value - (int)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return(((Vector2)_value == (Vector2)target_property.value ? 0.0f : Vector2.Distance((Vector2)_value, (Vector2)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return(((Vector3)_value == (Vector3)target_property.value ? 0.0f : Vector3.Distance((Vector3)_value, (Vector3)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return(((Vector4)_value == (Vector4)target_property.value ? 0.0f : Vector4.Distance((Vector4)_value, (Vector4)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;

            case OperatorType._different:
            {
                switch (_variable_type)
                {
                case VariableType._string: return((string.Compare((string)_value, (string)target_property.value) != 0 ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._bool: return(((bool)_value != (bool)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._char: return(((char)_value != (char)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value != (float)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)_value != (int)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return(((Vector2)_value != (Vector2)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return(((Vector3)value != (Vector3)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return(((Vector4)_value != (Vector4)target_property.value ? 0.0f : 1.0f) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;

            case OperatorType._bigger:
            {
                switch (_variable_type)
                {
                case VariableType._char: return(((char)_value > (char)target_property.value ? 0.0f : Mathf.Abs((char)_value - (char)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value > (float)target_property.value ? 0.0f : Mathf.Abs((float)_value - (float)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)value > (int)target_property.value ? 0.0f : Mathf.Abs((int)_value - (int)target_property.value) <= 0 ? 1 : Mathf.Abs((int)_value - (int)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return((((Vector2)_value).magnitude > ((Vector2)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector2)_value).magnitude - ((Vector2)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return((((Vector3)_value).magnitude > ((Vector3)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector3)_value).magnitude - ((Vector3)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return((((Vector4)_value).magnitude > ((Vector4)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector4)_value).magnitude - ((Vector4)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;

            case OperatorType._bigger_or_equal:
            {
                switch (_variable_type)
                {
                case VariableType._char: return(((char)_value >= (char)target_property.value ? 0.0f : Mathf.Abs((char)_value - (char)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value >= (float)target_property.value ? 0.0f : Mathf.Abs((float)_value - (float)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)_value >= (int)target_property.value ? 0.0f : Mathf.Abs((int)_value - (int)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return((((Vector2)_value).magnitude >= ((Vector2)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector2)_value).magnitude - ((Vector2)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return((((Vector3)_value).magnitude >= ((Vector3)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector3)_value).magnitude - ((Vector3)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return((((Vector4)_value).magnitude >= ((Vector4)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector4)_value).magnitude - ((Vector4)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;

            case OperatorType._smaller:
            {
                switch (_variable_type)
                {
                case VariableType._char: return(((char)_value < (char)target_property.value ? 0.0f : Mathf.Abs((char)_value - (char)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value < (float)target_property.value ? 0.0f : Mathf.Abs((float)_value - (float)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)_value < (int)target_property.value ? 0.0f : Mathf.Abs((int)_value - (int)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return((((Vector2)_value).magnitude < ((Vector2)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector2)_value).magnitude - ((Vector2)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return((((Vector3)_value).magnitude < ((Vector3)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector3)_value).magnitude - ((Vector3)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return((((Vector4)_value).magnitude < ((Vector4)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector4)_value).magnitude - ((Vector4)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;

            case OperatorType._smaller_or_equal:
            {
                switch (_variable_type)
                {
                case VariableType._char: return(((char)_value <= (char)target_property.value ? 0.0f : Mathf.Abs((char)_value - (char)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._float: return(((float)_value <= (float)target_property.value ? 0.0f : Mathf.Abs((float)_value - (float)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._int: return(((int)_value <= (int)target_property.value ? 0.0f : Mathf.Abs((int)_value - (int)target_property.value)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector2: return((((Vector2)_value).magnitude <= ((Vector2)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector2)_value).magnitude - ((Vector2)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector3: return((((Vector3)_value).magnitude <= ((Vector3)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector3)_value).magnitude - ((Vector3)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));

                case VariableType._vector4: return((((Vector4)_value).magnitude <= ((Vector4)target_property.value).magnitude ? 0.0f : Mathf.Abs(((Vector4)_value).magnitude - ((Vector4)target_property.value).magnitude)) * (no_dist == true ? 1.0f : _planning_value));
                }
            }
            break;
            }
            //In non valid operator type return false
            Debug.LogError("Variable: current " + _A_key + " " + operator_type.ToShortString() + " goal " + target_property.A_key + " is not a valid operation!");
            return(float.MaxValue);
        }
示例#5
0
        public void ApplyPropertyEffect(Property_GS target)
        {
            switch (target.operator_type)
            {
            case OperatorType._equal_equal:
            {
                Debug.LogError("UEP!");

                operator_type = target.operator_type;
                value         = target.value;
            }
            break;

            case OperatorType._is_equal:
            case OperatorType._bigger_or_equal:
            case OperatorType._smaller_or_equal:
            {
                operator_type = target.operator_type;
                value         = target.value;
            }
            break;

            case OperatorType._minus_equal:
            {
                switch (_variable_type)
                {
                case VariableType._char: _value = (char)_value - (char)target.value; return;

                case VariableType._float: _value = (float)_value - (float)target.value; return;

                case VariableType._int: _value = (int)_value - (int)target.value; return;

                case VariableType._vector2: _value = (Vector2)_value - (Vector2)target.value; return;

                case VariableType._vector3: _value = (Vector3)_value - (Vector3)target.value; return;

                case VariableType._vector4: _value = (Vector4)_value - (Vector4)target.value; return;
                }
            }
            break;

            case OperatorType._plus_equal:
            {
                switch (_variable_type)
                {
                case VariableType._char: _value = (char)_value + (char)target.value; return;

                case VariableType._float: _value = (float)_value + (float)target.value; return;

                case VariableType._int: _value = (int)_value + (int)target.value; return;

                case VariableType._vector2: _value = (Vector2)_value + (Vector2)target.value; return;

                case VariableType._vector3: _value = (Vector3)_value + (Vector3)target.value; return;

                case VariableType._vector4: _value = (Vector4)_value + (Vector4)target.value; return;
                }
            }
            break;
            }
        }