Пример #1
0
        private void Event_Refresh(object sender, MicroTimerEventArgs timereventargs)
        {
            Logger.Debug(TraceMessage.Execute(this, "Refresh celestial map control."));

            if (refreshInProgress)
            {
                return;
            }

            var timeDrawScreen = Stopwatch.StartNew();

            refreshInProgress = true;

            DrawTacticalMapScreen();

            if (_gameSession.SpaceMap.IsEnabled)
            {
                turnStep++;
            }

            RefreshSelectedInfoControl(MouseMoveCelestialObject, granularTurnInformation, turnStep);

            refreshInProgress = false;

            Logger.Debug(TraceMessage.Execute(this, $"Time {timeDrawScreen.Elapsed.TotalMilliseconds} ms."));
        }
Пример #2
0
        private void CalculateTurnInformation(GameSession gameSession)
        {
            if (crlRefreshMap == null)
            {
                Initialization();
            }

            Logger.Debug(TraceMessage.Execute(this, $"Turn: {gameSession.Turn}."));

            HistoryMovementLog.Update(_gameSession);

            _gameSession = gameSession;

            turnStep = 0;

            granularTurnInformation = CalculateGranularTurnInformation(_gameSession);



            var timeDrawScreen = Stopwatch.StartNew();

            History.Enqueue(granularTurnInformation.DeepClone());

            Logger.Debug(TraceMessage.Execute(this, $"Time {timeDrawScreen.Elapsed.TotalMilliseconds} ms."));
        }
Пример #3
0
        public void AddEvent(GameEvent gameEvent)
        {
            gameEvent.Turn = Turn + 1;

            Logger.Info(TraceMessage.Execute(this, $"Add event.Turn = {gameEvent.Turn} Turn = {Turn}"));

            GameEvents.Add(gameEvent);
        }
Пример #4
0
        private void ExecuteModuleForSelectSelectObject(IModule arg1, Func <GameSession, List <ICelestialObject> > getObjects)
        {
            if (_gameSession is null)
            {
                return;
            }

            var objects = getObjects(_gameSession);

            Logger.Info(TraceMessage.Execute(this, $"ExecuteModuleForSelectSelectObject {arg1.Name} execute. Objects cont is {objects.Count}."));
        }
