Beispiel #1
0
            public void OnFlyByWire(ref FlightCtrlState c)
            {
                Expression e = cpu.GetDeepestChildContext().GetLock(propertyName);

                if (e != null)
                {
                    this.Value = e.GetValue();

                    if (propertyName == "throttle")
                    {
                        c.mainThrottle = (float)Value;
                    }
                    if (propertyName == "steering")
                    {
                        if (Value is String && ((string)Value).ToUpper() == "KILL")
                        {
                            SteeringHelper.KillRotation(c, vessel);
                        }
                        else if (Value is Direction)
                        {
                            SteeringHelper.SteerShipToward((Direction)Value, c, vessel);
                        }
                    }

                    if (cpu.GetLock(name) == null)
                    {
                        locked = false;
                    }
                }
            }
Beispiel #2
0
        public override void Evaluate()
        {
            Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext);

            StdOut(e.GetValue().ToString());

            State = ExecutionState.DONE;
        }
Beispiel #3
0
        public override void Evaluate()
        {
            // External functions are now handled within expressions,
            // so simply execute the expression and throw away the value
            Expression subEx = new Expression(RegexMatch.Groups[1].Value, this);
            subEx.GetValue();

            State = ExecutionState.DONE;
        }
Beispiel #4
0
            public void OnFlyByWire(ref FlightCtrlState c)
            {
                Expression e = cpu.GetDeepestChildContext().GetLock(propertyName);

                if (e != null)
                {
                    this.Value = e.GetValue();

                    if (propertyName == "throttle")
                    {
                        c.mainThrottle = (float)Value;
                    }

                    if (propertyName == "wheelthrottle")
                    {
                        c.wheelThrottle = (float)Value;
                    }

                    if (propertyName == "steering")
                    {
                        if (Value is String && ((string)Value).ToUpper() == "KILL")
                        {
                            SteeringHelper.KillRotation(c, vessel);
                        }
                        else if (Value is Direction)
                        {
                            SteeringHelper.SteerShipToward((Direction)Value, c, vessel);
                        }
                    }

                    if (propertyName == "wheelsteering")
                    {
                        if (Value is VesselTarget)
                        {
                            var bearing = VesselUtils.GetTargetBearing(vessel, ((VesselTarget)Value).target);

                            if (vessel.horizontalSrfSpeed > 0.1f)
                            {
                                if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), VesselUtils.GetVelocityHeading(vessel))) <= 90)
                                {
                                    c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1);
                                }
                                else
                                {
                                    c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1);
                                }
                            }
                        }
                    }

                    if (cpu.GetLock(name) == null)
                    {
                        locked = false;
                    }
                }
            }
Beispiel #5
0
        public void UpdateLock(String name)
        {
            Expression e = GetLock(name);

            if (e != null)
            {
                var v = FindVariable(name);
                v.Value = e.GetValue();
            }
        }
Beispiel #6
0
        public override void Evaluate()
        {
            // External functions are now handled within expressions,
            // so simply execute the expression and throw away the value
            Expression subEx = new Expression(RegexMatch.Groups[1].Value, this);

            subEx.GetValue();

            State = ExecutionState.DONE;
        }
Beispiel #7
0
        public override void Evaluate()
        {
            targetExpression = new Expression(RegexMatch.Groups[1].Value, ParentContext);
            targetCommand = Command.Get(RegexMatch.Groups[2].Value, ParentContext);

            if (!objToBool(targetExpression.GetValue(), out originalValue))
            {
                throw new kOSException("Value type error");
            }

            ParentContext.Lock(this);

            State = ExecutionState.DONE;
        }
Beispiel #8
0
        public override void Evaluate()
        {
            Expression ex = new Expression(RegexMatch.Groups[1].Value, this);
            object obj = ex.GetValue();

            if (obj is kOS.Node)
            {
                ((Node)obj).Remove();
            }
            else
            {
                throw new kOSException("Supplied object ineligible for removal", this);
            }

            State = ExecutionState.DONE;
        }
Beispiel #9
0
        public override void Evaluate()
        {
            Expression ex  = new Expression(RegexMatch.Groups[1].Value, this);
            object     obj = ex.GetValue();

            if (obj is kOS.Node)
            {
                ((Node)obj).Remove();
            }
            else
            {
                throw new kOSException("Supplied object ineligible for removal", this);
            }

            State = ExecutionState.DONE;
        }
Beispiel #10
0
        public override void Evaluate()
        {
            String   varName = RegexMatch.Groups[1].Value;
            Variable v       = FindOrCreateVariable(varName);

            if (v != null)
            {
                Expression e = new Expression(RegexMatch.Groups[3].Value, ParentContext);
                v.Value = e.GetValue();

                State = ExecutionState.DONE;
            }
            else
            {
                throw new kOSException("Can't find or create variable '" + varName + "'");
            }
        }
