Ejemplo n.º 1
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            switch (top.Type)
            {
            case DmlType.Number:
                double p   = (double)top.Value;
                double val = (int)p;
                if (val != Math.Floor(p))
                {
                    throw new DmlSyntaxError(
                              "Invalid syntax; `Factorial` requires that argument one be an integer."
                              );
                }
                int factorial = 1;
                for (int i = 2; i < val; i++)
                {
                    factorial *= i;
                }
                top.Value = val;
                return(top);

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
            }
        }
Ejemplo n.º 2
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject amtObj   = stack.Pop();
            DmlObject endObj   = stack.Pop();
            DmlObject startObj = stack.Pop();

            if (startObj.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, startObj.Type);
            }

            if (endObj.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Vector, endObj.Type);
            }

            if (amtObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, amtObj.Type);
            }

            double  amt   = (double)(amtObj.Value);
            Vector2 end   = (Vector2)(endObj.Value);
            Vector2 start = (Vector2)(startObj.Value);

            return(new DmlObject(DmlType.Vector, Vector2.Lerp(start, end, (float)amt)));
        }
Ejemplo n.º 3
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            if (first.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, first.Type);
            }

            if (second.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, second.Type);
            }

            double  angle  = Math.PI / 180 * (double)(second.Value);
            Vector2 vec    = (Vector2)(first.Value);
            float   x      = vec.X;
            float   y      = vec.Y;
            float   cos    = (float)Math.Cos(angle);
            float   sin    = (float)Math.Sin(angle);
            var     newVec = new Vector2(x * cos - y * sin, x * sin + y * cos);

            newVec.Normalize(); // This avoids rounding errors that cause the bullets to eventually speed up.
            return(new DmlObject(DmlType.Vector, newVec));
        }
Ejemplo n.º 4
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            switch (argCount)
            {
            case 1:
                DmlObject top = stack.Pop();
                if (top.Type != DmlType.List)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
                }
                double low = Double.PositiveInfinity;

                try {
                    double val;
                    foreach (DmlObject v in (DmlObject[])top.Value)
                    {
                        val = (double)v.Value;
                        if (val <= low)
                        {
                            low = val;
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    throw new DmlSyntaxError(
                              "Invalid syntax; `Min` requires input array to be composed entirely of numbers."
                              );
                }
                return(new DmlObject(DmlType.Number, low));

            case 2:
                DmlObject second = stack.Pop();
                DmlObject first  = stack.Pop();

                if (first.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
                }

                else if (second.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

                return(new DmlObject(
                           DmlType.Number,
                           (double)first.Value < (double)second.Value ? first.Value : second.Value
                           ));

            default:
                throw new DmlSyntaxError(
                          "Invalid syntax; `Min` requires either 1 or 2 arguments."
                          );
            }
        }
Ejemplo n.º 5
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            if (top.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
            }
            double angle = Math.PI / 180 * (double)(top.Value);

            return(new DmlObject(DmlType.Vector, new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
        }
Ejemplo n.º 6
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            if (top.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, top.Type);
            }
            Vector2 vec = (Vector2)(top.Value);

            return(new DmlObject(DmlType.Vector, new Vector2(-vec.Y, vec.X)));
        }
Ejemplo n.º 7
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            if (top.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, top.Type);
            }
            Vector2 vec = (Vector2)(top.Value);

            return(new DmlObject(DmlType.Number, (double)Vector2.DistanceSquared(vec, Vector2.Zero)));
        }
Ejemplo n.º 8
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject timeObj = stack.Pop();

            if (timeObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, timeObj.Type);
            }
            double time  = (double)(timeObj.Value);
            double ltime = system.GlobalTime;

            return(new DmlObject(DmlType.Bool, ltime >= time));
        }
Ejemplo n.º 9
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject intervalObj;
            double    start, end, interval, ltime;

            switch (argCount)
            {
            case 1:
                intervalObj = stack.Pop();

                if (intervalObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type);
                }

                interval = (double)(stack.Pop().Value);
                ltime    = system.GlobalTime;
                return(new DmlObject(DmlType.Bool, (ltime % (2 * interval)) < interval));

            case 3:
                DmlObject endObj   = stack.Pop();
                DmlObject startObj = stack.Pop();
                intervalObj = stack.Pop();

                if (intervalObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type);
                }

                if (startObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, startObj.Type);
                }

                if (endObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, endObj.Type);
                }

                end      = (double)(stack.Pop().Value);
                start    = (double)(stack.Pop().Value);
                interval = (double)(stack.Pop().Value);
                ltime    = system.GlobalTime;
                double t2 = ltime - start;
                return(new DmlObject(DmlType.Bool,
                                     (t2 >= 0 && ltime <= end) && (t2 % (2 * interval)) < interval));

            default:
                return(null);    // Should never get here.
            }
        }
Ejemplo n.º 10
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            switch (top.Type)
            {
            case DmlType.Number:
                top.Value = Math.Exp((double)top.Value);
                return(top);

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
            }
        }
Ejemplo n.º 11
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            if (first.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }

            if (second.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
            }

            double y = (double)(second.Value);
            double x = (double)(first.Value);

            return(new DmlObject(DmlType.Vector, new Vector2((float)x, (float)y)));
        }
Ejemplo n.º 12
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            var time   = (DmlObject)(stack.Pop());
            var period = (DmlObject)(stack.Pop());
            var start  = (DmlObject)(stack.Pop());
            var max    = (DmlObject)(stack.Pop());
            var min    = (DmlObject)(stack.Pop());

            if (min.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, min.Type);
            }

            if (max.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, max.Type);
            }

            if (start.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, start.Type);
            }

            if (period.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 4, DmlType.Number, period.Type);
            }

            if (time.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 5, DmlType.Number, time.Type);
            }

            return(new DmlObject(DmlType.Number, _squareWave(
                                     (double)(min.Value),
                                     (double)(max.Value),
                                     (double)(start.Value),
                                     (double)(period.Value),
                                     (double)(time.Value)
                                     )));
        }
Ejemplo n.º 13
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject endObj   = stack.Pop();
            DmlObject startObj = stack.Pop();

            if (startObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, startObj.Type);
            }

            if (endObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, endObj.Type);
            }

            double end   = (double)(endObj.Value);
            double start = (double)(startObj.Value);
            double ltime = system.GlobalTime;

            return(new DmlObject(DmlType.Bool, start >= ltime && ltime > end));
        }
Ejemplo n.º 14
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    return(new DmlObject(DmlType.Number, 180 / Math.PI * Math.Atan2((double)first.Value, (double)second.Value)));

                default:
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }
Ejemplo n.º 15
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    return(new DmlObject(DmlType.Number, SpecialFunctions.YN((int)(double)first.Value, (double)second.Value)));

                default:
                    // throw new syntax error.
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }
Ejemplo n.º 16
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    var max = (double)(second.Value);
                    var min = (double)(first.Value);
                    return(new DmlObject(DmlType.Number, (max - min) * Globals.randGen.NextDouble() + min));

                default:
                    // throw new syntax error.
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }