Ejemplo n.º 1
0
        private static IEnumerable <TStatementSyntax> GetStatements(TBuilder builder)
        {
            var mapInfo = builder.Data.MapInfo;

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Common.SetCameraBounds),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Addition,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.BottomLeft.X),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_LEFT)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Addition,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.BottomLeft.Y),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_BOTTOM)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Subtraction,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.TopRight.X),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_RIGHT)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Subtraction,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.TopRight.Y),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_TOP)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Addition,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.TopLeft.X),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_LEFT)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Subtraction,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.TopLeft.Y),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_TOP)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Subtraction,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.BottomRight.X),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_RIGHT)))),
                             builder.GenerateBinaryExpression(
                                 BinaryOperator.Addition,
                                 builder.GenerateFloatLiteralExpression(mapInfo.CameraBounds.BottomRight.Y),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.GetCameraMargin),
                                     builder.GenerateVariableExpression(nameof(War3Api.Common.CAMERA_MARGIN_BOTTOM))))));

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Common.SetDayNightModels),
                             builder.GenerateEscapedStringLiteralExpression(LightEnvironmentProvider.GetTerrainLightEnvironmentModel(mapInfo.LightEnvironment)),
                             builder.GenerateEscapedStringLiteralExpression(LightEnvironmentProvider.GetUnitLightEnvironmentModel(mapInfo.LightEnvironment))));

            if (mapInfo.MapFlags.HasFlag(MapFlags.HasTerrainFog))
            {
                yield return(builder.GenerateInvocationStatement(
                                 nameof(War3Api.Common.SetTerrainFogEx),
                                 builder.GenerateIntegerLiteralExpression((int)mapInfo.FogStyle),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogStartZ),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogEndZ),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogDensity),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogColor.R / 255f),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogColor.G / 255f),
                                 builder.GenerateFloatLiteralExpression(mapInfo.FogColor.B / 255f)));
            }

            if (mapInfo.GlobalWeather != WeatherType.None)
            {
                // TODO: use GetWorldBounds or get coords from w3i/w3e
                yield return(builder.GenerateInvocationStatement(
                                 nameof(War3Api.Common.EnableWeatherEffect),
                                 builder.GenerateInvocationExpression(
                                     nameof(War3Api.Common.AddWeatherEffect),
                                     builder.GenerateInvocationExpression(
                                         nameof(War3Api.Common.Rect),
                                         builder.GenerateFloatLiteralExpression(-999999),
                                         builder.GenerateFloatLiteralExpression(-999999),
                                         builder.GenerateFloatLiteralExpression(999999),
                                         builder.GenerateFloatLiteralExpression(999999)),
                                     builder.GenerateIntegerLiteralExpression((int)mapInfo.GlobalWeather)),
                                 builder.GenerateBooleanLiteralExpression(true)));
            }

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Common.NewSoundEnvironment),
                             builder.GenerateEscapedStringLiteralExpression(mapInfo.SoundEnvironment)));

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Blizzard.SetAmbientDaySound),
                             builder.GenerateEscapedStringLiteralExpression(SoundEnvironmentProvider.GetAmbientDaySound(mapInfo.Tileset))));

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Blizzard.SetAmbientNightSound),
                             builder.GenerateEscapedStringLiteralExpression(SoundEnvironmentProvider.GetAmbientNightSound(mapInfo.Tileset))));

            yield return(builder.GenerateInvocationStatement(
                             nameof(War3Api.Common.SetMapMusic),
                             builder.GenerateEscapedStringLiteralExpression(MusicName),
                             builder.GenerateBooleanLiteralExpression(MusicRandom),
                             builder.GenerateIntegerLiteralExpression(MusicIndex)));

            var mapSounds  = builder.Data.MapSounds;
            var mapRegions = builder.Data.MapRegions;
            var mapDoodads = builder.Data.MapDoodads;
            var mapUnits   = builder.Data.MapUnits;

            if (WantGenerateSoundsHelperFunction(mapSounds))
            {
                yield return(builder.GenerateInvocationStatement("InitSounds"));
            }

            if (WantGenerateRegionsHelperFunction(mapRegions))
            {
                yield return(builder.GenerateInvocationStatement("CreateRegions"));
            }

            if (WantGenerateCamerasHelperFunction(null))
            {
                yield return(builder.GenerateInvocationStatement("CreateCameras"));
            }

            if (WantGenerateUpgradesHelperFunction(mapInfo))
            {
                yield return(builder.GenerateInvocationStatement("InitUpgrades"));
            }

            if (WantGenerateTechTreeHelperFunction(mapInfo))
            {
                yield return(builder.GenerateInvocationStatement("InitTechTree"));
            }

            if (WantGenerateDestructablesHelperFunction(mapDoodads))
            {
                yield return(builder.GenerateInvocationStatement("CreateAllDestructables"));
            }

            if (WantGenerateItemsHelperFunction(mapUnits))
            {
                yield return(builder.GenerateInvocationStatement("CreateAllItems"));
            }

            if (WantGenerateUnitsHelperFunction(mapUnits))
            {
                yield return(builder.GenerateInvocationStatement("CreateAllUnits"));
            }

            yield return(builder.GenerateInvocationStatement(nameof(War3Api.Blizzard.InitBlizzard)));

            if (builder.Data.CSharp)
            {
                yield return(builder.GenerateInvocationStatement(CSharpLua.LuaSyntaxGenerator.kManifestFuncName));
            }
        }