Beispiel #11
0
        public override void Evaluate()
        {
            String name = RegexMatch.Groups[1].Value;
            String paramString = RegexMatch.Groups[2].Value;

            var parameters = new List<String>();

            foreach (String param in Utils.ProcessParams(paramString))
            {
                Expression subEx = new Expression(param, this);
                parameters.Add(subEx.GetValue().ToString());
            }

            CallExternalFunction(name, parameters.ToArray());

            State = ExecutionState.DONE;
        }
Beispiel #12
0
        public override void Evaluate()
        {
            Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext);
            Expression ex = new Expression(RegexMatch.Groups[2].Value, ParentContext);
            Expression ey = new Expression(RegexMatch.Groups[3].Value, ParentContext);

            if (e.IsNull()) throw new kOSException("Null value in print statement");

            int x, y;

            if (Int32.TryParse(ex.GetValue().ToString(), out x) && Int32.TryParse(ey.GetValue().ToString(), out y))
            {
                Put(e.GetValue().ToString(), x, y);
            }
            else
            {
                throw new kOSException("Non-numeric value assigned to numeric function");
            }

            State = ExecutionState.DONE;
        }
Beispiel #13
0
        public override void Evaluate()
        {
            Term       targetTerm = new Term(RegexMatch.Groups[1].Value);
            Expression e          = new Expression(RegexMatch.Groups[2].Value, ParentContext);

            if (targetTerm.Type == Term.TermTypes.STRUCTURE)
            {
                object baseObj = new Expression(targetTerm.SubTerms[0], ParentContext).GetValue();

                if (baseObj is SpecialValue)
                {
                    if (((SpecialValue)baseObj).SetSuffix(targetTerm.SubTerms[1].Text.ToUpper(), e.GetValue()))
                    {
                        State = ExecutionState.DONE;
                        return;
                    }
                    else
                    {
                        throw new kOSException("Suffix '" + targetTerm.SubTerms[1].Text + "' doesn't exist or is read only", this);
                    }
                }
                else
                {
                    throw new kOSException("Can't set subvalues on a " + Expression.GetFriendlyNameOfItem(baseObj), this);
                }
            }
            else
            {
                Variable v = FindOrCreateVariable(targetTerm.Text);

                if (v != null)
                {
                    v.Value = e.GetValue();
                    State   = ExecutionState.DONE;
                    return;
                }
            }
        }
Beispiel #14
0
        public override void Evaluate()
        {
            Expression e  = new Expression(RegexMatch.Groups[1].Value, ParentContext);
            Expression ex = new Expression(RegexMatch.Groups[2].Value, ParentContext);
            Expression ey = new Expression(RegexMatch.Groups[3].Value, ParentContext);

            if (e.IsNull())
            {
                throw new kOSException("Null value in print statement");
            }

            int x, y;

            if (Int32.TryParse(ex.GetValue().ToString(), out x) && Int32.TryParse(ey.GetValue().ToString(), out y))
            {
                Put(e.GetValue().ToString(), x, y);
            }
            else
            {
                throw new kOSException("Non-numeric value assigned to numeric function");
            }

            State = ExecutionState.DONE;
        }
Beispiel #15
0
            public void OnFlyByWire(ref FlightCtrlState c)
            {
                Expression e = cpu.GetDeepestChildContext().GetLock(propertyName);

                if (e != null)
                {
                    Value = e.GetValue();

                    if (propertyName == "throttle")
                    {
                        c.mainThrottle = (float)e.Double();
                    }

                    if (propertyName == "wheelthrottle")
                    {
                        c.wheelThrottle = (float)Utils.Clamp(e.Double(), -1, 1);
                    }

                    if (propertyName == "steering")
                    {
                        if (Value is String && ((string)Value).ToUpper() == "KILL")
                        {
                            SteeringHelper.KillRotation(c, vessel);
                        }
                        else if (Value is Direction)
                        {
                            SteeringHelper.SteerShipToward((Direction)Value, c, vessel);
                        }
                        else if (Value is Vector)
                        {
                            SteeringHelper.SteerShipToward(((Vector)Value).ToDirection(), c, vessel);
                        }
                        else if (Value is Node)
                        {
                            SteeringHelper.SteerShipToward(((Node)Value).GetBurnVector().ToDirection(), c, vessel);
                        }
                    }

                    if (propertyName == "wheelsteering")
                    {
                        float bearing = 0;

                        if (Value is VesselTarget)
                        {
                            bearing = VesselUtils.GetTargetBearing(vessel, ((VesselTarget)Value).target);
                        }
                        else if (Value is GeoCoordinates)
                        {
                            bearing = ((GeoCoordinates)Value).GetBearing(vessel);
                        }
                        else if (Value is double)
                        {
                            bearing = (float)(Math.Round((double)Value) - Mathf.Round(FlightGlobals.ship_heading));
                        }

                        if (vessel.horizontalSrfSpeed > 0.1f)
                        {
                            if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), VesselUtils.GetVelocityHeading(vessel))) <= 90)
                            {
                                c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1);
                            }
                            else
                            {
                                c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1);
                            }
                        }
                    }

                    if (cpu.GetLock(name) == null)
                    {
                        locked = false;
                    }
                }
            }
