public static JassFunctionDeclarationSyntax CreateRegions(MapRegions mapRegions) { var statements = new List <IStatementSyntax>(); 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) { statements.Add(SyntaxFactory.CallStatement( nameof(EnableWeatherEffect), SyntaxFactory.InvocationExpression( nameof(AddWeatherEffect), SyntaxFactory.VariableReferenceExpression(regionName), SyntaxFactory.FourCCLiteralExpression((int)region.WeatherType)), SyntaxFactory.LiteralExpression(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)); }
protected virtual JassFunctionDeclarationSyntax CreateCameras(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapCameras = map.Cameras; if (mapCameras is null) { throw new ArgumentException($"Function '{nameof(CreateCameras)}' cannot be generated without {nameof(MapCameras)}.", nameof(map)); } var statements = new List <IStatementSyntax>(); statements.Add(JassEmptyStatementSyntax.Value); var zero = SyntaxFactory.LiteralExpression(0f); foreach (var camera in mapCameras.Cameras) { var cameraName = camera.GetVariableName(); statements.Add(SyntaxFactory.SetStatement(cameraName, SyntaxFactory.InvocationExpression(NativeName.CreateCameraSetup))); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.ZOffset), SyntaxFactory.LiteralExpression(camera.ZOffset), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.Rotation), SyntaxFactory.LiteralExpression(camera.Rotation), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.AngleOfAttack), SyntaxFactory.LiteralExpression(camera.AngleOfAttack), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.TargetDistance), SyntaxFactory.LiteralExpression(camera.TargetDistance), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.Roll), SyntaxFactory.LiteralExpression(camera.Roll), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.FieldOfView), SyntaxFactory.LiteralExpression(camera.FieldOfView), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.FarZ), SyntaxFactory.LiteralExpression(camera.FarClippingPlane), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.NearZ), SyntaxFactory.LiteralExpression(camera.NearClippingPlane), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.LocalPitch), SyntaxFactory.LiteralExpression(camera.LocalPitch), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.LocalYaw), SyntaxFactory.LiteralExpression(camera.LocalYaw), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetField, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(CameraFieldName.LocalRoll), SyntaxFactory.LiteralExpression(camera.LocalRoll), zero)); statements.Add(SyntaxFactory.CallStatement(NativeName.CameraSetupSetDestPosition, SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.LiteralExpression(camera.TargetPosition.X), SyntaxFactory.LiteralExpression(camera.TargetPosition.Y), zero)); statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateCameras)), statements)); }
protected virtual JassFunctionDeclarationSyntax CreateCameras(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapCameras = map.Cameras; if (mapCameras is null) { throw new ArgumentException($"Function '{nameof(CreateCameras)}' cannot be generated without {nameof(MapCameras)}.", nameof(map)); } var statements = new List <IStatementSyntax>(); statements.Add(JassEmptyStatementSyntax.Value); var zero = SyntaxFactory.LiteralExpression(0f); foreach (var camera in mapCameras.Cameras) { var cameraName = camera.GetVariableName(); statements.Add(SyntaxFactory.SetStatement(cameraName, SyntaxFactory.InvocationExpression(nameof(CreateCameraSetup)))); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_ZOFFSET)), SyntaxFactory.LiteralExpression(camera.ZOffset), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_ROTATION)), SyntaxFactory.LiteralExpression(camera.Rotation), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_ANGLE_OF_ATTACK)), SyntaxFactory.LiteralExpression(camera.AngleOfAttack), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_TARGET_DISTANCE)), SyntaxFactory.LiteralExpression(camera.TargetDistance), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_ROLL)), SyntaxFactory.LiteralExpression(camera.Roll), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_FIELD_OF_VIEW)), SyntaxFactory.LiteralExpression(camera.FieldOfView), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_FARZ)), SyntaxFactory.LiteralExpression(camera.FarClippingPlane), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_NEARZ)), SyntaxFactory.LiteralExpression(camera.NearClippingPlane), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_LOCAL_PITCH)), SyntaxFactory.LiteralExpression(camera.LocalPitch), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_LOCAL_YAW)), SyntaxFactory.LiteralExpression(camera.LocalYaw), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetField), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.VariableReferenceExpression(nameof(CAMERA_FIELD_LOCAL_ROLL)), SyntaxFactory.LiteralExpression(camera.LocalRoll), zero)); statements.Add(SyntaxFactory.CallStatement(nameof(CameraSetupSetDestPosition), SyntaxFactory.VariableReferenceExpression(cameraName), SyntaxFactory.LiteralExpression(camera.TargetPosition.X), SyntaxFactory.LiteralExpression(camera.TargetPosition.Y), zero)); statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateCameras)), statements)); }
protected virtual JassFunctionDeclarationSyntax InitTechTree(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapInfo = map.Info; var statements = new List <IStatementSyntax>(); foreach (var player in mapInfo.Players) { var playerNumber = player.Id; foreach (var techData in mapInfo.TechData) { if (techData.Players[playerNumber]) { if (techData.Id.ToRawcode()[0] == 'A') { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerAbilityAvailable), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerNumber)), SyntaxFactory.FourCCLiteralExpression(techData.Id), SyntaxFactory.LiteralExpression(false))); } else { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerTechMaxAllowed), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerNumber)), SyntaxFactory.FourCCLiteralExpression(techData.Id), SyntaxFactory.LiteralExpression(0))); } } } } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitTechTree)), statements)); }
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)); }
public static JassFunctionDeclarationSyntax CreateAllItems(MapUnits mapUnits) { const string LocalItemIdVariableName = "itemID"; var statements = new List <IStatementSyntax>(); statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, LocalItemIdVariableName)); foreach (var item in mapUnits.Units.Where(item => item.IsItem() && !item.IsPlayerStartLocation())) { if (item.IsRandomItem()) { var randomData = item.RandomData; switch (randomData) { case RandomUnitAny randomUnitAny: statements.Add(SyntaxFactory.SetStatement( LocalItemIdVariableName, SyntaxFactory.InvocationExpression( nameof(ChooseRandomItemEx), SyntaxFactory.InvocationExpression(nameof(ConvertItemType), SyntaxFactory.LiteralExpression((int)randomUnitAny.Class)), SyntaxFactory.LiteralExpression(randomUnitAny.Level)))); break; case RandomUnitGlobalTable randomUnitGlobalTable: break; case RandomUnitCustomTable randomUnitCustomTable: statements.Add(SyntaxFactory.CallStatement(nameof(War3Api.Blizzard.RandomDistReset))); var summedChance = 0; foreach (var randomItem in randomUnitCustomTable.RandomUnits) { IExpressionSyntax id = RandomItemProvider.IsRandomItem(randomItem.UnitId, out var itemClass, out var level) ? SyntaxFactory.InvocationExpression( nameof(ChooseRandomItemEx), SyntaxFactory.InvocationExpression(nameof(ConvertItemType), SyntaxFactory.LiteralExpression((int)itemClass)), SyntaxFactory.LiteralExpression(level)) : SyntaxFactory.FourCCLiteralExpression(randomItem.UnitId); statements.Add(SyntaxFactory.CallStatement( nameof(War3Api.Blizzard.RandomDistAddItem), id, SyntaxFactory.LiteralExpression(randomItem.Chance))); summedChance += randomItem.Chance; } if (summedChance < 100) { statements.Add(SyntaxFactory.CallStatement( nameof(War3Api.Blizzard.RandomDistAddItem), SyntaxFactory.LiteralExpression(-1), SyntaxFactory.LiteralExpression(100 - summedChance))); } statements.Add(SyntaxFactory.SetStatement( LocalItemIdVariableName, SyntaxFactory.InvocationExpression(nameof(War3Api.Blizzard.RandomDistChoose)))); break; default: break; } statements.Add(SyntaxFactory.IfStatement( SyntaxFactory.BinaryNotEqualsExpression(SyntaxFactory.VariableReferenceExpression(LocalItemIdVariableName), SyntaxFactory.LiteralExpression(-1)), SyntaxFactory.CallStatement( nameof(CreateItem), SyntaxFactory.VariableReferenceExpression(LocalItemIdVariableName), SyntaxFactory.LiteralExpression(item.Position.X), SyntaxFactory.LiteralExpression(item.Position.Y)))); } else { var args = new List <IExpressionSyntax>() { SyntaxFactory.FourCCLiteralExpression(item.TypeId), SyntaxFactory.LiteralExpression(item.Position.X), SyntaxFactory.LiteralExpression(item.Position.Y), }; var hasSkin = item.SkinId != 0 && item.SkinId != item.TypeId; if (hasSkin) { args.Add(SyntaxFactory.FourCCLiteralExpression(item.SkinId)); } statements.Add(SyntaxFactory.CallStatement(hasSkin ? nameof(BlzCreateItemWithSkin) : nameof(CreateItem), args.ToArray())); } } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateAllItems)), statements)); }
public static JassFunctionDeclarationSyntax InitUpgrades(MapInfo mapInfo) { var statements = new List <IStatementSyntax>(); foreach (var player in mapInfo.Players) { var playerNumber = player.Id; var maxLevel = new Dictionary <int, int>(); var researched = new Dictionary <int, int>(); for (var i = 0; i < mapInfo.UpgradeData.Count; i++) { var upgradeData = mapInfo.UpgradeData[i]; if (upgradeData.Availability != UpgradeAvailability.Available && upgradeData.Players[playerNumber]) { if (upgradeData.Availability == UpgradeAvailability.Unavailable) { if (maxLevel.TryGetValue(upgradeData.Id, out var level)) { if (upgradeData.Level < level) { maxLevel[upgradeData.Id] = upgradeData.Level; } } else { maxLevel.Add(upgradeData.Id, upgradeData.Level); } } else if (upgradeData.Availability == UpgradeAvailability.Researched) { if (researched.TryGetValue(upgradeData.Id, out var level)) { if (upgradeData.Level > level) { researched[upgradeData.Id] = upgradeData.Level; } } else { researched.Add(upgradeData.Id, upgradeData.Level); } } } } foreach (var tech in maxLevel) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerTechMaxAllowed), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerNumber)), SyntaxFactory.FourCCLiteralExpression(tech.Key), SyntaxFactory.LiteralExpression(tech.Value))); } foreach (var tech in researched) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerTechResearched), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerNumber)), SyntaxFactory.FourCCLiteralExpression(tech.Key), SyntaxFactory.LiteralExpression(tech.Value + 1))); } } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitUpgrades)), statements)); }
protected virtual JassFunctionDeclarationSyntax InitCustomPlayerSlots(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; for (var i = 0; i < playerDataCount; i++) { var playerData = mapInfo.Players[i]; statements.Add(JassEmptyStatementSyntax.Value); statements.Add(new JassCommentStatementSyntax($" Player {playerData.Id}")); statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerStartLocation), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.LiteralExpression(i))); if (playerData.Flags.HasFlag(PlayerFlags.FixedStartPosition)) { statements.Add(SyntaxFactory.CallStatement( nameof(ForcePlayerStartLocation), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.LiteralExpression(i))); } statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerColor), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.InvocationExpression(nameof(ConvertPlayerColor), SyntaxFactory.LiteralExpression(playerData.Id)))); statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerRacePreference), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.VariableReferenceExpression(RacePreferenceProvider.GetRacePreferenceString(playerData.Race)))); statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerRaceSelectable), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.LiteralExpression(playerData.Flags.HasFlag(PlayerFlags.RaceSelectable) || !mapInfo.MapFlags.HasFlag(MapFlags.FixedPlayerSettingsForCustomForces)))); statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerController), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.VariableReferenceExpression(PlayerControllerProvider.GetPlayerControllerString(playerData.Controller)))); if (playerData.Controller == PlayerController.Rescuable) { for (var j = 0; j < playerDataCount; j++) { var otherPlayerData = mapInfo.Players[j]; if (otherPlayerData.Controller == PlayerController.User) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerAlliance), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerData.Id)), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(otherPlayerData.Id)), SyntaxFactory.VariableReferenceExpression(nameof(ALLIANCE_RESCUABLE)), SyntaxFactory.LiteralExpression(true))); } } } } statements.Add(JassEmptyStatementSyntax.Value); return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitCustomPlayerSlots)), statements)); }
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)); }
protected virtual JassFunctionDeclarationSyntax InitCustomTeams(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapInfo = map.Info; var statements = new List <IStatementSyntax>(); var forceDataCount = mapInfo.Forces.Count; var useBlizzardAllianceFunctions = mapInfo.FormatVersion > MapInfoFormatVersion.v15; for (var i = 0; i < forceDataCount; i++) { var forceData = mapInfo.Forces[i]; var playerSlots = mapInfo.Players .Where(player => forceData.Players[player.Id]) .Select(player => player.Id) .ToList(); if (!playerSlots.Any()) { continue; } statements.Add(new JassCommentStatementSyntax($" Force: {forceData.Name}")); var alliedVictory = forceData.Flags.HasFlag(ForceFlags.AlliedVictory); foreach (var playerSlot in playerSlots) { statements.Add(SyntaxFactory.CallStatement( NativeName.SetPlayerTeam, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot)), SyntaxFactory.LiteralExpression(i))); if (alliedVictory) { statements.Add(SyntaxFactory.CallStatement( NativeName.SetPlayerState, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot)), SyntaxFactory.VariableReferenceExpression(PlayerStateName.AlliedVictory), SyntaxFactory.LiteralExpression(1))); } } var playerSlotPairs = playerSlots.SelectMany(slot1 => playerSlots.Where(slot2 => slot1 != slot2).Select(slot2 => (slot1, slot2))).ToArray(); if (useBlizzardAllianceFunctions) { void AddSetAllianceStateStatement(string statementName) { foreach (var(playerSlot1, playerSlot2) in playerSlotPairs) { statements.Add(SyntaxFactory.CallStatement( statementName, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot1)), SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot2)), SyntaxFactory.LiteralExpression(true))); } } if (forceData.Flags.HasFlag(ForceFlags.Allied)) { AddSetAllianceStateStatement(FunctionName.SetPlayerAllianceStateAllyBJ); } if (forceData.Flags.HasFlag(ForceFlags.ShareVision)) { AddSetAllianceStateStatement(FunctionName.SetPlayerAllianceStateVisionBJ); } if (forceData.Flags.HasFlag(ForceFlags.ShareUnitControl)) { AddSetAllianceStateStatement(FunctionName.SetPlayerAllianceStateControlBJ); } if (forceData.Flags.HasFlag(ForceFlags.ShareAdvancedUnitControl)) { AddSetAllianceStateStatement(FunctionName.SetPlayerAllianceStateFullControlBJ); } } else { void AddSetAllianceStateStatement(string variableName, string comment) { statements.Add(JassEmptyStatementSyntax.Value); statements.Add(new JassCommentStatementSyntax(comment)); foreach (var(playerSlot1, playerSlot2) in playerSlotPairs) { statements.Add(SyntaxFactory.CallStatement( NativeName.SetPlayerAlliance, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot1)), SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerSlot2)), SyntaxFactory.VariableReferenceExpression(variableName), SyntaxFactory.LiteralExpression(true))); } } if (forceData.Flags.HasFlag(ForceFlags.Allied)) { AddSetAllianceStateStatement(AllianceTypeName.Passive, " Allied"); } if (forceData.Flags.HasFlag(ForceFlags.ShareVision)) { AddSetAllianceStateStatement(AllianceTypeName.SharedVision, " Shared Vision"); } if (forceData.Flags.HasFlag(ForceFlags.ShareUnitControl)) { AddSetAllianceStateStatement(AllianceTypeName.SharedControl, " Shared Control"); } if (forceData.Flags.HasFlag(ForceFlags.ShareAdvancedUnitControl)) { AddSetAllianceStateStatement(AllianceTypeName.SharedAdvancedControl, " Advanced Control"); } } statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitCustomTeams)), statements)); }
public static JassFunctionDeclarationSyntax InitCustomTeams(MapInfo mapInfo) { var statements = new List <IStatementSyntax>(); var forceDataCount = mapInfo.Forces.Count; var useBlizzardAllianceFunctions = mapInfo.FormatVersion > MapInfoFormatVersion.v15; for (var i = 0; i < forceDataCount; i++) { var forceData = mapInfo.Forces[i]; var playerSlots = mapInfo.Players .Where(player => forceData.Players[player.Id]) .Select(player => player.Id) .ToList(); if (!playerSlots.Any()) { continue; } statements.Add(new JassCommentStatementSyntax($" Force: {forceData.Name}")); var alliedVictory = forceData.Flags.HasFlag(ForceFlags.AlliedVictory); foreach (var playerSlot in playerSlots) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerTeam), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot)), SyntaxFactory.LiteralExpression(i))); if (alliedVictory) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerState), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot)), SyntaxFactory.VariableReferenceExpression(nameof(PLAYER_STATE_ALLIED_VICTORY)), SyntaxFactory.LiteralExpression(1))); } } var playerSlotPairs = playerSlots.SelectMany(slot1 => playerSlots.Where(slot2 => slot1 != slot2).Select(slot2 => (slot1, slot2))).ToArray(); if (useBlizzardAllianceFunctions) { void AddSetAllianceStateStatement(string statementName) { foreach (var(playerSlot1, playerSlot2) in playerSlotPairs) { statements.Add(SyntaxFactory.CallStatement( statementName, SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot1)), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot2)), SyntaxFactory.LiteralExpression(true))); } } if (forceData.Flags.HasFlag(ForceFlags.Allied)) { AddSetAllianceStateStatement(nameof(War3Api.Blizzard.SetPlayerAllianceStateAllyBJ)); } if (forceData.Flags.HasFlag(ForceFlags.ShareVision)) { AddSetAllianceStateStatement(nameof(War3Api.Blizzard.SetPlayerAllianceStateVisionBJ)); } if (forceData.Flags.HasFlag(ForceFlags.ShareUnitControl)) { AddSetAllianceStateStatement(nameof(War3Api.Blizzard.SetPlayerAllianceStateControlBJ)); } if (forceData.Flags.HasFlag(ForceFlags.ShareAdvancedUnitControl)) { AddSetAllianceStateStatement(nameof(War3Api.Blizzard.SetPlayerAllianceStateFullControlBJ)); } } else { void AddSetAllianceStateStatement(string variableName, string comment) { statements.Add(JassEmptyStatementSyntax.Value); statements.Add(new JassCommentStatementSyntax(comment)); foreach (var(playerSlot1, playerSlot2) in playerSlotPairs) { statements.Add(SyntaxFactory.CallStatement( nameof(SetPlayerAlliance), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot1)), SyntaxFactory.InvocationExpression(nameof(Player), SyntaxFactory.LiteralExpression(playerSlot2)), SyntaxFactory.VariableReferenceExpression(variableName), SyntaxFactory.LiteralExpression(true))); } } if (forceData.Flags.HasFlag(ForceFlags.Allied)) { AddSetAllianceStateStatement(nameof(ALLIANCE_PASSIVE), " Allied"); } if (forceData.Flags.HasFlag(ForceFlags.ShareVision)) { AddSetAllianceStateStatement(nameof(ALLIANCE_SHARED_VISION), " Shared Vision"); } if (forceData.Flags.HasFlag(ForceFlags.ShareUnitControl)) { AddSetAllianceStateStatement(nameof(ALLIANCE_SHARED_CONTROL), " Shared Control"); } if (forceData.Flags.HasFlag(ForceFlags.ShareAdvancedUnitControl)) { AddSetAllianceStateStatement(nameof(ALLIANCE_SHARED_ADVANCED_CONTROL), " Advanced Control"); } } statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitCustomTeams)), statements)); }
public static JassFunctionDeclarationSyntax InitRandomGroups(IEnumerable <RandomUnitTable> randomUnitTables) { const string LocalCurrentSetVariableName = "curset"; var statements = new List <IStatementSyntax>(); statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, LocalCurrentSetVariableName)); statements.Add(JassEmptyStatementSyntax.Value); foreach (var unitTable in randomUnitTables) { statements.Add(new JassCommentStatementSyntax($" Group {unitTable.Index} - {unitTable.Name}")); statements.Add(SyntaxFactory.CallStatement(nameof(War3Api.Blizzard.RandomDistReset))); for (var i = 0; i < unitTable.UnitSets.Count; i++) { statements.Add(SyntaxFactory.CallStatement( nameof(War3Api.Blizzard.RandomDistAddItem), SyntaxFactory.LiteralExpression(i), SyntaxFactory.LiteralExpression(unitTable.UnitSets[i].Chance))); } statements.Add(SyntaxFactory.SetStatement(LocalCurrentSetVariableName, SyntaxFactory.InvocationExpression(nameof(War3Api.Blizzard.RandomDistChoose)))); statements.Add(JassEmptyStatementSyntax.Value); var groupVarName = unitTable.GetVariableName(); var ifElseifBlocks = new List <(IExpressionSyntax Condition, IStatementSyntax[] Body)>(); for (var setIndex = 0; setIndex < unitTable.UnitSets.Count; setIndex++) { var set = unitTable.UnitSets[setIndex]; var condition = SyntaxFactory.BinaryEqualsExpression(SyntaxFactory.VariableReferenceExpression(LocalCurrentSetVariableName), SyntaxFactory.LiteralExpression(setIndex)); var bodyStatements = new List <IStatementSyntax>(); for (var position = 0; position < unitTable.Types.Count; position++) { var id = set?.UnitIds[position] ?? 0; var unitTypeExpression = RandomUnitProvider.IsRandomUnit(id, out var level) ? SyntaxFactory.InvocationExpression(nameof(ChooseRandomCreep), SyntaxFactory.LiteralExpression(level)) : id == 0 ? SyntaxFactory.LiteralExpression(-1) : SyntaxFactory.FourCCLiteralExpression(id); bodyStatements.Add(SyntaxFactory.SetStatement( groupVarName, SyntaxFactory.LiteralExpression(position), unitTypeExpression)); } ifElseifBlocks.Add((new JassParenthesizedExpressionSyntax(condition), bodyStatements.ToArray())); } var elseClauseStatements = new List <IStatementSyntax>(); for (var position = 0; position < unitTable.Types.Count; position++) { elseClauseStatements.Add(SyntaxFactory.SetStatement( groupVarName, SyntaxFactory.LiteralExpression(position), SyntaxFactory.LiteralExpression(-1))); } statements.Add(SyntaxFactory.IfStatement( ifElseifBlocks.First().Condition, SyntaxFactory.StatementList(ifElseifBlocks.First().Body), ifElseifBlocks.Skip(1).Select(elseIf => new JassElseIfClauseSyntax(elseIf.Condition, SyntaxFactory.StatementList(elseIf.Body))), new JassElseClauseSyntax(SyntaxFactory.StatementList(elseClauseStatements)))); statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitRandomGroups)), statements)); }
protected virtual JassFunctionDeclarationSyntax InitRandomGroups(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var randomUnitTables = map.Info.RandomUnitTables; if (randomUnitTables is null) { throw new ArgumentException($"Function '{nameof(InitRandomGroups)}' cannot be generated without {nameof(MapInfo.RandomUnitTables)}.", nameof(map)); } var statements = new List <IStatementSyntax>(); statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, VariableName.CurrentSet)); statements.Add(JassEmptyStatementSyntax.Value); foreach (var unitTable in randomUnitTables) { statements.Add(new JassCommentStatementSyntax($" Group {unitTable.Index} - {unitTable.Name}")); statements.Add(SyntaxFactory.CallStatement(FunctionName.RandomDistReset)); for (var i = 0; i < unitTable.UnitSets.Count; i++) { statements.Add(SyntaxFactory.CallStatement( FunctionName.RandomDistAddItem, SyntaxFactory.LiteralExpression(i), SyntaxFactory.LiteralExpression(unitTable.UnitSets[i].Chance))); } statements.Add(SyntaxFactory.SetStatement(VariableName.CurrentSet, SyntaxFactory.InvocationExpression(FunctionName.RandomDistChoose))); statements.Add(JassEmptyStatementSyntax.Value); var groupVarName = unitTable.GetVariableName(); var ifElseifBlocks = new List <(IExpressionSyntax Condition, IStatementSyntax[] Body)>(); for (var setIndex = 0; setIndex < unitTable.UnitSets.Count; setIndex++) { var set = unitTable.UnitSets[setIndex]; var condition = SyntaxFactory.BinaryEqualsExpression(SyntaxFactory.VariableReferenceExpression(VariableName.CurrentSet), SyntaxFactory.LiteralExpression(setIndex)); var bodyStatements = new List <IStatementSyntax>(); for (var position = 0; position < unitTable.Types.Count; position++) { var id = set?.UnitIds[position] ?? 0; var unitTypeExpression = RandomUnitProvider.IsRandomUnit(id, out var level) ? SyntaxFactory.InvocationExpression(NativeName.ChooseRandomCreep, SyntaxFactory.LiteralExpression(level)) : id == 0 ? SyntaxFactory.LiteralExpression(-1) : SyntaxFactory.FourCCLiteralExpression(id); bodyStatements.Add(SyntaxFactory.SetStatement( groupVarName, SyntaxFactory.LiteralExpression(position), unitTypeExpression)); } ifElseifBlocks.Add((new JassParenthesizedExpressionSyntax(condition), bodyStatements.ToArray())); } var elseClauseStatements = new List <IStatementSyntax>(); for (var position = 0; position < unitTable.Types.Count; position++) { elseClauseStatements.Add(SyntaxFactory.SetStatement( groupVarName, SyntaxFactory.LiteralExpression(position), SyntaxFactory.LiteralExpression(-1))); } statements.Add(SyntaxFactory.IfStatement( ifElseifBlocks.First().Condition, SyntaxFactory.StatementList(ifElseifBlocks.First().Body), ifElseifBlocks.Skip(1).Select(elseIf => new JassElseIfClauseSyntax(elseIf.Condition, SyntaxFactory.StatementList(elseIf.Body))), new JassElseClauseSyntax(SyntaxFactory.StatementList(elseClauseStatements)))); statements.Add(JassEmptyStatementSyntax.Value); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitRandomGroups)), statements)); }
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)); }
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))); } }
protected virtual JassFunctionDeclarationSyntax CreateAllItems(Map map) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapUnits = map.Units; if (mapUnits is null) { throw new ArgumentException($"Function '{nameof(CreateAllItems)}' cannot be generated without {nameof(MapUnits)}.", nameof(map)); } var statements = new List <IStatementSyntax>(); statements.Add(SyntaxFactory.LocalVariableDeclarationStatement(JassTypeSyntax.Integer, VariableName.ItemId)); foreach (var item in mapUnits.Units.Where(item => CreateAllItemsConditionSingleItem(map, item))) { if (item.IsRandomItem()) { var randomData = item.RandomData; switch (randomData) { case RandomUnitAny randomUnitAny: statements.Add(SyntaxFactory.SetStatement( VariableName.ItemId, SyntaxFactory.InvocationExpression( NativeName.ChooseRandomItemEx, SyntaxFactory.InvocationExpression(NativeName.ConvertItemType, SyntaxFactory.LiteralExpression((int)randomUnitAny.Class)), SyntaxFactory.LiteralExpression(randomUnitAny.Level)))); break; case RandomUnitGlobalTable randomUnitGlobalTable: break; case RandomUnitCustomTable randomUnitCustomTable: statements.Add(SyntaxFactory.CallStatement(FunctionName.RandomDistReset)); var summedChance = 0; foreach (var randomItem in randomUnitCustomTable.RandomUnits) { IExpressionSyntax id = RandomItemProvider.IsRandomItem(randomItem.UnitId, out var itemClass, out var level) ? SyntaxFactory.InvocationExpression( NativeName.ChooseRandomItemEx, SyntaxFactory.InvocationExpression(NativeName.ConvertItemType, SyntaxFactory.LiteralExpression((int)itemClass)), SyntaxFactory.LiteralExpression(level)) : SyntaxFactory.FourCCLiteralExpression(randomItem.UnitId); statements.Add(SyntaxFactory.CallStatement( FunctionName.RandomDistAddItem, id, SyntaxFactory.LiteralExpression(randomItem.Chance))); summedChance += randomItem.Chance; } if (summedChance < 100) { statements.Add(SyntaxFactory.CallStatement( FunctionName.RandomDistAddItem, SyntaxFactory.LiteralExpression(-1), SyntaxFactory.LiteralExpression(100 - summedChance))); } statements.Add(SyntaxFactory.SetStatement( VariableName.ItemId, SyntaxFactory.InvocationExpression(FunctionName.RandomDistChoose))); break; default: break; } statements.Add(SyntaxFactory.IfStatement( SyntaxFactory.BinaryNotEqualsExpression(SyntaxFactory.VariableReferenceExpression(VariableName.ItemId), SyntaxFactory.LiteralExpression(-1)), SyntaxFactory.CallStatement( NativeName.CreateItem, SyntaxFactory.VariableReferenceExpression(VariableName.ItemId), SyntaxFactory.LiteralExpression(item.Position.X), SyntaxFactory.LiteralExpression(item.Position.Y)))); } else { var args = new List <IExpressionSyntax>() { SyntaxFactory.FourCCLiteralExpression(item.TypeId), SyntaxFactory.LiteralExpression(item.Position.X), SyntaxFactory.LiteralExpression(item.Position.Y), }; var hasSkin = item.SkinId != 0 && item.SkinId != item.TypeId; if (hasSkin) { args.Add(SyntaxFactory.FourCCLiteralExpression(item.SkinId)); } statements.Add(SyntaxFactory.CallStatement(hasSkin ? NativeName.BlzCreateItemWithSkin : NativeName.CreateItem, args.ToArray())); } } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(CreateAllItems)), statements)); }
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)); }
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)); }
protected virtual JassFunctionDeclarationSyntax InitUpgrades_Player(Map map, int playerId) { if (map is null) { throw new ArgumentNullException(nameof(map)); } var mapInfo = map.Info; var statements = new List <IStatementSyntax>(); var maxLevel = new Dictionary <int, int>(); var researched = new Dictionary <int, int>(); for (var i = 0; i < mapInfo.UpgradeData.Count; i++) { var upgradeData = mapInfo.UpgradeData[i]; if (upgradeData.Availability != UpgradeAvailability.Available && upgradeData.Players[playerId]) { if (upgradeData.Availability == UpgradeAvailability.Unavailable) { if (maxLevel.TryGetValue(upgradeData.Id, out var level)) { if (upgradeData.Level < level) { maxLevel[upgradeData.Id] = upgradeData.Level; } } else { maxLevel.Add(upgradeData.Id, upgradeData.Level); } } else if (upgradeData.Availability == UpgradeAvailability.Researched) { if (researched.TryGetValue(upgradeData.Id, out var level)) { if (upgradeData.Level > level) { researched[upgradeData.Id] = upgradeData.Level; } } else { researched.Add(upgradeData.Id, upgradeData.Level); } } } } foreach (var tech in maxLevel) { statements.Add(SyntaxFactory.CallStatement( NativeName.SetPlayerTechMaxAllowed, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerId)), SyntaxFactory.FourCCLiteralExpression(tech.Key), SyntaxFactory.LiteralExpression(tech.Value))); } foreach (var tech in researched) { statements.Add(SyntaxFactory.CallStatement( NativeName.SetPlayerTechResearched, SyntaxFactory.InvocationExpression(NativeName.Player, SyntaxFactory.LiteralExpression(playerId)), SyntaxFactory.FourCCLiteralExpression(tech.Key), SyntaxFactory.LiteralExpression(tech.Value + 1))); } return(SyntaxFactory.FunctionDeclaration(SyntaxFactory.FunctionDeclarator(nameof(InitUpgrades_Player) + playerId), statements)); }