Пример #5
0
        private void DrawTacticalMapScreen()
        {
            Logger.Debug(TraceMessage.Execute(this, $"Turn { _gameSession.Turn}.{turnStep}"));

            Image image = new Bitmap(Width, Height);

            var graphics = Graphics.FromImage(image);

            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.Bicubic;
            graphics.SmoothingMode      = SmoothingMode.AntiAlias;
            graphics.TextRenderingHint  = TextRenderingHint.AntiAlias;

            var currentTurnBoardInfo = new BoardInfo
            {
                GraphicSurface = graphics,
                ScreenInfo     = _screenParameters,
                TurnInfo       = granularTurnInformation,
                TurnStep       = turnStep
            };


            DrawMapTools.DrawGrid(currentTurnBoardInfo);

            DrawMapTools.DrawSelectedObject(graphics, _mode, _gameSession, MouseMoveCelestialObject, _connectorsSelect, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawConnectors(graphics, _gameSession, _connectorsShow, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawConnectors(graphics, _gameSession, _connectorsSelect, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawDestinationPoint(graphics, _gameSession, destinationPoint, _screenParameters);

            DrawMapTools.DrawChangeMovementDestination(graphics, _gameSession, pointInSpace, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawSpaceShipMovement(graphics, _gameSession, granularTurnInformation, turnStep, HistoryMovementLog, _screenParameters);

            DrawMapTools.DrawMissiles(graphics, _gameSession, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawExplosions(graphics, _gameSession, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawSpaceShipTrajectories(graphics, _gameSession, granularTurnInformation, _screenParameters);

            DrawMapTools.DrawScreen(graphics, _gameSession, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawActiveModule(graphics, _activeModule, mouseCoordinates, _gameSession, granularTurnInformation, turnStep, _screenParameters);

            DrawMapTools.DrawMouseMoveObject(graphics, _gameSession, MouseMoveCelestialObject, granularTurnInformation, turnStep, _screenParameters);



            BackgroundImage = image;
        }
Пример #6
0
        public CelestialMap Execute(GameSession gameSession)
        {
            Logger.Debug(TraceMessage.Execute(this, "Start execute artificial intelligence logic."));

            var result = gameSession.SpaceMap.DeepClone();

            result = new Targeting().Execute(result);

            result = new Navigation().Execute(result, gameSession.Commands);

            result = new Attack().Execute(result, gameSession);

            return(result);
        }
Пример #7
0
        private void MapMouseMove(object sender, MouseEventArgs e)
        {
            Logger.Debug(TraceMessage.Execute(this, $"MapMouseMove]"));

            mouseCoordinates = e.Location;

            var mouseCoordinatesInternal = OutlandAreaCommon.Tools.ToRelativeCoordinates(e.Location, _screenParameters.Center);

            var mouseMapCoordinates = OutlandAreaCommon.Tools.ToTacticalMapCoordinates(mouseCoordinatesInternal, _screenParameters.CenterScreenOnMap);

            var celestialObjectInRange = SessionTools.GetObjectInRange(_gameSession, 15, new PointF(mouseMapCoordinates.X, mouseMapCoordinates.Y));

            MouseMoveCelestialObject = celestialObjectInRange?.DeepClone();
        }
Пример #8
0
        private void AddTarget(Spaceship npcShip, List <ICelestialObject> targetSpaceships)
        {
            var id = RandomGenerator.GetInteger(targetSpaceships.Count);

            try
            {
                var targetSpaceship = targetSpaceships[id];

                npcShip.TargetId = targetSpaceship.Id;
            }
            catch (Exception e)
            {
                Logger.Error(TraceMessage.Execute(this, $"Add target critical error. GameEvent is {e.Message}"));
            }
        }
Пример #9
0
        public CommandExecuteResult Execute(GameSession gameSession, Command command)
        {
            Logger.Debug(TraceMessage.Execute(this, "Execute command scanning is started."));

            gameSession.AddHistoryMessage("started.", GetType().Name, true);

            if (RandomGenerator.DiceRoller() < gameSession.Rules.Spawn.AsteroidSmallSize)
            {
                Logger.Debug(TraceMessage.Execute(this, "Add new asteroid."));

                gameSession.AddCelestialObject(CelestialObjectsFactory.GenerateAsteroid(gameSession));
            }

            return(new CommandExecuteResult {
                Command = command, IsResume = false
            });
        }
Пример #10
0
        public CelestialMap Execute(CelestialMap spaceMap)
        {
            Logger.Debug(TraceMessage.Execute(this, "Start NPC targeting logic."));

            var npcSpaceships = spaceMap.CelestialObjects.
                                Where(_ => _.IsSpaceship()).
                                Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipNpcEnemy).
                                Where(_ => _.ToSpaceship().TargetId < 1).ToList(); // Check if no need targeting process

            var targetSpaceships = spaceMap.CelestialObjects.
                                   Where(_ => _.IsSpaceship()).
                                   Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipPlayer || _.Classification == (int)CelestialObjectTypes.SpaceshipNpcFriend).ToList();

            foreach (var celestialObject in npcSpaceships)
            {
                AddTarget(celestialObject.ToSpaceship(), targetSpaceships);
            }


            return(spaceMap);
        }
Пример #11
0
        private void Initialization()
        {
            Logger.Info(TraceMessage.Execute(this, "Celestial map control - Initialization"));

            _screenParameters = new ScreenParameters(Width, Height, _centerScreenPosition.X, _centerScreenPosition.Y);

            if (DebugTools.IsInDesignMode())
            {
                return;
            }

            crlRefreshMap = new MicroTimer();
            crlRefreshMap.MicroTimerElapsed += Event_Refresh;

            var intervalMilliseconds = 50;

            crlRefreshMap.Interval = 1000 * intervalMilliseconds; // 1000 = 1ms

            crlRefreshMap.Enabled = true;

            _screenParameters.DrawInterval = 1000 / intervalMilliseconds;
        }
Пример #12
0
        public CelestialMap Execute(CelestialMap spaceMap, GameSession session)
        {
            Logger.Debug(TraceMessage.Execute(this, "Start NPC attack logic."));

            var npcSpaceships = spaceMap.CelestialObjects.
                                Where(_ => _.IsSpaceship()).
                                Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipNpcEnemy).
                                Map(_ => _.ToSpaceship()); // Convert to spaceship type

            var targetSpaceships = spaceMap.CelestialObjects.
                                   Where(_ => _.IsSpaceship()).
                                   Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipPlayer || _.Classification == (int)CelestialObjectTypes.SpaceshipNpcFriend).
                                   Map(_ => _.ToSpaceship());


            foreach (var spaceship in npcSpaceships)
            {
                ImplementAttack(spaceship, targetSpaceships.FirstOrDefault(_ => _.Id == spaceship.TargetId), session, session.Commands);
            }

            return(session.SpaceMap);
        }
Пример #13
0
        public CelestialMap Execute(CelestialMap spaceMap, List <Command> sessionCommands)
        {
            Logger.Debug(TraceMessage.Execute(this, "Start NPC navigation logic."));

            var npcSpaceships = spaceMap.CelestialObjects.
                                Where(_ => _.IsSpaceship()).
                                Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipNpcEnemy).
                                Map(_ => _.ToSpaceship()); // Convert to spaceship type

            var targetSpaceships = spaceMap.CelestialObjects.
                                   Where(_ => _.IsSpaceship()).
                                   Where(_ => _.Classification == (int)CelestialObjectTypes.SpaceshipPlayer || _.Classification == (int)CelestialObjectTypes.SpaceshipNpcFriend).
                                   Map(_ => _.ToSpaceship());


            foreach (var spaceship in npcSpaceships)
            {
                AddNavigationChange(spaceship, targetSpaceships.FirstOrDefault(_ => _.Id == spaceship.TargetId));
            }

            return(spaceMap);
        }
Пример #14
0
 private void CalculateTurnInformation(GameSession gameSession)
 {
     _gameSession = gameSession;
     Logger.Info(TraceMessage.Execute(this, $"Turn {gameSession.Turn} execute."));
 }
Пример #15
0
 private void ActivateModule(IModule module)
 {
     Logger.Info(TraceMessage.Execute(this, $"ActivateModule {module.Name}."));
 }
Пример #16
0
        private void AddNavigationChange(Spaceship npcShip, Spaceship targetSpaceship)
        {
            Logger.Debug(TraceMessage.Execute(this, $"Set navigation npc-commend for {npcShip.Id} to {targetSpaceship.Id}."));

            npcShip.TargetId = targetSpaceship.Id;
        }
Пример #17
0
        private void ImplementAttack(Spaceship npcShip, Spaceship targetSpaceship, GameSession session, List <Command> sessionCommands)
        {
            Logger.Debug(TraceMessage.Execute(this, $"Set attack npc-commend for {npcShip.Id} to {targetSpaceship.Id}."));

            var modulesWeapon = npcShip.Modules.
                                Where(module => module.Category == Category.Weapon).
                                                                                               //Map(_ => _.ToWeapon()). // Convert to weapon type
                                Where(_ => _.ToWeapon().ReloadTime <= _.ToWeapon().Reloading); // GetInteger only modules with ready to use


            var distance = Coordinates.GetDistance(npcShip.GetLocation(), targetSpaceship.GetLocation());



            foreach (var weaponModule in modulesWeapon)
            {
                var missile = MissilesFactory.GetMissile(weaponModule.ToWeapon().AmmoId).ToCelestialObject();

                missile.Id        = RandomGenerator.GetId();
                missile.OwnerId   = npcShip.Id;
                missile.PositionX = npcShip.PositionX;
                missile.PositionY = npcShip.PositionY;

                var weaponTargetPointInSpace = GetTargetLocation(targetSpaceship, missile, distance);

                var targetPointInSpace = new PointInSpace
                {
                    Id             = RandomGenerator.GetId(),
                    PositionY      = weaponTargetPointInSpace.Y,
                    PositionX      = weaponTargetPointInSpace.X,
                    Speed          = 0,
                    Direction      = 0,
                    Name           = "Missile Target",
                    Signature      = 1,
                    Classification = (int)CelestialObjectTypes.PointInMap,
                    IsScanned      = true
                };

                session.AddCelestialObject(targetPointInSpace);
                session.AddCelestialObject(missile);

                var command = new Command
                {
                    CelestialObjectId       = missile.Id,
                    TargetCelestialObjectId = targetPointInSpace.Id,
                    MemberId     = 0,
                    TargetCellId = 0,
                    Type         = CommandTypes.Fire
                };

                session.AddCommand(command);

                var commandReloadModule = new Command
                {
                    CelestialObjectId       = npcShip.Id,
                    TargetCelestialObjectId = weaponModule.Id,
                    MemberId     = 0,
                    TargetCellId = 0,
                    Type         = CommandTypes.ReloadWeapon
                };

                session.AddCommand(commandReloadModule);
            }
        }
Пример #18
0
 public static void AddCelestialObject(this GameSession session, ICelestialObject celestialObject)
 {
     Logger.Info(TraceMessage.Execute(session, $"[AddCelestialObject] Turn = {session.Turn} AddCelestialObject Id = {celestialObject.Id} Name = {celestialObject.Name} Classification = {celestialObject.Classification}"));
     session.SpaceMap.CelestialObjects.Add(celestialObject);
 }
Пример #19
0
        private void MapClick(object sender, MouseEventArgs e)
        {
            var mouseScreenCoordinates = OutlandAreaCommon.Tools.ToRelativeCoordinates(e.Location, _screenParameters.Center);

            var mouseMapCoordinates = OutlandAreaCommon.Tools.ToTacticalMapCoordinates(mouseScreenCoordinates, _screenParameters.CenterScreenOnMap);

            var celestialObjectInRange = SessionTools.GetObjectInRange(_gameSession, 15, new PointF(mouseMapCoordinates.X, mouseMapCoordinates.Y));


            switch (_activeModule)
            {
            case CelestialObjectTypes.PointInMap:
                break;

            case CelestialObjectTypes.Missile:
                if (e.Button == MouseButtons.Right)
                {
                    _activeModule = CelestialObjectTypes.None;
                    return;
                }

                if (e.Button == MouseButtons.Left)
                {
                    _activeCelestialObject.PositionX = mouseMapCoordinates.X;
                    _activeCelestialObject.PositionY = mouseMapCoordinates.Y;

                    _activeModule = CelestialObjectTypes.None;

                    OnLaunchMissile?.Invoke(_activeCelestialObject);
                    return;
                }

                break;

            case CelestialObjectTypes.SpaceshipPlayer:
                break;

            case CelestialObjectTypes.SpaceshipNpcNeutral:
                break;

            case CelestialObjectTypes.SpaceshipNpcEnemy:
                break;

            case CelestialObjectTypes.SpaceshipNpcFriend:
                break;

            case CelestialObjectTypes.Asteroid:
                break;

            case CelestialObjectTypes.None:
                _connectorsShow = new List <ICelestialObject>();
                break;
            }



            Logger.Info(TraceMessage.Execute(this, $"MapClick"));

            //if (e.Button == MouseButtons.Right)
            //{
            //    AlignToCommand(null, e);
            //    return;
            //}


            if (celestialObjectInRange != null)
            {
                Global.Game.SelectCelestialObject(celestialObjectInRange);
            }
            else
            {
                // Movement by mouse click
                //Global.Game.SelectPointInSpace(mouseMapCoordinates);
            }

            //pointInSpace = mouseMapCoordinates;
        }