public static void CraneTruckGoOut(object obj, ElapsedEventArgs e) { if (!Aircraft.suspendedTargetDowned) { return; } Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; if (main.TruckCraneImg.Visibility == Visibility.Hidden) { return; } craneTruckMove = !craneTruckMove; string craneTrackSource = "truck_crane" + (craneTruckMove ? "_move" : ""); main.TruckCraneImg.Source = Functions.ImageFromResources(craneTrackSource, Aircraft.ImageType.Interface); if (main.TruckCraneImg.Margin.Left > SystemParameters.PrimaryScreenWidth) { main.TruckCraneImg.Visibility = Visibility.Hidden; } else { main.TruckCraneImg.Margin = new Thickness( main.TruckCraneImg.Margin.Left + 1, main.TruckCraneImg.Margin.Top, main.TruckCraneImg.Margin.Right, main.TruckCraneImg.Margin.Bottom ); } })); }
public static void EndGameCleaning() { Statistic.Clean(); fire = false; reheatingGunBurrels = false; lastDegree = 0; Aircraft.allAircraftsInGame = 0; Weather.Restart(Weather.WeatherTypes.good); Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.firePlace.Children.Clear(); main.PlayerName.Text = String.Empty; main.schoolInfoBox.Visibility = Visibility.Hidden; Aircraft.aircrafts.Clear(); Case.cases.Clear(); Shell.shells.Clear(); Weather.weather.Clear(); })); }
public void Shutdown(FirePlace main) { if (friend || airliner) { main.EndGameByShutdown(aircraftName, friend, trainingTug); } else { dead = true; if (suspendedTarget) { suspendedTargetDowned = true; } if (deadSprite) { foreach (DynamicElement d in dynamicElemets) { main.firePlace.Children.Remove(d.element); } ImageSource sprite = Functions.ImageFromResources(aircraftType + "_dead", ImageType.DeadSprite); if (sprite != null) { aircraftImage.Source = sprite; } } Canvas.SetZIndex(aircraftImage, 1); Statistic.Shutdown(this); } }
public static void DrawGansFlashs(FirePlace main, Line gun, int numGuns, double flashThickness) { flashСount++; if (flashСount >= 10) { flashСount = 0; } if ( ((flashСount >= 2) && (flashСount < 5) && (numGuns == 0)) || ((flashСount >= 7) && (numGuns == 1)) ) { Line flash = new Line { X1 = gun.X2, Y1 = gun.Y2 }; int flashSize = rand.Next(1, 4); flash.X2 = gun.X2 + flashSize * Shell.lastCos; flash.Y2 = gun.Y2 - flashSize * Shell.lastSin; flash.Stroke = FlashesColor(); flash.StrokeThickness = flashThickness; main.firePlace.Children.Add(flash); Canvas.SetZIndex(flash, 210); Shell.allLines.Add(flash); } }
private void MessageForTraining(FirePlace main) { if (!trainingSuspendedTarget) { suspendedTargetTimerCount += 1; if (suspendedTargetTimerCount > Constants.TRAINING_TIMEOUT_BEFORE_FIRST_INFO) { main.SchoolMessage(Constants.SUSPENDED_TARGET_INFORMATION, Brushes.SeaGreen, ref trainingSuspendedTarget); } } if (!trainingTurgetTug && suspendedTargetDowned) { main.SchoolMessage(Constants.TRAINING_TUG_INFORMATION, Brushes.BlueViolet, ref trainingTurgetTug); } if (!trainingTurgetPlane && (allAircraftsInGame > Constants.TRAINING_IL28_AT_THE_START)) { main.SchoolMessage(Constants.TRAINING_PLANE_INFORMATION, Brushes.Crimson, ref trainingTurgetPlane); } if (!trainingTurgetDrone && (allAircraftsInGame > Constants.TRAINING_M16K_AT_THE_START)) { main.SchoolMessage(Constants.TRAINING_DRONE_INFORMATION, Brushes.LightSeaGreen, ref trainingTurgetDrone); } }
private static void Lightning(bool thunderclap = false, bool thunderimage = false) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; if (thunderimage) { Image thuderImage = new Image { Height = rand.Next(200, (int)SystemParameters.PrimaryScreenHeight), Source = Functions.ImageFromResources("thunder" + (rand.Next(1, 7)), Aircraft.ImageType.Other), Margin = new Thickness(rand.Next(0, (int)SystemParameters.PrimaryScreenWidth), -10, 0, 0) }; thunderCurrentImage = thuderImage; main.firePlace.Children.Add(thuderImage); } else { if (thunderCurrentImage != null) { main.firePlace.Children.Remove(thunderCurrentImage); } } main.thunderPlace.Background = (Shilka.currentScript == Scripts.ScriptsNames.Yugoslavia ? Brushes.White : Brushes.Black); main.thunderPlace.Visibility = (thunderclap ? Visibility.Visible : Visibility.Hidden); })); }
public static void WreckBreackOffFromAircraft(double startX, double startY, Aircraft.FlightDirectionType direction, int maxSpeed, int maxSize, int number, int randomDistance = 0) { if (rand.Next(Constants.WRECKS_RAND_RANGE) > number) { return; } wreckMutex++; if (wreckMutex > 1) { wreckMutex--; return; } Wrecks newWreck = new Wrecks { x = startX + (randomDistance > 0 ? rand.Next(randomDistance / Constants.WRECKS_SUSP_WRECKS_PART) : 0), y = startY, sin = 0, cos = (direction == Aircraft.FlightDirectionType.Left ? 1 : -1), flightDirection = direction, speed = RandomSpeed(maxSpeed), rotateSpeed = rand.Next(Constants.WRECKS_MIN_ROTATE_SPEED, Constants.WRECKS_MAX_ROTATE_SPEED), rotateDirection = (rand.Next(2) == 0 ? 1 : -1), fly = true }; int wr_rand_num = Constants.WRECKS_TYPE_NUM + 1; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; Image newImage = new Image { Width = rand.Next(maxSize) + Constants.WRECKS_MIN_SIZE, Height = rand.Next(maxSize) + Constants.WRECKS_MIN_SIZE, Source = Functions.ImageFromResources("wrecks" + (Aircraft.rand.Next(1, wr_rand_num)), Aircraft.ImageType.Other), Margin = new Thickness(newWreck.x, newWreck.y, 0, 0) }; newWreck.wreckImage = newImage; main.firePlace.Children.Add(newImage); Wrecks.wrecks.Add(newWreck); })); wreckMutex--; }
public static void Fly(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; wreckMutex++; if (wreckMutex > 1) { wreckMutex--; return; } foreach (var c in wrecks) { c.fall += Constants.FREE_FALL_SPEED; if (Weather.currentWeather == Weather.WeatherTypes.storm) { c.speed = SpeedInStorm(c.speed, ref c.flightDirection); c.cos = (c.flightDirection == Aircraft.FlightDirectionType.Left ? 1 : -1); } c.x = (c.x - c.speed * c.cos); c.y = (c.y - c.speed * c.sin) + c.fall; c.wreckImage.Margin = new Thickness(c.x, c.y, 0, 0); c.rotateDegreeCurrent += (c.rotateSpeed * c.rotateDirection); if (c.rotateDegreeCurrent < -180 || c.rotateDegreeCurrent > 180) { c.rotateDegreeCurrent = 0; } c.wreckImage.RenderTransform = new RotateTransform(c.rotateDegreeCurrent, (c.wreckImage.ActualWidth / 2), (c.wreckImage.ActualHeight / 2)); if (c.x < 0) { c.fly = false; } } for (int x = 0; x < wrecks.Count; x++) { if ((wrecks[x].fly == false) && (wreckMutex == 1)) { main.firePlace.Children.Remove(wrecks[x].wreckImage); wrecks.RemoveAt(x); } } wreckMutex--; })); }
public static void CaseExtractor() { caseMutex++; if (caseMutex > 1) { caseMutex--; return; } Case newCase = new Case { x = Constants.FIRE_WIDTH_CORRECTION / 2, y = Shell.currentHeight - Constants.EXTR_HEIGHT_CORRECTION }; if (Shilka.currentScript == Scripts.ScriptsNames.Libya) { newCase.sin = rand.NextDouble() * (Constants.MAX_FRAGM_SIN_DAMAGED - Constants.MIN_FRAGM_SIN) + Constants.MIN_FRAGM_SIN; newCase.cos = rand.NextDouble() * (Constants.MAX_FRAGM_COS_DAMAGED - Constants.MIN_FRAGM_COS) + Constants.MIN_FRAGM_COS; newCase.speed = rand.Next(Constants.MIN_SPEED, Constants.MAX_SPEED_DAMAGED); } else { newCase.sin = rand.NextDouble() * (Constants.MAX_FRAGM_SIN - Constants.MIN_FRAGM_SIN) + Constants.MIN_FRAGM_SIN; newCase.cos = rand.NextDouble() * (Constants.MAX_FRAGM_COS - Constants.MIN_FRAGM_COS) + Constants.MIN_FRAGM_COS; newCase.speed = rand.Next(Constants.MIN_SPEED, Constants.MAX_SPEED); } newCase.fly = true; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; Image newImage = new Image { Width = Constants.CASE_LENGTH, Height = Constants.CASE_LENGTH, Source = Functions.ImageFromResources("case", Aircraft.ImageType.Other), Margin = new Thickness(newCase.x, newCase.y, 0, 0) }; newCase.caseImage = newImage; main.firePlace.Children.Add(newImage); Case.cases.Add(newCase); })); caseMutex--; }
public static void RadarmMalfunction(object obj, ElapsedEventArgs e) { if (currentScript == Scripts.ScriptsNames.IranIraq) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.RadarImg.RenderTransform = new RotateTransform( RadarmMalfunction(), Constants.RADAR_MALFUNC_X, Constants.RADAR_MALFUNC_Y ); })); } }
public static void HeatingOfGuns(bool shooting) { if (Functions.TossACoin()) { return; } degreeOfHeatingGunBurrels += (shooting ? 1 : -1); int currentDegreeOfHeatinMin = degreeOfHeatingGunBurrelsMin; if (Weather.currentWeather == Weather.WeatherTypes.rain) { currentDegreeOfHeatinMin += Constants.HEATING_IN_RAIN; } else if (Weather.currentWeather == Weather.WeatherTypes.snow) { currentDegreeOfHeatinMin += Constants.HEATING_UNDER_SNOW; } if (degreeOfHeatingGunBurrels < currentDegreeOfHeatinMin) { degreeOfHeatingGunBurrels = currentDegreeOfHeatinMin; } else if (degreeOfHeatingGunBurrels > Constants.GUNS_OVERHEATING) { reheatingGunBurrels = true; fire = false; } else if (degreeOfHeatingGunBurrels < Constants.GUNS_HEAT_UP) { reheatingGunBurrels = false; } if (Shilka.school && !schoolHeating && (degreeOfHeatingGunBurrels > Constants.GUNS_HEAT_UP)) { schoolHeating = true; _ = Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; bool _ = false; main.SchoolMessage(Constants.HEATING_INFORMATION, Brushes.Orange, ref _); })); } }
private void MessagesForSchool(FirePlace main) { if ((allAircraftsInGame > Constants.SCHOOL_AIRLINER_AT_THE_START) && !schoolMixAlready) { main.SchoolMessage(Constants.MIX_INFORMATION, Brushes.Gray, ref schoolMixAlready); } else if (airliner && !schoolAirlinerAlready) { main.SchoolMessage(Constants.AIRLINER_INFORMATION, Brushes.Blue, ref schoolAirlinerAlready); } else if (friend && !schoolFriendAlready) { main.SchoolMessage(Constants.FRIEND_INFORMATION, Brushes.Green, ref schoolFriendAlready); } else if (!schoolEnemyAlready) { main.SchoolMessage(Constants.ENEMY_INFORMATION, Brushes.Red, ref schoolEnemyAlready); } }
public static void SchoolShow(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; if (SchoolTicTac) { main.schoolLabel.Background = Brushes.Black; main.schoolLabel.Foreground = Brushes.White; SchoolTicTac = false; } else { main.schoolLabel.Background = Brushes.Transparent; main.schoolLabel.Foreground = Brushes.Black; SchoolTicTac = true; } })); }
public static void ShowTraining(object obj, ElapsedEventArgs e) { string stat = String.Empty; if (statisticShellsFired > 0) { stat += String.Format("выстрелов: {0}\n", statisticShellsFired); } if (staticticInTarget > 0) { stat += String.Format("попаданий: {0}\n", staticticInTarget); } if (staticticAircraftShutdown > 0) { stat += String.Format("сбито: {0} из {1}\n", staticticAircraftShutdown, statisticAllAircraft); } if (statisticDamaged > 0) { stat += String.Format("повреждено: {0}\n", statisticDamaged); } if (statisticHasGone > 0) { stat += String.Format("упущено: {0}\n", statisticHasGone); } if (statisticShellsFired > 0) { stat += String.Format("температура стволов: {0}°C {1}", Shilka.degreeOfHeatingGunBurrels, (Shilka.reheatingGunBurrels ? " - перегрев!" : String.Empty)); } Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.statShells.Content = stat; })); }
public static void HideHand(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.HandMove.Enabled = false; main.HandMove.Stop(); ThicknessAnimation move = new ThicknessAnimation { Duration = TimeSpan.FromSeconds(1.5), From = main.HandImg.Margin, To = new Thickness( (SystemParameters.PrimaryScreenHeight / 2), SystemParameters.PrimaryScreenHeight, 0, 0 ) }; main.HandImg.BeginAnimation(MarginProperty, move); })); }
public static void Fly(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; caseMutex++; if (caseMutex > 1) { caseMutex--; return; } foreach (var c in cases) { c.fall += Constants.FREE_FALL_SPEED; c.x = (c.x - c.speed * c.cos); c.y = (c.y - c.speed * c.sin) + c.fall; c.caseImage.Margin = new Thickness(c.x, c.y, 0, 0); if (c.x < 0) { c.fly = false; } } for (int x = 0; x < cases.Count; x++) { if ((cases[x].fly == false) && (caseMutex == 1)) { main.firePlace.Children.Remove(cases[x].caseImage); cases.RemoveAt(x); } } caseMutex--; })); }
public static void StartSuspendedTarget() { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.TruckCraneImg.Margin = new Thickness( (SystemParameters.PrimaryScreenWidth - main.TruckCraneImg.Width - Constants.TRAINING_CRANE_LEFT_CORRECTTION), (SystemParameters.PrimaryScreenHeight - main.TruckCraneImg.Height - Constants.TRAINING_CRANE_TOP_CORRECTTION), 0, 0 ); main.TruckCraneImg.Visibility = Visibility.Visible; Aircraft newAircraft = Aircrafts.suspendedTargets[rand.Next(Aircrafts.suspendedTargets.Count)]; newAircraft.Launch( startX: main.TruckCraneImg.Margin.Left - newAircraft.suspendedLeftCorrection, startY: main.TruckCraneImg.Margin.Top + newAircraft.suspendedTopCorrection, suspended: true ); })); }
public static void Fire(object obj, ElapsedEventArgs e) { int currentFragmentation = Constants.FRAGMENTATION + ((Shilka.degreeOfHeatingGunBurrels - 30) / 25); if ((Shilka.currentScript == Scripts.ScriptsNames.Libya) && (rand.Next(Constants.GUN_JAMMING_CHANCE) == 1)) { Array jamming = Enum.GetValues(typeof(gunJammedType)); gunJammed = (gunJammedType)jamming.GetValue(rand.Next(jamming.Length)); } if ( (Shilka.fire || (gunJammed == gunJammedType.alwaysShoot)) && (gunJammed != gunJammedType.doesntShoot) && !((gunJammed != gunJammedType.sometimesShoot) && (rand.Next(Constants.GUN_JAMMING_CHANCE) == 1)) && !Shilka.reheatingGunBurrels ) { fireMutex++; if (fireMutex > 1) { fireMutex--; return; } for (int a = 0; a < Constants.VOLLEY; a++) { Shell newShell = new Shell { fly = true, delay = 0, x = rand.Next((-1 * currentFragmentation), currentFragmentation) + Constants.FIRE_WIDTH_CORRECTION, y = currentHeight + rand.Next((-1 * currentFragmentation), currentFragmentation) - Constants.FIRE_HEIGHT_CORRECTION }; double e1 = Math.Sqrt((ptX * ptX) + (ptY * ptY)); double tryCos = ptX / e1; double trySin = ptY / e1; newShell.cos = (double.IsNaN(tryCos) ? lastCos : tryCos); newShell.sin = (double.IsNaN(trySin) ? lastSin : trySin); lastCos = newShell.cos; lastSin = newShell.sin; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; Image newImage = new Image { Width = Constants.SHELL_LENGTH, Height = Constants.SHELL_THICKNESS }; double angle = (Math.Asin(newShell.sin) * 180 / Math.PI) * -1; newImage.RenderTransform = new RotateTransform(angle); newImage.Source = Functions.ImageFromResources("shell", Aircraft.ImageType.Other); newImage.Margin = new Thickness(newShell.x, newShell.y, 0, 0); newImage.Visibility = Visibility.Hidden; newShell.shellImage = newImage; Canvas.SetZIndex(newImage, 10); main.firePlace.Children.Add(newImage); shells.Add(newShell); })); Statistic.ShellFiredAdd(); Case.CaseExtractor(); } fireMutex--; Shilka.HeatingOfGuns(shooting: true); } else { Shilka.HeatingOfGuns(shooting: false); } }
public static void DrawGuns(FirePlace main) { double currentHeight = Shell.currentHeight; if (currentHeight < 0) { currentHeight = main.ActualHeight; } if (fire) { gunReturn++; } if (gunReturn > Constants.GUN_RETURN_TIMEOUT) { gunReturn = 0; } double[,] mountXY = new double[2, 2] { { 0, 0 }, { 0, 0 } }; for (int numGuns = 0; numGuns <= 1; numGuns++) { Line gun = new Line { X1 = Constants.FIRE_WIDTH_CORRECTION - 3 - (12 * numGuns), Y1 = currentHeight - Constants.FIRE_HEIGHT_CORRECTION + 5 - (9 * numGuns) }; int gunReturnLen = 0; if (fire && ( (gunReturn < Constants.GUN_MIDDLE_TIMEOUT && numGuns == 0) || (gunReturn >= Constants.GUN_MIDDLE_TIMEOUT && numGuns == 1) )) { gunReturnLen = Constants.GUN_RETURN_LEN; } gun.X2 = gun.X1 + (Constants.GUNS_LENGTH - gunReturnLen) * Shell.lastCos; gun.Y2 = gun.Y1 - (Constants.GUNS_LENGTH - gunReturnLen) * Shell.lastSin; mountXY[numGuns, 0] = gun.X1 + (Constants.GUNS_LENGTH - gunReturnLen - Constants.GUN_NOUNT_LENGTH) * Shell.lastCos; mountXY[numGuns, 1] = gun.Y1 - (Constants.GUNS_LENGTH - gunReturnLen - Constants.GUN_NOUNT_LENGTH) * Shell.lastSin; byte colorOfGuns = ( degreeOfHeatingGunBurrels > Constants.HEATING_COLOR_BASE ? (byte)((degreeOfHeatingGunBurrels - Constants.HEATING_COLOR_BASE) / 2) : (byte)0 ); if (Shilka.night) { int color = (degreeOfHeatingGunBurrels < Constants.HEATING_COLOR_BASE ? 0 : 360 - degreeOfHeatingGunBurrels); gun.Stroke = (color > 0 ? new SolidColorBrush(Color.FromRgb((byte)255, (byte)color, (byte)color)) : Brushes.White); } else if (colorOfGuns == 0) { gun.Stroke = (Shilka.night ? Brushes.White : Brushes.Black); } else { gun.Stroke = new SolidColorBrush(Color.FromRgb((byte)(colorOfGuns - Constants.HEATING_COLOR_BASE), 0, 0)); } gun.StrokeThickness = Constants.GUN_THICKNESS; main.firePlace.Children.Add(gun); Canvas.SetZIndex(gun, 200); Shell.allLines.Add(gun); if (Shilka.currentScript == Scripts.ScriptsNames.Vietnam) { Line backGun = new Line { X1 = gun.X1, X2 = gun.X2, Y1 = gun.Y1, Y2 = gun.Y2, StrokeThickness = gun.StrokeThickness + 2, Stroke = Brushes.White }; main.firePlace.Children.Add(backGun); Canvas.SetZIndex(backGun, 199); Shell.allLines.Add(backGun); } if (fire) { DrawGansFlashs(main, gun, numGuns, gun.StrokeThickness); } } Line gunMount = new Line { X1 = mountXY[0, 0], Y1 = mountXY[0, 1], X2 = mountXY[1, 0], Y2 = mountXY[1, 1], StrokeThickness = 1, Stroke = (Shilka.night ? Brushes.White : Brushes.Black) }; main.firePlace.Children.Add(gunMount); Canvas.SetZIndex(gunMount, 200); Shell.allLines.Add(gunMount); }
public static void ShowGame(object obj, ElapsedEventArgs e) { string stat = String.Empty; Calc(out double baseForPercent, out int shutdownPercent, out int damagedPercent, out int statisticWithoutDamage, out double chance, out int inTargetPercent, out int shellsForShutdown); if (statisticShellsFired > 0) { stat += String.Format("выстрелов: {0}", statisticShellsFired); if (staticticAircraftShutdown > 0) { stat += String.Format(" ( {0} выстр./сбитый )", shellsForShutdown); } stat += "\n"; } if (staticticInTarget > 0) { stat += String.Format( "попаданий: {0} ( {1}%{2} )\n", staticticInTarget, inTargetPercent, GetDynamic(inTargetPercent, "inTarget") ); } if (staticticAircraftShutdown > 0) { stat += String.Format( "сбито: {0} ( {1}%{2} )", staticticAircraftShutdown, shutdownPercent, GetDynamic(inTargetPercent, "shotsown") ); } if (statisticDamaged > 0) { stat += String.Format( "{0} повреждено: {1} ( {2}%{3} )\n", (staticticAircraftShutdown == 0 ? String.Empty : " +"), statisticDamaged, damagedPercent, GetDynamic(damagedPercent, "damaged") ); } else if (staticticAircraftShutdown > 0) { stat += "\n"; } if (statisticHasGone > 0) { int hasGonePercent = (int)(statisticHasGone * baseForPercent); if ((hasGonePercent == 0) && (statisticHasGone > 0)) { hasGonePercent = 1; } stat += String.Format( "упущено: {0} ( {1}%{2}, последний {3} )", statisticHasGone, hasGonePercent, GetDynamic(hasGonePercent, "hasGone"), statisticLastHasGone ); if (statisticDamaged < statisticHasGone) { stat += String.Format(", в т.ч. неповредённых: {0} ( {1}%{2} )", (statisticHasGone - statisticDamaged), statisticWithoutDamage, GetDynamic(statisticWithoutDamage, "withoutDamage") ); } stat += "\n"; } if (statisticAmountOfDamage > 0 && !Shilka.school && !Shilka.training) { stat += String.Format("нанесён ущерб: {0}", HumanReadableSumm(statisticAmountOfDamage)); if (statisticShutdownFlag) { stat += String.Format(" ( +{0} млн $ сбит {1} )", statisticLastDamagePrice, statisticLastDamageType); } else { stat += String.Format(" ( +{0:f2} млн ${1} повреждён {2} )", statisticLastDamagePrice, (seriousDamage ? " серьёзно" : String.Empty), statisticLastDamageType); } stat += "\n"; } if (statisticFriendDamage > 0) { stat += String.Format("повреждено своих: {0} ( последний {1} )\n", statisticFriendDamage, statisticLastDamageFriend); } if (statisticAirlinerDamage > 0) { stat += String.Format("повреждено гражданских: {0} ( последний {1} )\n", statisticAirlinerDamage, statisticLastDamageAirliner); } if (statisticAllAircraft > 0 && !Shilka.training) { stat += String.Format("удача: {0:f2}", chance) + "\n"; } if (statisticShellsFired > 0) { stat += String.Format("температура стволов: {0}°C{1}{2}", Shilka.degreeOfHeatingGunBurrels, (Shilka.reheatingGunBurrels ? " - перегрев!" : String.Empty), (Shilka.degreeOfHeatingGunBurrels > Constants.GUNS_HEATING_WARN ? " ⚠" : String.Empty) ); } Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; main.statShells.Content = stat; })); }
public static void Fly(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; if (animationStop) { return; } foreach (var line in allLines) { main.firePlace.Children.Remove(line); } allLines.Clear(); Shilka.DrawGuns(main); fireMutex++; foreach (var shell in shells) { shell.x = (shell.x + Constants.SHELL_SPEED * shell.cos); shell.y = (shell.y - Constants.SHELL_SPEED * shell.sin); shell.shellImage.Margin = new Thickness(shell.x, shell.y, 0, 0); foreach (Aircraft aircraft in Aircraft.aircrafts) { if ( shell.fly && (shell.y < (aircraft.aircraftImage.Margin.Top + aircraft.aircraftImage.Height)) && (shell.y > (aircraft.aircraftImage.Margin.Top)) && (shell.x > (aircraft.aircraftImage.Margin.Left)) && (shell.x < (aircraft.aircraftImage.Margin.Left + aircraft.aircraftImage.Width)) ) { if (aircraft.cloud) { continue; } bool itsOnlyTargetPlane = false; if (Shilka.training && (aircraft.aircraftType == "il28bm_77bm2")) { if (aircraft.TargetTubHit(shell, ref itsOnlyTargetPlane)) { continue; } } if (itsOnlyTargetPlane && aircraft.fly && (aircraft.tragetTugHitPoint <= 0)) { aircraft.TargetTugDisengaged(); } Line shellTrace = new Line { X1 = shell.x + shell.cos, Y1 = shell.y - shell.sin, X2 = shell.x + Constants.FLASH_SIZE, Y2 = shell.y - Constants.FLASH_SIZE }; shell.flash = true; shellTrace.Stroke = Brushes.Red; shellTrace.StrokeThickness = Constants.FLASH_SIZE; Wrecks.WreckBreackOffFromAircraft( startX: shell.x, startY: shell.y, direction: aircraft.flightDirection, maxSpeed: (aircraft.zeroSpeed ? 0 : (int)aircraft.speed), maxSize: aircraft.wrecksMaxSize, number: aircraft.wrecksNumber, randomDistance: (aircraft.zeroSpeed ? aircraft.size[0] : 0) ); if (aircraft.weight == Aircraft.WeightType.Light) { aircraft.y -= Constants.THROWS_UP_BY_HITS; } else if (aircraft.weight == Aircraft.WeightType.Middle) { aircraft.y -= Constants.THROWS_UP_BY_HITS_FOR_MIDDLE_AIRCRAFT; } main.firePlace.Children.Add(shellTrace); Canvas.SetZIndex(shellTrace, 20); allLines.Add(shellTrace); Statistic.ShellFiredAdd(inTarget: true); if (itsOnlyTargetPlane) { shell.fly = false; continue; } aircraft.hitpoint -= 1; if (aircraft.hitpoint <= 0 && !aircraft.dead) { aircraft.Shutdown(main); } double planeMiddle = aircraft.aircraftImage.Margin.Left + aircraft.aircraftImage.Width / 2; aircraft.placeOfDamage = (shell.x < planeMiddle ? 1 : -1); } else if (shell.flash) { shell.fly = false; } } if ((shell.delay >= Constants.SHELL_DELAY) && (shell.shellImage.Visibility == Visibility.Hidden)) { shell.shellImage.Visibility = Visibility.Visible; } if ((shell.y < 0) || (shell.x > currentWidth)) { shell.fly = false; } else if (shell.delay < Constants.SHELL_DELAY) { shell.delay++; } } for (int x = 0; x < shells.Count; x++) { if ((shells[x].fly == false) && (fireMutex == 1)) { main.firePlace.Children.Remove(shells[x].shellImage); shells.RemoveAt(x); } } fireMutex--; })); }
public void Launch(double?startX = null, double?startY = null, FlightDirectionType?startDirection = null, bool dead = false, bool transformation = false, bool suspended = false, bool swarm = false) { if (!transformation && (!Shilka.training || !cloud)) { allAircraftsInGame += 1; } Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; zIndexType?zIndex = null; Image newAircraftImage = new Image { Width = size[0], Height = size[1] }; Aircraft newAircraft = Clone(); newAircraft.dead = dead; newAircraft.suspendedTarget = suspended; newAircraft.y = startY ?? rand.Next(maxAltitudeGlobal, Aircrafts.minAltitudeGlobal); if ((newAircraft.minAltitude != -1) && (newAircraft.y > newAircraft.minAltitude)) { newAircraft.y = newAircraft.minAltitude; } FlightDirectionType newDirection = startDirection ?? (Functions.TossACoin() ? FlightDirectionType.Right : FlightDirectionType.Left); if ((Weather.currentWeather == Weather.WeatherTypes.storm) && cloud) { newDirection = Weather.stormDirection; } if ((Shilka.currentScript == Scripts.ScriptsNames.Belgrad) && !cloud) { if (friend) { newDirection = FlightDirectionType.Right; } else { newDirection = FlightDirectionType.Left; } } newAircraft.flightDirection = newDirection; int swarmDistance = (swarm ? rand.Next(20, Constants.UAV_SWARM_DISTANCE) : 0); if (newDirection == FlightDirectionType.Right) { newAircraft.x = -1 * newAircraftImage.Width - swarmDistance; } else { newAircraft.x = Application.Current.MainWindow.Width + swarmDistance; } newAircraft.x = startX ?? newAircraft.x; newAircraftImage.Source = Functions.ImageFromResources( imageName: aircraftType, type: (newAircraft.cloud ? ImageType.Other : ImageType.Aircraft) ); bool flightLeftAndNotCloud = (newAircraft.flightDirection == FlightDirectionType.Left) && !cloud; bool flightRightAndCloud = Functions.TossACoin() && cloud; if (flightLeftAndNotCloud || flightRightAndCloud) { newAircraftImage.FlowDirection = FlowDirection.RightToLeft; } newAircraftImage.Margin = new Thickness(newAircraft.x, newAircraft.y, 0, 0); if ((elements != null) && (elements.Count > 0)) { zIndex = (rand.Next(2) > 0 ? zIndexType.inFront : zIndexType.Behind); foreach (DynamicElement d in elements) { DynamicElement tmp = DynamicElement.Clone(d); tmp.element = new Image { Margin = new Thickness(newAircraft.x, newAircraft.y, 0, 0), Source = Functions.ImageFromResources(d.elementName, ImageType.DynamicElement) }; tmp.rotateDegreeCurrent = d.startDegree; if ((newAircraft.flightDirection == FlightDirectionType.Right) && !d.mirror) { tmp.element.FlowDirection = FlowDirection.RightToLeft; } else if ((newAircraft.flightDirection == FlightDirectionType.Left) && d.mirror) { tmp.element.FlowDirection = FlowDirection.RightToLeft; } newAircraft.dynamicElemets.Add(tmp); bool flightRightAndZRotate = ( (newAircraft.flightDirection == FlightDirectionType.Right) && (d.movingType == DynamicElement.MovingType.zRotate) ); int newZIndex = 0; bool inFront = (zIndex == zIndexType.inFront); if (d.background || flightRightAndZRotate) { newZIndex = (inFront ? 65 : 25); } else if (newAircraft.flightDirection == FlightDirectionType.Right) { newZIndex = (inFront ? 85 : 45); } else { newZIndex = (inFront ? 75 : 35); } Canvas.SetZIndex(tmp.element, newZIndex); main.firePlace.Children.Add(tmp.element); } } int randomSpeed = (cloud ? 0 : rand.Next(3)); newAircraft.speed = (speed < 1 ? Constants.STANDART_SPEED : speed) + randomSpeed; if ((Shilka.currentScript == Scripts.ScriptsNames.Khmeimim) && !friend && !airliner && !cloud) { speed = Constants.UAC_SWARM_SPEED; } if (newAircraft.minAltitude == -1) { newAircraft.minAltitude = Aircrafts.minAltitudeGlobal; } if (((!friend && !airliner) || (Shilka.training && !cloud && friend)) && !transformation) { Statistic.NewAircraftAdd(this); } if (suspended) { Canvas.SetZIndex(newAircraftImage, 101); } else if (zIndex != null) { int newZIndex = 0; bool inFront = (zIndex == zIndexType.inFront); if (newAircraft.flightDirection == FlightDirectionType.Right) { newZIndex = (inFront ? 80 : 40); } else { newZIndex = (inFront ? 70 : 30); } Canvas.SetZIndex(newAircraftImage, newZIndex); } else { Canvas.SetZIndex(newAircraftImage, (cloud ? 100 : 50)); } if (Shilka.school || !cloud) { Label aircraftLabelName = new Label { Content = newAircraft.GetAircraftFullName() }; newAircraft.aircraftSchoolName = aircraftLabelName; Brush labelNameColor = null; if (airliner) { labelNameColor = Brushes.Blue; } else if (friend) { labelNameColor = Brushes.Green; } else { labelNameColor = Brushes.Red; } newAircraft.aircraftSchoolName.Foreground = labelNameColor; Canvas.SetZIndex(aircraftLabelName, Canvas.GetZIndex(newAircraftImage)); main.firePlace.Children.Add(aircraftLabelName); if (!airliner && !friend) { Label aircraftLabelPrice = new Label { Content = GetAircraftPriceLine() }; newAircraft.aircraftSchoolPrice = aircraftLabelPrice; newAircraft.aircraftSchoolPrice.Foreground = Brushes.Gray; Canvas.SetZIndex(aircraftLabelPrice, Canvas.GetZIndex(newAircraftImage)); main.firePlace.Children.Add(aircraftLabelPrice); } } if (Shilka.school && !newAircraft.cloud) { newAircraft.MessagesForSchool(main); } if (Shilka.training) { newAircraft.MessageForTraining(main); } newAircraft.aircraftImage = newAircraftImage; main.firePlace.Children.Add(newAircraftImage); aircrafts.Add(newAircraft); })); }
public static void Fly(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; foreach (Aircraft aircraft in aircrafts) { if (!aircraft.suspendedTarget) { if ((aircraft.cloud || aircraft.aerostat) && (Weather.currentWeather == Weather.WeatherTypes.storm)) { aircraft.speed = SpeedInStorm(aircraft.speed, ref aircraft.flightDirection); } double escape = (((aircraft.hitpoint < aircraft.hitpointMax) && !aircraft.cantEscape) ? Constants.ESCAPE_COEFFICIENT : 1); double direction = (aircraft.flightDirection == FlyObject.FlightDirectionType.Left ? -1 : 1); double tailWind = 1; if (Weather.currentWeather == Weather.WeatherTypes.storm) { tailWind = (aircraft.flightDirection == Weather.stormDirection ? 1.3 : 0.7); } aircraft.x += aircraft.speed * escape * tailWind * direction; } if (aircraft.dead) { aircraft.y += aircraft.DeadFallSpeed(); if ((aircraft.dynamicElemets.Count == 0 || aircraft.deadSprite) && !aircraft.aerostat) { double angle = aircraft.FlyAngle(); aircraft.angleOfAttack += (angle * aircraft.placeOfDamage); aircraft.aircraftImage.RenderTransform = new RotateTransform( aircraft.angleOfAttack, (aircraft.aircraftImage.ActualWidth / 2), (aircraft.aircraftImage.ActualHeight / 2) ); } } else if (aircraft.suspendedTarget) { double angleDirection = 0; if (suspendedTargetAngle > Constants.TRAINING_CRANE_ANGLE_MAX) { angleDirection = -1; } else if (suspendedTargetAngle < (Constants.TRAINING_CRANE_ANGLE_MAX * -1)) { angleDirection = 1; } else { angleDirection = rand.NextDouble() * 2 - 1; } aircraft.angleOfAttack += Constants.TRAINING_CRANE_ANGLE_CHANGE_SPEED * angleDirection; aircraft.aircraftImage.RenderTransform = new RotateTransform( aircraft.angleOfAttack, (aircraft.aircraftImage.ActualWidth / 2), (aircraft.aircraftImage.ActualHeight / 2) ); } else if (!aircraft.aerostat && !aircraft.cloud && !aircraft.suspendedTarget) { aircraft.tangageDelay++; if (aircraft.tangageDelay > Constants.TANGAGE_DELAY) { aircraft.tangageDelay = 0; aircraft.tangage = Constants.TANGAGE_SPEED * (rand.NextDouble() * 2 - 1); } aircraft.y += aircraft.tangage; if (aircraft.y > aircraft.minAltitude) { aircraft.y = aircraft.minAltitude; } } bool notSwarmScript = Shilka.currentScript != Scripts.ScriptsNames.Khmeimim; if ((aircraft.maxAltitude >= 0) && (aircraft.y < aircraft.maxAltitude) && notSwarmScript) { aircraft.y = aircraft.maxAltitude; } else if (aircraft.y < maxAltitudeGlobal) { aircraft.y = maxAltitudeGlobal; } if ( (((aircraft.x + aircraft.aircraftImage.Width) < 0) && (aircraft.flightDirection == FlightDirectionType.Left)) || ((aircraft.x > main.Width) && (aircraft.flightDirection == FlightDirectionType.Right)) ) { aircraft.fly = false; Statistic.Change(aircraft); } aircraft.aircraftImage.Margin = new Thickness(aircraft.x, aircraft.y, 0, 0); foreach (DynamicElement d in aircraft.dynamicElemets) { double xDirection = (aircraft.flightDirection == FlightDirectionType.Left ? d.x_left : d.x_right); d.element.Margin = new Thickness(aircraft.x + xDirection, aircraft.y + d.y, 0, 0); if (d.movingType == DynamicElement.MovingType.zRotate) { int direction = (aircraft.flightDirection == FlyObject.FlightDirectionType.Left ? 1 : -1); d.rotateDegreeCurrent += (Constants.ROTATE_STEP * direction); if (d.rotateDegreeCurrent < -180 || d.rotateDegreeCurrent > 180) { d.rotateDegreeCurrent = 0; } d.element.RenderTransform = new RotateTransform(d.rotateDegreeCurrent, (d.element.ActualWidth / 2), (d.element.ActualHeight / 2)); } if (d.movingType == DynamicElement.MovingType.xRotate || d.movingType == DynamicElement.MovingType.yRotate) { int direction = (d.positiveDirection ? 1 : -1); d.rotateDegreeCurrent += ((d.slowRotation ? Constants.SLOW_ROTATION : Constants.FAST_ROTATION) * direction); if (d.rotateDegreeCurrent < Constants.ROTATION_REVERT) { if (d.backSide) { d.element.Source = Functions.ImageFromResources( d.elementName + (d.currentSide ? String.Empty : "_back"), ImageType.DynamicElement ); } d.currentSide = !d.currentSide; d.positiveDirection = true; } else if (d.rotateDegreeCurrent >= 1) { d.positiveDirection = false; if (d.oneWay) { d.element.Source = Functions.ImageFromResources(d.elementName, ImageType.DynamicElement); d.currentSide = !d.currentSide; } } if (d.movingType == DynamicElement.MovingType.xRotate) { d.element.RenderTransform = new ScaleTransform(d.rotateDegreeCurrent, 1, (d.element.ActualWidth / 2), 0); } else { d.element.RenderTransform = new ScaleTransform(1, d.rotateDegreeCurrent, 0, (d.element.ActualHeight / 2)); } } } if (Shilka.school && !aircraft.cloud) { aircraft.aircraftSchoolName.Content = aircraft.GetAircraftFullName(); aircraft.aircraftSchoolName.Margin = new Thickness(aircraft.x, aircraft.y + aircraft.aircraftImage.Height, 0, 0); } if (Shilka.school && !aircraft.cloud && !aircraft.friend && !aircraft.airliner) { aircraft.aircraftSchoolPrice.Content = aircraft.GetAircraftPriceLine(); aircraft.aircraftSchoolPrice.Margin = new Thickness(aircraft.x, aircraft.y + aircraft.aircraftImage.Height + 16, 0, 0); } } for (int x = 0; x < aircrafts.Count; x++) { if (aircrafts[x].fly == false) { main.firePlace.Children.Remove(aircrafts[x].aircraftImage); foreach (DynamicElement d in aircrafts[x].dynamicElemets) { main.firePlace.Children.Remove(d.element); } if (Shilka.school) { main.firePlace.Children.Remove(aircrafts[x].aircraftSchoolName); } aircrafts.RemoveAt(x); } } })); }
public static void Change(object obj, ElapsedEventArgs e) { if (Shilka.training || Shilka.school) { return; } if ((thundar != 0) || (currentWeather == WeatherTypes.storm)) { Thunder(); } if (weatherCycle < Constants.WEATHER_CYCLE) { weatherCycle += 1; if (currentWeather == WeatherTypes.storm) { if (weatherCycle.ToString().Contains("00")) { stormDirection = (rand.Next(2) > 0 ? Aircraft.FlightDirectionType.Right : Aircraft.FlightDirectionType.Left); } } } else { Restart(); } if (currentWeather == WeatherTypes.good) { return; } int newWeatherElementsCount = (currentWeather == WeatherTypes.storm ? 4 : 1); for (int iterator = 0; iterator < newWeatherElementsCount; iterator++) { Weather newWeather = new Weather(); if (currentWeather == WeatherTypes.storm) { newWeather.x = rand.Next((int)SystemParameters.PrimaryScreenWidth * -1, (int)SystemParameters.PrimaryScreenWidth * 2); newWeather.y = 0; } else if (currentWeather == WeatherTypes.sand) { newWeather.x = 0; newWeather.y = rand.Next(0, (int)SystemParameters.PrimaryScreenHeight); } else { newWeather.x = rand.Next(0, (int)SystemParameters.PrimaryScreenWidth); newWeather.y = 0; } newWeather.speed = rand.Next(Constants.MIN_SPEED, Constants.MAX_SPEED); newWeather.fly = true; newWeather.type = currentWeather; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { Image newImage = new Image(); string imageName; if ((currentWeather == WeatherTypes.rain) || (currentWeather == WeatherTypes.storm)) { newImage.Width = rand.Next(Constants.RAIN_MIN_WIDTH, Constants.RAIN_MAX_WIDTH); newImage.Height = rand.Next(Constants.RAIN_MIN_HEIGHT, Constants.RAIN_MAX_HEIGHT); imageName = "rain" + rand.Next(1, Constants.MAX_RAIN_TYPE + 1).ToString(); } else if (currentWeather == WeatherTypes.sand) { newImage.Width = Constants.CASE_LENGTH; newImage.Height = Constants.CASE_LENGTH; imageName = "case"; } else { newImage.Width = rand.Next(Constants.SNOW_MIN_SIZE, Constants.SNOW_MAX_SIZE); newImage.Height = rand.Next(Constants.SNOW_MIN_SIZE, Constants.SNOW_MAX_SIZE); imageName = "snow" + rand.Next(1, Constants.MAX_SNOW_TYPE + 1).ToString(); } newImage.Source = Functions.ImageFromResources(imageName, Aircraft.ImageType.Other); newImage.Margin = new Thickness(newWeather.x, newWeather.y, 0, 0); newWeather.weatherImage = newImage; FirePlace main = (FirePlace)Application.Current.MainWindow; Canvas.SetZIndex(newImage, 120); main.firePlace.Children.Add(newImage); Weather.weather.Add(newWeather); })); } }
public static void Fly(object obj, ElapsedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { weatherMutex += 1; if (weatherMutex > 1) { weatherMutex -= 1; return; } FirePlace main = (FirePlace)Application.Current.MainWindow; foreach (Weather w in weather) { if (w.type == WeatherTypes.snow) { if (rand.Next(Constants.SNOW_DIRECTION_CHANGE_CHANCE) == 1) { w.direction = rand.Next( (Constants.SNOW_DIRECTION_FLY_SPEED * -1), Constants.SNOW_DIRECTION_FLY_SPEED + 1 ); } w.x += w.direction; } if (w.type == WeatherTypes.sand) { if (rand.Next(Constants.SNOW_DIRECTION_CHANGE_CHANCE) == 1) { w.direction = rand.Next( (Constants.SNOW_DIRECTION_FLY_SPEED * -1), Constants.SNOW_DIRECTION_FLY_SPEED + 1 ); } w.y += w.direction; w.x = (w.x + w.speed); } else { w.y = (w.y + w.speed); } if (currentWeather == WeatherTypes.storm) { w.x += Constants.STORM_FLY_SPEED * (stormDirection == Aircraft.FlightDirectionType.Right ? 1 : -1); } w.weatherImage.Margin = new Thickness(w.x, w.y, 0, 0); if (w.y > SystemParameters.PrimaryScreenHeight + 100) { w.fly = false; } if ((w.type == WeatherTypes.sand) && (w.x > SystemParameters.PrimaryScreenWidth + 10)) { w.fly = false; } } for (int x = weather.Count - 1; x >= 0; x--) { if ((weather[x].fly == false) && (weatherMutex == 1)) { main.firePlace.Children.Remove(weather[x].weatherImage); weather.RemoveAt(x); } } weatherMutex = 0; })); }