Ejemplo n.º 2
0
        private FunctionSyntax GetMainFunctionSyntax(float left, float right, float top, float bottom, Tileset tileset, SoundEnvironment sound, params string[] initFunctions)
        {
            var statements = new List <NewStatementSyntax>()
            {
                JassSyntaxFactory.CallStatement(
                    "SetCameraBounds",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.VariableExpression("left"),
                        JassSyntaxFactory.VariableExpression("bottom"),
                        JassSyntaxFactory.VariableExpression("right"),
                        JassSyntaxFactory.VariableExpression("top"),
                        JassSyntaxFactory.VariableExpression("left"),
                        JassSyntaxFactory.VariableExpression("top"),
                        JassSyntaxFactory.VariableExpression("right"),
                        JassSyntaxFactory.VariableExpression("bottom"))),
                JassSyntaxFactory.CallStatement(
                    "SetDayNightModels",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.ConstantExpression(LightEnvironmentProvider.GetTerrainLightEnvironmentModel(tileset)),
                        JassSyntaxFactory.ConstantExpression(LightEnvironmentProvider.GetUnitLightEnvironmentModel(tileset)))),
                JassSyntaxFactory.CallStatement(
                    "NewSoundEnvironment",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetSoundEnvironment(sound))),
                JassSyntaxFactory.CallStatement(
                    "SetAmbientDaySound",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetAmbientDaySound(tileset))),
                JassSyntaxFactory.CallStatement(
                    "SetAmbientNightSound",
                    JassSyntaxFactory.ConstantExpression(SoundEnvironmentProvider.GetAmbientNightSound(tileset))),
                JassSyntaxFactory.CallStatement(
                    "SetMapMusic",
                    JassSyntaxFactory.ArgumentList(
                        JassSyntaxFactory.ConstantExpression("Music"),
                        JassSyntaxFactory.ConstantExpression(true),
                        JassSyntaxFactory.ConstantExpression(0))),
            };

            foreach (var initFunction in initFunctions)
            {
                statements.Add(JassSyntaxFactory.CallStatement(initFunction));
            }

            return(JassSyntaxFactory.Function(
                       JassSyntaxFactory.FunctionDeclaration("main"),
                       JassSyntaxFactory.LocalVariableList(
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "left",
                               JassSyntaxFactory.BinaryAdditionExpression(
                                   JassSyntaxFactory.ConstantExpression(left),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_LEFT"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "right",
                               JassSyntaxFactory.BinarySubtractionExpression(
                                   JassSyntaxFactory.ConstantExpression(right),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_RIGHT"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "top",
                               JassSyntaxFactory.BinarySubtractionExpression(
                                   JassSyntaxFactory.ConstantExpression(top),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_TOP"))))),
                           JassSyntaxFactory.VariableDefinition(
                               JassSyntaxFactory.ParseTypeName("real"),
                               "bottom",
                               JassSyntaxFactory.BinaryAdditionExpression(
                                   JassSyntaxFactory.ConstantExpression(bottom),
                                   JassSyntaxFactory.InvocationExpression(
                                       "GetCameraMargin",
                                       JassSyntaxFactory.ArgumentList(JassSyntaxFactory.VariableExpression("CAMERA_MARGIN_BOTTOM")))))),
                       statements.ToArray()));
        }
Ejemplo n.º 3
0
        protected virtual JassFunctionDeclarationSyntax main(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapEnvironment = map.Environment;
            var mapInfo        = map.Info;

            var statements = new List <IStatementSyntax>();

            if (UseWeatherEffectVariable && EnableGlobalWeatherEffectCondition(map))
            {
                statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(TypeName.WeatherEffect), VariableName.WeatherEffect));
            }

            if (mapInfo.CameraBoundsComplements is null)
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetCameraBounds,
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.BottomLeft.X, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.BottomLeft.Y, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.TopRight.X, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.TopRight.Y, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.TopLeft.X, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.TopLeft.Y, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.BottomRight.X, precision: 1),
                                   SyntaxFactory.LiteralExpression(mapInfo.CameraBounds.BottomRight.Y, precision: 1)));
            }
            else
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetCameraBounds,
                                   SyntaxFactory.BinaryAdditionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Left + (128 * mapInfo.CameraBoundsComplements.Left), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Left))),
                                   SyntaxFactory.BinaryAdditionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Bottom + (128 * mapInfo.CameraBoundsComplements.Bottom), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Bottom))),
                                   SyntaxFactory.BinarySubtractionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Right - (128 * mapInfo.CameraBoundsComplements.Right), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Right))),
                                   SyntaxFactory.BinarySubtractionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Top - (128 * mapInfo.CameraBoundsComplements.Top), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Top))),
                                   SyntaxFactory.BinaryAdditionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Left + (128 * mapInfo.CameraBoundsComplements.Left), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Left))),
                                   SyntaxFactory.BinarySubtractionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Top - (128 * mapInfo.CameraBoundsComplements.Top), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Top))),
                                   SyntaxFactory.BinarySubtractionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Right - (128 * mapInfo.CameraBoundsComplements.Right), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Right))),
                                   SyntaxFactory.BinaryAdditionExpression(
                                       SyntaxFactory.LiteralExpression(mapEnvironment.Bottom + (128 * mapInfo.CameraBoundsComplements.Bottom), precision: 1),
                                       SyntaxFactory.InvocationExpression(NativeName.GetCameraMargin, SyntaxFactory.VariableReferenceExpression(CameraMarginName.Bottom)))));
            }

            if (SetDayNightModelsCondition(map))
            {
                var lightEnvironment = mapInfo.LightEnvironment == Tileset.Unspecified ? mapInfo.Tileset : mapInfo.LightEnvironment;
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetDayNightModels,
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(LightEnvironmentProvider.GetTerrainLightEnvironmentModel(lightEnvironment))),
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(LightEnvironmentProvider.GetUnitLightEnvironmentModel(lightEnvironment)))));
            }

            if (SetTerrainFogExCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetTerrainFogEx,
                                   SyntaxFactory.LiteralExpression((int)mapInfo.FogStyle),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogStartZ),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogEndZ),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogDensity),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogColor.R / 255f),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogColor.G / 255f),
                                   SyntaxFactory.LiteralExpression(mapInfo.FogColor.B / 255f)));
            }

            if (SetWaterBaseColorCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetWaterBaseColor,
                                   SyntaxFactory.LiteralExpression(mapInfo.WaterTintingColor.R),
                                   SyntaxFactory.LiteralExpression(mapInfo.WaterTintingColor.G),
                                   SyntaxFactory.LiteralExpression(mapInfo.WaterTintingColor.B),
                                   SyntaxFactory.LiteralExpression(mapInfo.WaterTintingColor.A)));
            }

            if (EnableGlobalWeatherEffectCondition(map))
            {
                var createWeather = SyntaxFactory.InvocationExpression(
                    NativeName.AddWeatherEffect,
                    SyntaxFactory.InvocationExpression(
                        NativeName.Rect,
                        SyntaxFactory.LiteralExpression(mapEnvironment.Left, precision: 1),
                        SyntaxFactory.LiteralExpression(mapEnvironment.Bottom, precision: 1),
                        SyntaxFactory.LiteralExpression(mapEnvironment.Right, precision: 1),
                        SyntaxFactory.LiteralExpression(mapEnvironment.Top, precision: 1)),
                    SyntaxFactory.FourCCLiteralExpression((int)mapInfo.GlobalWeather));

                if (UseWeatherEffectVariable)
                {
                    statements.Add(SyntaxFactory.SetStatement(VariableName.WeatherEffect, createWeather));
                    statements.Add(SyntaxFactory.CallStatement(NativeName.EnableWeatherEffect, SyntaxFactory.VariableReferenceExpression(VariableName.WeatherEffect), SyntaxFactory.LiteralExpression(true)));
                }
                else
                {
                    statements.Add(SyntaxFactory.CallStatement(NativeName.EnableWeatherEffect, createWeather, SyntaxFactory.LiteralExpression(true)));
                }
            }

            if (NewSoundEnvironmentCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.NewSoundEnvironment,
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(string.IsNullOrEmpty(mapInfo.SoundEnvironment) ? "Default" : mapInfo.SoundEnvironment))));
            }

            if (SetAmbientSoundCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   FunctionName.SetAmbientDaySound,
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(SoundEnvironmentProvider.GetAmbientDaySound(mapInfo.Tileset)))));

                statements.Add(SyntaxFactory.CallStatement(
                                   FunctionName.SetAmbientNightSound,
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(SoundEnvironmentProvider.GetAmbientNightSound(mapInfo.Tileset)))));
            }

            if (SetMapMusicCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   NativeName.SetMapMusic,
                                   SyntaxFactory.LiteralExpression("Music"),
                                   SyntaxFactory.LiteralExpression(true),
                                   SyntaxFactory.LiteralExpression(0)));
            }

            if (InitSoundsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitSounds)));
            }

            if (CreateRegionsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(CreateRegions)));
            }

            if (CreateCamerasCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(CreateCameras)));
            }

            if (InitUpgradesCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitUpgrades)));
            }

            if (InitTechTreeCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitTechTree)));
            }

            if (CreateAllDestructablesCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(CreateAllDestructables)));
            }

            if (CreateAllItemsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(CreateAllItems)));
            }

            if (InitRandomGroupsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitRandomGroups)));
            }

            if (CreateAllUnitsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(CreateAllUnits)));
            }

            if (InitBlizzardCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(FunctionName.InitBlizzard));
            }

            if (UseCSharpLua)
            {
                statements.Add(SyntaxFactory.CallStatement(CSharpLua.LuaSyntaxGenerator.kManifestFuncName));
            }

            statements.Add(JassEmptyStatementSyntax.Value);

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(main)), statements));
        }
