示例#1
0
        public void Event_SelectCelestialObject(ICelestialObject celestialObject, ICelestialObject spaceship)
        {
            if (txtObjectName.InvokeRequired)
            {
                RefreshCallback d = Event_SelectCelestialObject;
                Invoke(d, celestialObject, spaceship);
                return;
            }

            if (celestialObject != null)
            {
                txtObjectName.Text           = celestialObject.Name;
                txtObjectClassification.Text = celestialObject.Classification.ToString();

                txtDirection.Text = $@"{celestialObject.Direction:N2}%";
                txtDistance.Text  = $@"{Coordinates.GetDistance(celestialObject.GetLocation(), spaceship.GetLocation()):N2}%";
                txtSignature.Text = $@"{celestialObject.Signature:N2}%";
                txtSpeed.Text     = $@"{celestialObject.Speed:N2}%";
            }
            else
            {
                if (SelectedCelestialObject == null)
                {
                    txtObjectName.Text           = @"No Object Selected";
                    txtObjectClassification.Text = @"";

                    txtDirection.Text = @"???";
                    txtDistance.Text  = @"???";
                    txtSignature.Text = @"???";
                    txtSpeed.Text     = @"???";
                }
            }
        }
示例#2
0
        private Hashtable EnqueueMovementHistory(ICelestialObject mapCelestialObject, Hashtable allObjectsHistory)
        {
            var previousIteration = new SpaceMapObjectLocation
            {
                Distance    = SpaceMapTools.GetDistance(mapCelestialObject.GetLocation(), mapCelestialObject.GetLocation()),
                Direction   = mapCelestialObject.Direction,
                Status      = MovementType.Linear,
                Coordinates = mapCelestialObject.GetLocation()
            };

            if (allObjectsHistory.ContainsKey(mapCelestialObject.Id) == false)
            {
                // New celestial object in history collection
                var initialIteration = new SpaceMapObjectLocation
                {
                    Distance    = SpaceMapTools.GetDistance(mapCelestialObject.GetLocation(), mapCelestialObject.GetLocation()),
                    Direction   = mapCelestialObject.Direction,
                    Status      = MovementType.Linear,
                    Coordinates = Coordinates.MoveObject(mapCelestialObject.GetLocation(), 2000,
                                                         (mapCelestialObject.Direction - 180).To360Degrees())
                };

                var initialHistory = new FixedSizedQueue <SpaceMapObjectLocation>(_historyBufferSize);

                initialHistory.Enqueue(initialIteration);

                initialHistory.Enqueue(previousIteration);

                allObjectsHistory.Add(mapCelestialObject.Id, initialHistory);

                return(allObjectsHistory);
            }

            // Add new history point to exist celestial object movement history

            if (!(allObjectsHistory[mapCelestialObject.Id] is FixedSizedQueue <SpaceMapObjectLocation> currentObjectMovementHistory))
            {
                return(allObjectsHistory);
            }

            currentObjectMovementHistory.Enqueue(previousIteration);

            allObjectsHistory[mapCelestialObject.Id] = currentObjectMovementHistory;

            return(allObjectsHistory);
        }
示例#3
0
        private void FillControls(Spaceship targetSpaceship, ICelestialObject playerSpaceship)
        {
            txtCelestialObjectName.Text = targetSpaceship.Name;

            var shieldsMax    = (int)targetSpaceship.ShieldsMax;
            var shieldCurrent = (int)targetSpaceship.Shields;

            crlShields.Maximum      = shieldsMax;
            crlShields.CurrentValue = shieldCurrent;
            crlShields.Refresh();

            if (txtDirection.Text != Math.Round(targetSpaceship.Direction, 2) + "")
            {
                txtDirection.Text = Math.Round(targetSpaceship.Direction, 2) + "";
            }

            if (txtSpeed.Text != Math.Round(targetSpaceship.Speed, 2) + "")
            {
                txtSpeed.Text = Math.Round(targetSpaceship.Speed, 2) + "";
            }

            if (txtDistance.Text != Math.Round(GeometryTools.Distance(targetSpaceship.GetLocation(), playerSpaceship.GetLocation()), 2) + "")
            {
                txtDistance.Text = Math.Round(GeometryTools.Distance(targetSpaceship.GetLocation(), playerSpaceship.GetLocation()), 2) + "";
            }
        }
