Esempio n. 1
0
        protected virtual IEnumerable <JassGlobalDeclarationSyntax> Units(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapUnits = map.Units;

            if (mapUnits is null)
            {
                yield break;
            }

            foreach (var unit in mapUnits.Units.Where(unit => CreateAllUnitsConditionSingleUnit(map, unit)))
            {
                yield return(SyntaxFactory.GlobalDeclaration(
                                 SyntaxFactory.ParseTypeName(TypeName.Unit),
                                 unit.GetVariableName()));
            }
        }
Esempio n. 2
0
        protected virtual IEnumerable <JassGlobalDeclarationSyntax> Regions(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapRegions = map.Regions;

            if (mapRegions is null)
            {
                yield break;
            }

            foreach (var region in mapRegions.Regions)
            {
                yield return(SyntaxFactory.GlobalDeclaration(
                                 SyntaxFactory.ParseTypeName(nameof(rect)),
                                 region.GetVariableName(),
                                 JassNullLiteralExpressionSyntax.Value));
            }
        }
Esempio n. 3
0
        protected virtual IEnumerable <JassGlobalDeclarationSyntax> Sounds(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapSounds = map.Sounds;

            if (mapSounds is null)
            {
                yield break;
            }

            foreach (var sound in mapSounds.Sounds)
            {
                yield return(SyntaxFactory.GlobalDeclaration(
                                 SyntaxFactory.ParseTypeName(nameof(sound)),
                                 sound.Name,
                                 JassNullLiteralExpressionSyntax.Value));
            }
        }
Esempio n. 4
0
        protected virtual IEnumerable <JassGlobalDeclarationSyntax> Cameras(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapCameras = map.Cameras;

            if (mapCameras is null)
            {
                yield break;
            }

            foreach (var camera in mapCameras.Cameras)
            {
                yield return(SyntaxFactory.GlobalDeclaration(
                                 SyntaxFactory.ParseTypeName(TypeName.CameraSetup),
                                 camera.GetVariableName(),
                                 JassNullLiteralExpressionSyntax.Value));
            }
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        protected virtual JassFunctionDeclarationSyntax CreateAllDestructables(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapDoodads = map.Doodads;

            if (mapDoodads is null)
            {
                throw new ArgumentException($"Function '{nameof(CreateAllDestructables)}' cannot be generated without {nameof(MapDoodads)}.", nameof(map));
            }

            var statements = new List <IStatementSyntax>();

            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(nameof(destructable)), VariableName.Destructable));
            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(nameof(trigger)), VariableName.Trigger));

            if (UseLifeVariable)
            {
                statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Real, VariableName.Life));
            }

            var createFunctions = new[]
            {
                nameof(CreateDestructable),
                nameof(CreateDeadDestructable),
                nameof(CreateDestructableZ),
                nameof(CreateDeadDestructableZ),
                nameof(BlzCreateDestructableWithSkin),
                nameof(BlzCreateDeadDestructableWithSkin),
                nameof(BlzCreateDestructableZWithSkin),
                nameof(BlzCreateDeadDestructableZWithSkin),
            };

            foreach (var(destructable, id) in mapDoodads.Doodads.IncludeId().Where(pair => CreateAllDestructablesConditionSingleDoodad(map, pair.Obj)))
            {
                var isDead              = destructable.Life == 0;
                var hasZ                = destructable.State.HasFlag(DoodadState.WithZ);
                var hasSkin             = destructable.SkinId != 0 && destructable.SkinId != destructable.TypeId;
                var createFunctionIndex = isDead ? 1 : 0;

                var arguments = new List <IExpressionSyntax>();
                arguments.Add(SyntaxFactory.FourCCLiteralExpression(destructable.TypeId));
                arguments.Add(SyntaxFactory.LiteralExpression(destructable.Position.X));
                arguments.Add(SyntaxFactory.LiteralExpression(destructable.Position.Y));
                if (hasZ)
                {
                    arguments.Add(SyntaxFactory.LiteralExpression(destructable.Position.Z));
                    createFunctionIndex += 2;
                }

                arguments.Add(SyntaxFactory.LiteralExpression(destructable.Rotation * (180f / MathF.PI), precision: 3));
                arguments.Add(SyntaxFactory.LiteralExpression(destructable.Scale.X, precision: 3));
                arguments.Add(SyntaxFactory.LiteralExpression(destructable.Variation));
                if (hasSkin)
                {
                    arguments.Add(SyntaxFactory.FourCCLiteralExpression(destructable.SkinId));
                    createFunctionIndex += 4;
                }

                statements.Add(SyntaxFactory.SetStatement(
                                   VariableName.Destructable,
                                   SyntaxFactory.InvocationExpression(createFunctions[createFunctionIndex], arguments.ToArray())));

                if (!isDead && destructable.Life != 100)
                {
                    if (UseLifeVariable)
                    {
                        statements.Add(SyntaxFactory.SetStatement(
                                           VariableName.Life,
                                           SyntaxFactory.InvocationExpression(
                                               nameof(GetDestructableLife),
                                               SyntaxFactory.VariableReferenceExpression(VariableName.Destructable))));

                        statements.Add(SyntaxFactory.CallStatement(
                                           nameof(SetDestructableLife),
                                           SyntaxFactory.VariableReferenceExpression(VariableName.Destructable),
                                           SyntaxFactory.BinaryMultiplicationExpression(
                                               SyntaxFactory.LiteralExpression(destructable.Life * 0.01f, precision: 2),
                                               SyntaxFactory.VariableReferenceExpression(VariableName.Life))));
                    }
                    else
                    {
                        statements.Add(SyntaxFactory.CallStatement(
                                           nameof(SetDestructableLife),
                                           SyntaxFactory.VariableReferenceExpression(VariableName.Destructable),
                                           SyntaxFactory.BinaryMultiplicationExpression(
                                               SyntaxFactory.LiteralExpression(destructable.Life * 0.01f, precision: 2),
                                               SyntaxFactory.InvocationExpression(nameof(GetDestructableLife), SyntaxFactory.VariableReferenceExpression(VariableName.Destructable)))));
                    }
                }

                statements.Add(SyntaxFactory.SetStatement(
                                   VariableName.Trigger,
                                   SyntaxFactory.InvocationExpression(nameof(CreateTrigger))));

                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(TriggerRegisterDeathEvent),
                                   SyntaxFactory.VariableReferenceExpression(VariableName.Trigger),
                                   SyntaxFactory.VariableReferenceExpression(VariableName.Destructable)));

                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(TriggerAddAction),
                                   SyntaxFactory.VariableReferenceExpression(VariableName.Trigger),
                                   SyntaxFactory.FunctionReferenceExpression(nameof(War3Api.Blizzard.SaveDyingWidget))));

                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(TriggerAddAction),
                                   SyntaxFactory.VariableReferenceExpression(VariableName.Trigger),
                                   SyntaxFactory.FunctionReferenceExpression(destructable.GetDropItemsFunctionName(id))));
            }

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateAllDestructables)), statements));
        }