Ejemplo n.º 4
0
        private LuaVariableListDeclarationSyntax GetMainFunctionSyntax(float left, float right, float top, float bottom, Tileset tileset, SoundEnvironment sound, params string[] initFunctions)
        {
            var localLeft = new LuaBinaryExpressionSyntax(
                new LuaFloatLiteralExpressionSyntax(left),
                LuaSyntaxNode.Tokens.Plus,
                new LuaInvocationExpressionSyntax("GetCameraMargin", "CAMERA_MARGIN_LEFT"));
            var localRight = new LuaBinaryExpressionSyntax(
                new LuaFloatLiteralExpressionSyntax(right),
                LuaSyntaxNode.Tokens.Sub,
                new LuaInvocationExpressionSyntax("GetCameraMargin", "CAMERA_MARGIN_RIGHT"));
            var localTop = new LuaBinaryExpressionSyntax(
                new LuaFloatLiteralExpressionSyntax(top),
                LuaSyntaxNode.Tokens.Sub,
                new LuaInvocationExpressionSyntax("GetCameraMargin", "CAMERA_MARGIN_TOP"));
            var localBottom = new LuaBinaryExpressionSyntax(
                new LuaFloatLiteralExpressionSyntax(bottom),
                LuaSyntaxNode.Tokens.Plus,
                new LuaInvocationExpressionSyntax("GetCameraMargin", "CAMERA_MARGIN_BOTTOM"));
            var locals = new[]
            {
                localLeft,
                localRight,
                localTop,
                localBottom,
            };

            var statements = new List <LuaStatementSyntax>
            {
                new LuaLocalDeclarationStatementSyntax(new LuaLocalVariablesStatementSyntax(
                                                           new[]
                {
                    new LuaSymbolNameSyntax(new LuaIdentifierLiteralExpressionSyntax("left")),
                    new LuaSymbolNameSyntax(new LuaIdentifierLiteralExpressionSyntax("right")),
                    new LuaSymbolNameSyntax(new LuaIdentifierLiteralExpressionSyntax("top")),
                    new LuaSymbolNameSyntax(new LuaIdentifierLiteralExpressionSyntax("bottom")),
                },
                                                           locals)),
                new LuaExpressionStatementSyntax(
                    new LuaInvocationExpressionSyntax(
                        "SetCameraBounds",
                        "left",
                        "bottom",
                        "right",
                        "top",
                        "left",
                        "top",
                        "right",
                        "bottom")),
                new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax(
                                                     "SetDayNightModels",
                                                     new LuaStringLiteralExpressionSyntax(LightEnvironmentProvider.GetTerrainLightEnvironmentModel(tileset)),
                                                     new LuaStringLiteralExpressionSyntax(LightEnvironmentProvider.GetUnitLightEnvironmentModel(tileset)))),
                new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax("NewSoundEnvironment", new LuaStringLiteralExpressionSyntax(SoundEnvironmentProvider.GetSoundEnvironment(sound)))),
                new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax("SetAmbientDaySound", new LuaStringLiteralExpressionSyntax(SoundEnvironmentProvider.GetAmbientDaySound(tileset)))),
                new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax("SetAmbientNightSound", new LuaStringLiteralExpressionSyntax(SoundEnvironmentProvider.GetAmbientNightSound(tileset)))),
                new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax(
                                                     "SetMapMusic",
                                                     new LuaStringLiteralExpressionSyntax("Music"),
                                                     LuaIdentifierLiteralExpressionSyntax.False,
                                                     LuaNumberLiteralExpressionSyntax.Zero)),
            };

            foreach (var initFunction in initFunctions)
            {
                statements.Add(new LuaExpressionStatementSyntax(new LuaInvocationExpressionSyntax(initFunction)));
            }

            var functionSyntax = new LuaFunctionExpressionSyntax();

            functionSyntax.AddStatements(statements);

            var mainFunctionDeclarator = new LuaVariableDeclaratorSyntax("main", functionSyntax);

            mainFunctionDeclarator.IsLocalDeclaration = false;

            var globalFunctionSyntax = new LuaVariableListDeclarationSyntax();

            globalFunctionSyntax.Variables.Add(mainFunctionDeclarator);

            return(globalFunctionSyntax);
        }