示例#4
0
        public static void DrawTrajectory(GameSession gameSession, ICelestialObject spaceShip, ICelestialObject targetObject, Graphics graphics, ScreenParameters screenParameters)
        {
            var pointCurrentLocation      = new PointF(spaceShip.PositionX, spaceShip.PositionY);
            var pointTargetLocation       = new PointF(targetObject.PositionX, targetObject.PositionY);
            var pointCenterTargetLocation = new PointF(targetObject.PositionX, targetObject.PositionY);
            var prevPointCurrentLocation  = new PointF(spaceShip.PositionX, spaceShip.PositionY);

            List <ObjectLocation> result = null;

            var movementType = gameSession.GetMovementType(spaceShip.Id);

            if (movementType == CommandTypes.Orbit)
            {
                var trajectoryOrbit = AllIn.GetRadiusPoint(spaceShip.GetLocation(), pointTargetLocation, 50, spaceShip.Direction, spaceShip.Speed);

                pointTargetLocation = new Point((int)trajectoryOrbit.StartPoint.X, (int)trajectoryOrbit.StartPoint.Y);

                result = AllIn.GetTrajectoryOrbit(pointCurrentLocation, pointTargetLocation, spaceShip.Direction, spaceShip.Speed, 200);
            }

            if (movementType == CommandTypes.AlignTo)
            {
                result = AllIn.GetTrajectoryApproach(pointCurrentLocation, pointTargetLocation, spaceShip.Direction, spaceShip.Speed, 200);
            }


            int temp      = 0;
            int iteration = 0;

            var screenCurrentObjectLocation  = new PointF(0, 0);
            var screenPreviousObjectLocation = new PointF(0, 0);

            bool isDrawConnectionLine = true;

            var points = new List <PointF>();;

            foreach (var objectLocation in result)
            {
                screenCurrentObjectLocation = UI.ToScreenCoordinates(screenParameters, objectLocation.Coordinates);

                points.Add(new PointF(screenCurrentObjectLocation.X, screenCurrentObjectLocation.Y));
            }


            if (points.Count < 2)
            {
                return;
            }

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            // Draw arc to screen.
            graphics.DrawLines(new Pen(Color.FromArgb(18, 18, 18), 4), points.ToArray());
            graphics.DrawLines(new Pen(Color.FromArgb(22, 22, 22), 2), points.ToArray());
            graphics.DrawLines(new Pen(Color.FromArgb(28, 28, 28), 1), points.ToArray());

            var pen = new Pen(Color.Red, 1);// { StartCap = LineCap.ArrowAnchor };

            foreach (var objectLocation in result)
            {
                iteration++;

                screenCurrentObjectLocation  = UI.ToScreenCoordinates(screenParameters, objectLocation.Coordinates);
                screenPreviousObjectLocation = UI.ToScreenCoordinates(screenParameters, prevPointCurrentLocation);

                PointF[] linePoints =
                {
                    new PointF(screenCurrentObjectLocation.X,  screenCurrentObjectLocation.Y),
                    new PointF(screenPreviousObjectLocation.X, screenPreviousObjectLocation.Y)
                };

                graphics.DrawLines(pen, linePoints);

                prevPointCurrentLocation = new PointF(objectLocation.Coordinates.X, objectLocation.Coordinates.Y);

                //temp++;
                //if (temp == 1)
                //{
                //    temp = 0;
                //    graphics.FillEllipse(new SolidBrush(Color.DarkOliveGreen), screenCurrentObjectLocation.X - 1, screenCurrentObjectLocation.Y - 1, 3, 3);
                //}

                if (objectLocation.IsLinearMotion && isDrawConnectionLine)
                {
                    //graphics.FillEllipse(new SolidBrush(Color.Yellow), screenCurrentObjectLocation.X - 1, screenCurrentObjectLocation.Y - 1, 3, 3);

                    //isDrawConnectionLine = false;
                }

                //Logger.Debug($"iteration = {iteration} Coordinates = {objectLocation.Coordinates} IsLinearMotion = {objectLocation.IsLinearMotion} VectorToTarget = {objectLocation.VectorToTarget} Direction = {objectLocation.Direction} ScanRange = {objectLocation.ScanRange}");
            }



            if (movementType == CommandTypes.Orbit)
            {
                var trajectoryOrbit = AllIn.GetRadiusPoint(spaceShip.GetLocation(), pointTargetLocation, 50, spaceShip.Direction, spaceShip.Speed);

                var orbitRadius = 50;

                var lastPoint = points[points.Count - 1];

                var pointTargetCenter = UI.ToScreenCoordinates(screenParameters, pointCenterTargetLocation);

                //graphics.DrawLine(pen, lastWeyPointLocation.X, lastWeyPointLocation.Y, pointTargetCenter.X, pointTargetCenter.Y);
                graphics.DrawEllipse(pen, pointTargetCenter.X - orbitRadius, pointTargetCenter.Y - orbitRadius, orbitRadius * 2, orbitRadius * 2);

                var pointOrbitPoint = UI.ToScreenCoordinates(screenParameters, pointCenterTargetLocation);

                graphics.DrawEllipse(new Pen(new SolidBrush(Color.Coral), 1), pointOrbitPoint.X - 1, pointOrbitPoint.Y - 1, 5, 5);
                graphics.DrawEllipse(new Pen(new SolidBrush(Color.Goldenrod), 1), lastPoint.X - 1, lastPoint.Y - 1, 5, 5);

                var lastPointCoordinates = UI.ToMapCoordinates(screenParameters, lastPoint);

                var angleFirstOrbitPoint = Coordinates.GetRotation(lastPointCoordinates, pointCenterTargetLocation);

                for (int i = 0; i < 15; i++)
                {
                    var secondOrbitPoint = Coordinates.RotatePoint(pointCenterTargetLocation, orbitRadius, angleFirstOrbitPoint + trajectoryOrbit.Direction * i * 10);

                    var secondOrbitPointCoordinates = UI.ToScreenCoordinates(screenParameters, secondOrbitPoint);

                    graphics.DrawEllipse(new Pen(new SolidBrush(Color.GreenYellow), 1), secondOrbitPointCoordinates.X - 1, secondOrbitPointCoordinates.Y - 1, 5, 5);
                }


                //var thirdOrbitPointCoordinates = UI.ToScreenCoordinates(screenParameters, thirdOrbitPoint);



                ////double theta = Math.Tan(Math.atan2(y - cy, x - cx));
                //var X = thirdOrbitPointCoordinates.X + 100 * Math.Cos(angleFirstOrbitPoint);
                //var Y = thirdOrbitPointCoordinates.Y + 100 * Math.Sin(angleFirstOrbitPoint);

                //graphics.DrawEllipse(new Pen(new SolidBrush(Color.BlueViolet), 1), (int)(X - 1), (int)(Y - 1), 5, 5);
            }
        }