Esempio n. 7
0
        protected virtual JassFunctionDeclarationSyntax CreateRegions(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapRegions = map.Regions;

            if (mapRegions is null)
            {
                throw new ArgumentException($"Function '{nameof(CreateRegions)}' cannot be generated without {nameof(MapRegions)}.", nameof(map));
            }

            var statements = new List <IStatementSyntax>();

            if (UseWeatherEffectVariable)
            {
                statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(nameof(weathereffect)), VariableName.WeatherEffect));
                statements.Add(JassEmptyStatementSyntax.Value);
            }

            foreach (var region in mapRegions.Regions)
            {
                var regionName = region.GetVariableName();

                statements.Add(SyntaxFactory.SetStatement(
                                   regionName,
                                   SyntaxFactory.InvocationExpression(
                                       nameof(Rect),
                                       SyntaxFactory.LiteralExpression(region.Left, precision: 1),
                                       SyntaxFactory.LiteralExpression(region.Bottom, precision: 1),
                                       SyntaxFactory.LiteralExpression(region.Right, precision: 1),
                                       SyntaxFactory.LiteralExpression(region.Top, precision: 1))));

                if (region.WeatherType != WeatherType.None)
                {
                    if (UseWeatherEffectVariable)
                    {
                        statements.Add(SyntaxFactory.SetStatement(
                                           VariableName.WeatherEffect,
                                           SyntaxFactory.InvocationExpression(
                                               nameof(AddWeatherEffect),
                                               SyntaxFactory.VariableReferenceExpression(regionName),
                                               SyntaxFactory.FourCCLiteralExpression((int)region.WeatherType))));

                        statements.Add(SyntaxFactory.CallStatement(
                                           nameof(EnableWeatherEffect),
                                           SyntaxFactory.VariableReferenceExpression(VariableName.WeatherEffect),
                                           JassBooleanLiteralExpressionSyntax.True));
                    }
                    else
                    {
                        statements.Add(SyntaxFactory.CallStatement(
                                           nameof(EnableWeatherEffect),
                                           SyntaxFactory.InvocationExpression(
                                               nameof(AddWeatherEffect),
                                               SyntaxFactory.VariableReferenceExpression(regionName),
                                               SyntaxFactory.FourCCLiteralExpression((int)region.WeatherType)),
                                           JassBooleanLiteralExpressionSyntax.True));
                    }
                }

                if (!string.IsNullOrEmpty(region.AmbientSound))
                {
                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundPosition),
                                       SyntaxFactory.VariableReferenceExpression(region.AmbientSound),
                                       SyntaxFactory.LiteralExpression(region.CenterX),
                                       SyntaxFactory.LiteralExpression(region.CenterY),
                                       SyntaxFactory.LiteralExpression(0f)));

                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(RegisterStackedSound),
                                       SyntaxFactory.VariableReferenceExpression(region.AmbientSound),
                                       SyntaxFactory.LiteralExpression(true),
                                       SyntaxFactory.LiteralExpression(region.Width),
                                       SyntaxFactory.LiteralExpression(region.Height)));
                }
            }

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateRegions)), statements));
        }
