Ejemplo n.º 1
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.º 2
0
        protected virtual JassFunctionDeclarationSyntax config(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapInfo = map.Info;

            var statements = new List <IStatementSyntax>();

            var playerDataCount = mapInfo.Players.Count;
            var forceDataCount  = mapInfo.Forces.Count;

            statements.Add(SyntaxFactory.CallStatement(nameof(SetMapName), SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(mapInfo.MapName))));
            statements.Add(SyntaxFactory.CallStatement(nameof(SetMapDescription), SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(mapInfo.MapDescription))));
            statements.Add(SyntaxFactory.CallStatement(nameof(SetPlayers), SyntaxFactory.LiteralExpression(playerDataCount)));
            statements.Add(SyntaxFactory.CallStatement(nameof(SetTeams), SyntaxFactory.LiteralExpression(playerDataCount)));
            statements.Add(SyntaxFactory.CallStatement(nameof(SetGamePlacement), SyntaxFactory.VariableReferenceExpression(nameof(MAP_PLACEMENT_USE_MAP_SETTINGS))));
            statements.Add(JassEmptyStatementSyntax.Value);

            if (!string.IsNullOrEmpty(LobbyMusic))
            {
                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(PlayMusic),
                                   SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(LobbyMusic))));
            }

            for (var i = 0; i < playerDataCount; i++)
            {
                var location = mapInfo.Players[i].StartPosition;
                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(DefineStartLocation),
                                   SyntaxFactory.LiteralExpression(i),
                                   SyntaxFactory.LiteralExpression(location.X, precision: 1),
                                   SyntaxFactory.LiteralExpression(location.Y, precision: 1)));
            }

            statements.Add(JassEmptyStatementSyntax.Value);
            statements.Add(new JassCommentStatementSyntax(" Player setup"));

            if (InitCustomPlayerSlotsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitCustomPlayerSlots)));
            }

            var elseStatements = new List <IStatementSyntax>();

            if (!mapInfo.MapFlags.HasFlag(MapFlags.UseCustomForces))
            {
                for (var i = 0; i < playerDataCount; i++)
                {
                    elseStatements.Add(SyntaxFactory.CallStatement(
                                           nameof(War3Api.Blizzard.SetPlayerSlotAvailable),
                                           SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(mapInfo.Players[i].Id)),
                                           SyntaxFactory.VariableReferenceExpression(nameof(MAP_CONTROL_USER))));
                }

                elseStatements.Add(SyntaxFactory.CallStatement(nameof(War3Api.Blizzard.InitGenericPlayerSlots)));
            }

            statements.AddRange(elseStatements);

            if (InitCustomTeamsCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitCustomTeams)));
            }

            if (InitAllyPrioritiesCondition(map))
            {
                statements.Add(SyntaxFactory.CallStatement(nameof(InitAllyPriorities)));
            }

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(config)), statements));
        }
Ejemplo n.º 3
0
        protected virtual JassFunctionDeclarationSyntax InitSounds(Map map)
        {
            if (map is null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var mapSounds = map.Sounds;

            if (mapSounds is null)
            {
                throw new ArgumentException($"Function '{nameof(InitSounds)}' cannot be generated without {nameof(MapSounds)}.", nameof(map));
            }

            var mapInfo = map.Info;

            var statements = new List <IStatementSyntax>();

            foreach (var sound in mapSounds.Sounds)
            {
                var is3DSound = sound.Flags.HasFlag(SoundFlags.Is3DSound) &&
                                sound.Channel != SoundChannel.Error &&
                                sound.Channel != SoundChannel.Music &&
                                sound.Channel != SoundChannel.UserInterface;

                statements.Add(SyntaxFactory.SetStatement(
                                   sound.Name,
                                   SyntaxFactory.InvocationExpression(
                                       nameof(CreateSound),
                                       SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(sound.FilePath)),
                                       SyntaxFactory.LiteralExpression(sound.Flags.HasFlag(SoundFlags.Looping)),
                                       SyntaxFactory.LiteralExpression(is3DSound),
                                       SyntaxFactory.LiteralExpression(sound.Flags.HasFlag(SoundFlags.StopWhenOutOfRange)),
                                       SyntaxFactory.LiteralExpression(sound.FadeInRate),
                                       SyntaxFactory.LiteralExpression(sound.FadeOutRate),
                                       SyntaxFactory.LiteralExpression(EscapedStringProvider.GetEscapedString(sound.EaxSetting)))));

                if (sound.DistanceCutoff != 3000f)
                {
                    var distanceCutoff = sound.DistanceCutoff == uint.MaxValue ? 3000f : sound.DistanceCutoff;
                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundDistanceCutoff),
                                       SyntaxFactory.VariableReferenceExpression(sound.Name),
                                       SyntaxFactory.LiteralExpression(distanceCutoff, precision: 1)));
                }

                if ((int)sound.Channel != -1)
                {
                    var channel = sound.Channel == SoundChannel.Undefined ? SoundChannel.General : sound.Channel;
                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundChannel),
                                       SyntaxFactory.VariableReferenceExpression(sound.Name),
                                       SyntaxFactory.LiteralExpression((int)channel)));
                }

                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(SetSoundVolume),
                                   SyntaxFactory.VariableReferenceExpression(sound.Name),
                                   SyntaxFactory.LiteralExpression(sound.Volume == -1 ? 127 : sound.Volume)));

                statements.Add(SyntaxFactory.CallStatement(
                                   nameof(SetSoundPitch),
                                   SyntaxFactory.VariableReferenceExpression(sound.Name),
                                   SyntaxFactory.LiteralExpression(sound.Pitch == uint.MaxValue ? 1f : sound.Pitch, precision: 1)));

                if (is3DSound)
                {
                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundDistances),
                                       SyntaxFactory.VariableReferenceExpression(sound.Name),
                                       SyntaxFactory.LiteralExpression(sound.MinDistance == uint.MaxValue ? 0f : sound.MinDistance, precision: 1),
                                       SyntaxFactory.LiteralExpression(sound.MaxDistance == uint.MaxValue ? 10000f : sound.MaxDistance, precision: 1)));

                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundConeAngles),
                                       SyntaxFactory.VariableReferenceExpression(sound.Name),
                                       SyntaxFactory.LiteralExpression(sound.ConeAngleInside == uint.MaxValue ? 0f : sound.ConeAngleInside, precision: 1),
                                       SyntaxFactory.LiteralExpression(sound.ConeAngleOutside == uint.MaxValue ? 0f : sound.ConeAngleOutside, precision: 1),
                                       SyntaxFactory.LiteralExpression(sound.ConeOutsideVolume == -1 ? 127 : sound.ConeOutsideVolume)));

                    statements.Add(SyntaxFactory.CallStatement(
                                       nameof(SetSoundConeOrientation),
                                       SyntaxFactory.VariableReferenceExpression(sound.Name),
                                       SyntaxFactory.LiteralExpression(sound.ConeOrientation.X == uint.MaxValue ? 0f : sound.ConeOrientation.X, precision: 1),
                                       SyntaxFactory.LiteralExpression(sound.ConeOrientation.Y == uint.MaxValue ? 0f : sound.ConeOrientation.Y, precision: 1),
                                       SyntaxFactory.LiteralExpression(sound.ConeOrientation.Z == uint.MaxValue ? 0f : sound.ConeOrientation.Z, precision: 1)));
                }
            }

            return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitSounds)), statements));
        }