Beispiel #16
0
        public override void Evaluate()
        {
            Expression e = new Expression(RegexMatch.Groups[1].Value, ParentContext);

            StdOut(e.GetValue().ToString());

            State = ExecutionState.DONE;
        }
Beispiel #17
0
        public static String Evaluate(String text, ExecutionContext context)
        {
            Expression e = new Expression(text, context);

            return(e.GetValue().ToString());
        }
Beispiel #18
0
 public static String Evaluate(String text, ExecutionContext context)
 {
     Expression e = new Expression(text, context);
     return e.GetValue().ToString();
 }
Beispiel #19
0
        // Evaluate and return the value of the part of an expression that this instance represents
        public object GetValue()
        {
            if (EvalDlg != null)
            {
                EvalDlg();
            }

            if (SpecialValue != null)
            {
                if (string.IsNullOrEmpty(Suffix))
                {
                    return(SpecialValue.ToString());
                }
                else
                {
                    return(SpecialValue.GetSuffix(Suffix));
                }
            }

            if (LeftSide == null)
            {
                if (Variable != null && !IsStatic)
                {
                    return(Variable.Value);
                }
                else
                {
                    return(Value);
                }
            }
            else
            {
                if (Operator == "AND")
                {
                    return(LeftSide.Bool() && RightSide.Bool());
                }
                if (Operator == "OR")
                {
                    return(LeftSide.Bool() || RightSide.Bool());
                }

                if (LeftSide.Value is String || RightSide.Value is String)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Value.ToString() + RightSide.Value.ToString());
                    }

                    if (Operator == "==")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Value.ToString() != RightSide.Value.ToString());
                    }
                }

                if (LeftSide.Value is float || RightSide.Value is float)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Float() + RightSide.Float());
                    }
                    if (Operator == "-")
                    {
                        return(LeftSide.Float() - RightSide.Float());
                    }
                    if (Operator == "/")
                    {
                        return(LeftSide.Float() / RightSide.Float());
                    }
                    if (Operator == "*")
                    {
                        return(LeftSide.Float() * RightSide.Float());
                    }
                    if (Operator == "^")
                    {
                        return((float)Math.Pow(LeftSide.Double(), RightSide.Double()));
                    }

                    if (Operator == "<")
                    {
                        return(LeftSide.Float() < RightSide.Float());
                    }
                    if (Operator == ">")
                    {
                        return(LeftSide.Float() > RightSide.Float());
                    }
                    if (Operator == "<=")
                    {
                        return(LeftSide.Float() <= RightSide.Float());
                    }
                    if (Operator == ">=")
                    {
                        return(LeftSide.Float() >= RightSide.Float());
                    }
                    if (Operator == "==")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Float() != RightSide.Float());
                    }
                }

                if (LeftSide.Value is Direction && RightSide.Value is Direction)
                {
                    if (Operator == "*")
                    {
                        return((Direction)LeftSide.GetValue() * (Direction)RightSide.GetValue());
                    }
                    if (Operator == "+")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                    if (Operator == "-")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                }
            }

            throw new kOSException("Expression error.");
        }
Beispiel #20
0
        public override void Evaluate()
        {
            Term targetTerm = new Term(RegexMatch.Groups[1].Value);
            Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext);

            if (targetTerm.Type == Term.TermTypes.STRUCTURE)
            {
                object baseObj = new Expression(targetTerm.SubTerms[0], ParentContext).GetValue();

                if (baseObj is SpecialValue)
                {
                    if (((SpecialValue)baseObj).SetSuffix(targetTerm.SubTerms[1].Text.ToUpper(), e.GetValue()))
                    {
                        State = ExecutionState.DONE;
                        return;
                    }
                    else
                    {
                        throw new kOSException("Suffix '" + targetTerm.SubTerms[1].Text + "' doesn't exist or is read only", this);
                    }
                }
                else
                {
                    throw new kOSException("Can't set subvalues on a " + Expression.GetFriendlyNameOfItem(baseObj), this);
                }
            }
            else
            {
                Variable v = FindOrCreateVariable(targetTerm.Text);

                if (v != null)
                {
                    v.Value = e.GetValue();
                    State = ExecutionState.DONE;
                    return;
                }
            }
        }
Beispiel #21
0
        public override void Evaluate()
        {
            String varName = RegexMatch.Groups[1].Value;
            Variable v = FindOrCreateVariable(varName);

            if (v != null)
            {
                Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext);
                v.Value = e.GetValue();

                State = ExecutionState.DONE;
            }
            else
            {
                throw new kOSException("Can't find or create variable '" + varName + "'");
            }
        }