/// <summary> /// Konstruktor. Erstellt ein Segel mit dem angegebenen Typ, indem die entsprechenden SLPs geladen werden. /// </summary> /// <param name="type">Der Typ des zu erstellenden Segels.</param> /// <param name="graphicsDrs">Die Graphics-DRS.</param> public Sail(SailType type, DRSLibrary.DRSFile graphicsDrs) : this() { // Passende Segel in Liste einfügen if (type == SailType.MainGo) { // Hauptsegel Fahren SailSlps.Add(ShipFile.Civ.AS, new SLPFile(new RAMBuffer(Properties.Resources.MainGo_AS))); SailSlps.Add(ShipFile.Civ.IN, new SLPFile(new RAMBuffer(Properties.Resources.MainGo_IN))); SailSlps.Add(ShipFile.Civ.ME, new SLPFile(new RAMBuffer(Properties.Resources.MainGo_ME))); SailSlps.Add(ShipFile.Civ.OR, new SLPFile(new RAMBuffer(Properties.Resources.MainGo_OR))); SailSlps.Add(ShipFile.Civ.WE, new SLPFile(new RAMBuffer(Properties.Resources.MainGo_WE))); } else if (type == SailType.MainStop) { // Hauptsegel Stehen SailSlps.Add(ShipFile.Civ.AS, new SLPFile(new RAMBuffer(Properties.Resources.MainStop_AS))); SailSlps.Add(ShipFile.Civ.IN, new SLPFile(new RAMBuffer(Properties.Resources.MainStop_IN))); SailSlps.Add(ShipFile.Civ.ME, new SLPFile(new RAMBuffer(Properties.Resources.MainStop_ME))); SailSlps.Add(ShipFile.Civ.OR, new SLPFile(new RAMBuffer(Properties.Resources.MainStop_OR))); SailSlps.Add(ShipFile.Civ.WE, new SLPFile(new RAMBuffer(Properties.Resources.MainStop_WE))); } else { foreach (var currSail in SAIL_RESOURCE_IDs) { if (currSail.Item1 == type) { SailSlps.Add(currSail.Item2, new SLPFile(new RAMBuffer(graphicsDrs.GetResourceData(currSail.Item3)))); } } } }
public IExpression Parse(Parser parser, Token token, IExpression left) { if (!(left is IdentifierExpression)) { ErrorManager.CreateError("Explicit variable declaration syntax: name : type = value", ErrorType.Error, token.Line, token.Column); return(null); } var value = parser.ParseExpression(GetPrecedence() - 1); SailType type = SailType.UNKNOWN; if (value is BoolLiteralExpression || value is StringLiteralExpression || value is FloatLiteralExpression || value is IntLiteralExpression) { type = TypeResolver.ToSailType(value as ILiteralExpression); } else if (value is FunctionCallExpression) { type = SailType.UNKNOWN; } else if (value is ComparisonExpression) { type = SailType.BOOL; } else { throw new Exception("Incorrect explicit variable declaration syntax!"); } return(new AssignmentExpression(token.Line, token.Column, left, value, type)); }
public VarDeclarationNoAssignExpression(int line, int column, string name, SailType type) { Name = name; Type = type; Line = line; Column = column; }
public Sail(SailType sailType, float height, float width, float depth, float boomHeight) { _sailType = sailType; _boomHeight = boomHeight; _height = height; _width = width; _depth = depth; _offset = 0; _needsBuild = true; }
public Sail(SailType sailType,float height, float width,float depth,float boomHeight) { _sailType = sailType; _boomHeight = boomHeight; _height = height; _width = width; _depth = depth; _offset = 0; _needsBuild = true; }
public AssignmentExpression(int line, int column, IExpression name, IExpression value, SailType type, SailType expectedType = SailType.UNKNOWN) { Name = name; Value = value; Type = type; ExpectedType = expectedType; Line = line; Column = column; }
public void Visit(FunctionCallExpression funcCall) { _functionVariables.Clear(); var funcToCall = _functions.FirstOrDefault(f => f.Name == funcCall.FunctionName); foreach (var v in funcCall.Parameters) { object value = null; SailType type = SailType.UNKNOWN; if (v is IdentifierExpression) { var variable = _variables.FirstOrDefault(va => va.Name == (v as IdentifierExpression).Value); if (variable == null) { ErrorManager.CreateError("Argument passed to function doesn't exist!", ErrorType.Error, funcCall.Line, funcCall.Column); return; } value = variable.Value; type = variable.Type; } else if (v is ILiteralExpression) { var literal = v as ILiteralExpression; type = TypeResolver.ToSailType(literal); value = literal.GetValue(); } else if (v is ComparisonExpression) { Visit(v); type = SailType.BOOL; value = (bool)_comparisonResults.Pop().Value; } else { ErrorManager.CreateError("Argument passed to function must be a variable name or value!", ErrorType.Error, funcCall.Line, funcCall.Column); return; } _functionVariables.Push(new SailObject(null, value, type)); } if (funcCall != null) { funcToCall.Invoke(this); } }
public SailObject(string name, object value, SailType type) { Value = value; Type = type; Name = name; }
public AsCastExpression(IExpression left, SailType type) { }
public void Visit(MathsExpression maths) { object leftVal = null; object rightVal = null; SailType resultType = SailType.UNKNOWN; // Left if (maths.Left is IntLiteralExpression) { leftVal = ((IntLiteralExpression)maths.Left).Value; resultType = SailType.INT; } else if (maths.Left is FloatLiteralExpression) { leftVal = ((FloatLiteralExpression)maths.Left).Value; resultType = SailType.FLOAT; } else if (maths.Left is IdentifierExpression) { string name = ((IdentifierExpression)maths.Left).Value; var variable = _variables.FirstOrDefault(v => v.Name == name); if (variable == null) { ErrorManager.CreateError("Can't compare non-existant variable!", ErrorType.Error, maths.Left.Line, maths.Left.Column); return; } if (variable.Value == null) { ErrorManager.CreateError("Can't compare null valued variable!", ErrorType.Error, maths.Left.Line, maths.Left.Column); return; } leftVal = variable.Value; resultType = variable.Type; } else if (maths.Left is MathsExpression) { Visit(maths.Left); var mathsValue = _mathsResults.Pop(); rightVal = mathsValue.Value; resultType = mathsValue.Type; } // Right if (maths.Right is IntLiteralExpression) { rightVal = ((IntLiteralExpression)maths.Right).Value; resultType = SailType.INT; } else if (maths.Right is FloatLiteralExpression) { rightVal = ((FloatLiteralExpression)maths.Right).Value; resultType = SailType.FLOAT; } else if (maths.Right is IdentifierExpression) { string name = ((IdentifierExpression)maths.Right).Value; var variable = _variables.FirstOrDefault(v => v.Name == name); if (variable == null) { ErrorManager.CreateError("Can't compare non-existant variable!", ErrorType.Error, maths.Right.Line, maths.Right.Column); return; } if (variable.Value == null) { ErrorManager.CreateError("Can't compare null valued variable!", ErrorType.Error, maths.Right.Line, maths.Right.Column); return; } rightVal = variable.Value; resultType = variable.Type; } else if (maths.Right is MathsExpression) { Visit(maths.Right); var mathsValue = _mathsResults.Pop(); rightVal = mathsValue.Value; resultType = mathsValue.Type; } object value = null; switch (maths.OperatorType) { case TokenType.PLUS: value = Convert.ToSingle(leftVal) + Convert.ToSingle(rightVal); break; case TokenType.MINUS: value = Convert.ToSingle(leftVal) - Convert.ToSingle(rightVal); break; case TokenType.ASTERISK: value = Convert.ToSingle(leftVal) * Convert.ToSingle(rightVal); break; case TokenType.FSLASH: value = Convert.ToSingle(leftVal) / Convert.ToSingle(rightVal); break; case TokenType.MODULO: value = Convert.ToSingle(leftVal) % Convert.ToSingle(rightVal); break; } _mathsResults.Push(new SailObject(null, value, resultType)); }