示例#5
0
        private void ExplosionCalculate(ICelestialObject celestialObject, GameSession gameSession, EngineSettings settings)
        {
            if (!(celestialObject is Missile missile))
            {
                return;
            }

            Logger.Debug($"Missile {missile.Id} from spaceship {missile.OwnerId}");

            var target = gameSession.GetCelestialObject(missile.TargetId).ToSpaceship();

            var distance = GeometryTools.Distance(celestialObject.GetLocation(), target.GetLocation());

            if (!(distance < celestialObject.Speed))
            {
                return;
            }

            Logger.Info($"Missile {missile.Id} from spaceship {missile.OwnerId} hit to spaceship {target.Id}");

            target.Damage(missile.Damage);

            _explodedMissiles.Add(celestialObject);

            var explosion = new Explosion(gameSession.Turn, target.Id)
            {
                OwnerId   = celestialObject.OwnerId,
                PositionX = target.PositionX,
                PositionY = target.PositionY
            };

            _addedExplosions.Add(explosion);

            var newGameEvent = new GameEvent
            {
                Type         = GameEventTypes.ExplosionResult,
                Turn         = gameSession.Turn + 1,
                IsPause      = true,
                IsOpenWindow = true
            };

            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.OwnerId, missile.OwnerId));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.TargetId, missile.TargetId));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.ModuleId, missile.ModuleId));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.ActionId, missile.ActionId));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.Dice, missile.Dice));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.Damage, missile.Damage));
            newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.Chance, missile.Chance));

            if ((int)missile.Damage == 0)
            {
                newGameEvent.GenericObjects.Add(new GameEventParameter(GameEventParameterTypes.Result, "MISS"));
            }

            if (missile.Damage > 0)
            {
                newGameEvent.GenericObjects.Add(target.Shields > 0 ? new GameEventParameter(GameEventParameterTypes.Result, "HIT")
                    : new GameEventParameter(GameEventParameterTypes.Result, "DESTROYED"));
            }

            gameSession.AddEvent(newGameEvent);
        }
示例#6
0
        private void RecalculateGeneralObjectLocation(GameSession gameSession, ICelestialObject celestialObject, EngineSettings settings)
        {
            var speedInTick = celestialObject.Speed / settings.UnitsPerSecond;

            var position = GeometryTools.MoveObject(
                new PointF(celestialObject.PositionX, celestialObject.PositionY),
                speedInTick,
                celestialObject.Direction);


            if (celestialObject is Missile missile)
            {
                var target = gameSession.GetCelestialObject(missile.TargetId).ToSpaceship();

                var direction = GeometryTools.Azimuth(target.GetLocation(), missile.GetLocation());

                position = GeometryTools.MoveObject(new PointF(celestialObject.PositionX, celestialObject.PositionY), speedInTick, direction);
            }

            Logger.Debug($"Object '{celestialObject.Name}' id='{celestialObject.Id}' moved from {celestialObject.GetLocation()} to {position}");

            celestialObject.PreviousPositionX = celestialObject.PositionX;
            celestialObject.PreviousPositionY = celestialObject.PositionY;

            celestialObject.PositionX = position.X;
            celestialObject.PositionY = position.Y;
        }