Esempio n. 8
0
        protected virtual IEnumerable <IStatementSyntax> GetItemTableDropItemsStatements(Map map, IEnumerable <RandomItemSet> itemSets, bool chooseItemClass)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            if (itemSets is null)
            {
                throw new ArgumentNullException(nameof(itemSets));
            }

            var statements = new List <IStatementSyntax>();

            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(TypeName.Widget), VariableName.TrigWidget, JassNullLiteralExpressionSyntax.Value));
            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(SyntaxFactory.ParseTypeName(TypeName.Unit), VariableName.TrigUnit, JassNullLiteralExpressionSyntax.Value));
            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, VariableName.ItemId, SyntaxFactory.LiteralExpression(0)));
            statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Boolean, VariableName.CanDrop, SyntaxFactory.LiteralExpression(true)));
            statements.Add(JassEmptyStatementSyntax.Value);

            statements.Add(SyntaxFactory.SetStatement(
                               VariableName.TrigWidget,
                               SyntaxFactory.VariableReferenceExpression(VariableName.BJLastDyingWidget)));

            statements.Add(SyntaxFactory.IfStatement(
                               new JassParenthesizedExpressionSyntax(SyntaxFactory.BinaryEqualsExpression(SyntaxFactory.VariableReferenceExpression(VariableName.TrigWidget), JassNullLiteralExpressionSyntax.Value)),
                               SyntaxFactory.SetStatement(VariableName.TrigUnit, SyntaxFactory.InvocationExpression(NativeName.GetTriggerUnit))));

            statements.Add(JassEmptyStatementSyntax.Value);

            var canDropConditionExpression = SyntaxFactory.UnaryNotExpression(SyntaxFactory.InvocationExpression(NativeName.IsUnitHidden, SyntaxFactory.VariableReferenceExpression(VariableName.TrigUnit)));

            var ifBody = new List <IStatementSyntax>()
            {
                SyntaxFactory.SetStatement(VariableName.CanDrop, canDropConditionExpression),
            };

            ifBody.Add(SyntaxFactory.IfStatement(
                           new JassParenthesizedExpressionSyntax(SyntaxFactory.BinaryAndExpression(
                                                                     SyntaxFactory.VariableReferenceExpression(VariableName.CanDrop),
                                                                     SyntaxFactory.BinaryNotEqualsExpression(SyntaxFactory.InvocationExpression(NativeName.GetChangingUnit), JassNullLiteralExpressionSyntax.Value))),
                           SyntaxFactory.SetStatement(
                               VariableName.CanDrop,
                               new JassParenthesizedExpressionSyntax(SyntaxFactory.BinaryEqualsExpression(
                                                                         SyntaxFactory.InvocationExpression(NativeName.GetChangingUnitPrevOwner),
                                                                         SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.VariableReferenceExpression(GlobalVariableName.PlayerNeutralHostile)))))));

            statements.Add(SyntaxFactory.IfStatement(
                               new JassParenthesizedExpressionSyntax(SyntaxFactory.BinaryNotEqualsExpression(SyntaxFactory.VariableReferenceExpression(VariableName.TrigUnit), JassNullLiteralExpressionSyntax.Value)),
                               ifBody.ToArray()));
            statements.Add(JassEmptyStatementSyntax.Value);

            var i = 0;
            var randomDistStatements = new List <IStatementSyntax>();

            foreach (var itemSet in itemSets)
            {
                randomDistStatements.Add(new JassCommentStatementSyntax($" Item set {i}"));
                randomDistStatements.Add(SyntaxFactory.CallStatement(FunctionName.RandomDistReset));

                var summedChance = 0;
                foreach (var item in itemSet.Items)
                {
                    if (RandomItemProvider.IsRandomItem(item.ItemId, out var itemClass, out var level))
                    {
                        if (chooseItemClass)
                        {
                            randomDistStatements.Add(SyntaxFactory.CallStatement(
                                                         FunctionName.RandomDistAddItem,
                                                         SyntaxFactory.InvocationExpression(
                                                             NativeName.ChooseRandomItemEx,
                                                             SyntaxFactory.VariableReferenceExpression(itemClass.GetVariableName()),
                                                             SyntaxFactory.LiteralExpression(level)),
                                                         SyntaxFactory.LiteralExpression(item.Chance)));
                        }
                        else
                        {
                            randomDistStatements.Add(SyntaxFactory.CallStatement(
                                                         FunctionName.RandomDistAddItem,
                                                         SyntaxFactory.InvocationExpression(NativeName.ChooseRandomItem, SyntaxFactory.LiteralExpression(level)),
                                                         SyntaxFactory.LiteralExpression(item.Chance)));
                        }
                    }