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))); }
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); } }
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)); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value - (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value - (Vector2)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Colour: Color c1 = (Color)first.Value; Color c2 = (Color)second.Value; stack.Push(new DmlObject(DmlType.Colour, new Color( c1.R - c2.R, c1.G - c2.G, c1.B - c2.B, c1.A - c2.A) )); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } }
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." ); } }
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)))); }
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))); }
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))); }
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)); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value / (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value / (float)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Colour, (Color)first.Value * (1 / (float)second.Value))); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } }
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. } }
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); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type != DmlType.Number || second.Type != DmlType.Number) { throw DmlSyntaxError.BadBinaryOperandTypes("<", first.Type, second.Type); } stack.Push(new DmlObject(DmlType.Bool, (double)(first.Value) < (double)(second.Value))); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type == DmlType.Number) { stack.Push(new DmlObject(DmlType.Number, Math.Abs((double)top.Value))); } else { throw DmlSyntaxError.BadUnaryOperandType("~", top.Type); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type == DmlType.Number && second.Type == DmlType.Number) { stack.Push(new DmlObject(DmlType.Number, (double)first.Value % (double)second.Value)); } else { throw DmlSyntaxError.BadBinaryOperandTypes("%", first.Type, second.Type); } }
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))); }
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) ))); }
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)); }
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); } }
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); } }
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); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type == DmlType.String) { stack.Push(new DmlObject(DmlType.String, (string)first.Value + second.Value.ToString())); } else if (first.Type == DmlType.List) { var old = (DmlObject[])first.Value; var @new = new DmlObject[old.Length + 1]; @new[old.Length] = second; for (int i = 0; i <= old.Length; i++) { @new[i] = old[i]; } stack.Push(new DmlObject(DmlType.List, @new)); } else if (second.Type == DmlType.String) { stack.Push(new DmlObject(DmlType.String, first.Value.ToString() + (string)second.Value)); } else if (second.Type == DmlType.List) { var old = (DmlObject[])second.Value; var @new = new DmlObject[old.Length + 1]; @new[0] = first; for (int i = 0; i <= old.Length; i++) { @new[i + 1] = old[i]; } stack.Push(new DmlObject(DmlType.List, @new)); } else { switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value + (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value + (Vector2)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Colour: Color c1 = (Color)first.Value; Color c2 = (Color)second.Value; stack.Push(new DmlObject(DmlType.Colour, new Color( c1.R + c2.R, c1.G + c2.G, c1.B + c2.B, c1.A + c2.A) )); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } } }