Пример #1
0
        void ProcessStepDetectGridsUsingSensor()
        {
            var sensors = new List <IMySensorBlock>();

            GridTerminalSystem.GetBlocksOfType(sensors, blk => blk.IsSameConstructAs(Me) && MyIni.HasSection(blk.CustomData, ScriptPrefixTag));
            foreach (var sensor in sensors)
            {
                var detectedGrids = new List <MyDetectedEntityInfo>();
                sensor.DetectedEntities(detectedGrids);
                foreach (var grid in detectedGrids)
                {
                    CelestialMap.AddGPSPosition(grid.Name, grid.Position);
                }
            }
        }
Пример #2
0
        void ProcessStepDetectGridsUsingCamera()
        {
            var cameras = new List <IMyCameraBlock>();

            GridTerminalSystem.GetBlocksOfType(cameras, blk => blk.IsSameConstructAs(Me) && MyIni.HasSection(blk.CustomData, ScriptPrefixTag));
            foreach (var camera in cameras)
            {
                camera.EnableRaycast = true;
                //EchoR($"raycast scan range: {camera.AvailableScanRange}");
                if (camera.CanScan(CameraScanRange))
                {
                    var detectedGrid = camera.Raycast(CameraScanRange, 0, 0);
                    if (!detectedGrid.IsEmpty())
                    {
                        //EchoR($"detected: {detectedGrid.Name}");
                        CelestialMap.AddGPSPosition(detectedGrid.Name, detectedGrid.Position);
                    }
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
 void ProcessStepCheckBroadcastMessages()
 {
     if (this.BroadcastListener.HasPendingMessage)
     {
         EchoR("Received broadcast message");
         MyIGCMessage message = this.BroadcastListener.AcceptMessage();
         try
         {
             var     data       = message.As <MyTuple <long, string, Vector3D, string> >();
             GPSInfo gpsmessage = new GPSInfo()
             {
                 ID       = data.Item1,
                 Name     = data.Item2,
                 Position = data.Item3,
                 Created  = DateTime.Now
             };
             CelestialMap.AddGPSPosition(gpsmessage.Name, gpsmessage.Position);
         }
         catch { }
     }
 }
Пример #5
0
            public World(Program program)
            {
                this.program = program;

                CelestialMap  = program.celestialBodies;
                CelestialInfo = new List <CelestialBody>(CelestialMap);                // Copied due to sorting.

                // Setup map specfic properties.
                foreach (CelestialBody celestialBody in CelestialMap)
                {
                    // Finds the farthest point from origo in the solar system, and scales it (used to create a sort of margin on the LCD).
                    radius = celestialBody.Position.X > radius ? celestialBody.Position.X * SCALE : radius;
                    radius = celestialBody.Position.Z > radius ? celestialBody.Position.Z * SCALE : radius;

                    // Finds the farthest points from origo in the solar system, to center the map.
                    maxOffset.X = celestialBody.Position.X > maxOffset.X ? celestialBody.Position.X : maxOffset.X;
                    maxOffset.Y = celestialBody.Position.Z > maxOffset.Y ? celestialBody.Position.Z : maxOffset.Y;
                }

                // The map object needs to be sorted.
                CelestialMap.Sort(SortByDistance);
            }
Пример #6
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);
        }
Пример #7
0
        public CelestialMap Recalculate(CelestialMap spaceMap)
        {
            var result = spaceMap.DeepClone();

            foreach (var celestialObject in result.CelestialObjects)
            {
                var position = Engine.Common.Geometry.SpaceMapTools.Move(
                    new PointF(celestialObject.PositionX, celestialObject.PositionY),
                    celestialObject.Speed,
                    celestialObject.Direction).PointTo;

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

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

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

            return(result);
        }
Пример #8
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);
        }
Пример #9
0
        public static GameSession ToGameSession(string body)
        {
            var jObject       = JObject.Parse(body);
            var iCelestialMap = jObject["celestialMap"];

            var gameSession = new GameSession
            {
                Id   = (int)jObject["id"],
                Turn = (int)jObject["turn"]
            };

            if (jObject["rules"] != null)
            {
                var rules = jObject["rules"];

                if (rules["spawn"] != null)
                {
                    var spawnRules = rules["spawn"];

                    gameSession.Rules.Spawn.AsteroidSmallSize = (double)spawnRules["asteroidSmall"];
                }

                if (rules["events"] != null)
                {
                    gameSession.Rules.IsEventsEnabled = (bool)rules["events"];
                }
            }



            var celestialMap = new CelestialMap
            {
                Id        = (string)iCelestialMap["id"],
                IsEnabled = (bool)iCelestialMap["isEnabled"],
                Turn      = (int)iCelestialMap["turn"]
            };

            foreach (var celestialObject in iCelestialMap["celestialObjects"].ToArray())
            {
                var jsonCelestialObject = celestialObject.ToString();

                var jCelestialObject = JObject.Parse(jsonCelestialObject);

                var classification = (int)jCelestialObject["classification"];

                switch (classification)
                {
                case 1:
                    var asteroid = new Asteroid
                    {
                        Id                = (int)jCelestialObject["id"],
                        Name              = (string)jCelestialObject["name"],
                        PositionX         = (int)jCelestialObject["positionX"],
                        PositionY         = (int)jCelestialObject["positionY"],
                        PreviousPositionX = (int)jCelestialObject["positionX"],
                        PreviousPositionY = (int)jCelestialObject["positionY"],
                        Direction         = (int)jCelestialObject["direction"],
                        Signature         = (int)jCelestialObject["signature"],
                        Speed             = (int)jCelestialObject["speed"],
                        Classification    = classification,
                        IsScanned         = (bool)jCelestialObject["isScanned"]
                    };

                    celestialMap.CelestialObjects.Add(asteroid);
                    break;

                case 201:
                case 202:
                case 203:
                case 2:
                case 200:
                    var spaceship = new Spaceship()
                    {
                        Id                = (int)jCelestialObject["id"],
                        Name              = (string)jCelestialObject["name"],
                        PositionX         = (int)jCelestialObject["positionX"],
                        PositionY         = (int)jCelestialObject["positionY"],
                        PreviousPositionX = (int)jCelestialObject["positionX"],
                        PreviousPositionY = (int)jCelestialObject["positionY"],
                        Direction         = (int)jCelestialObject["direction"],
                        Signature         = (int)jCelestialObject["signature"],
                        Speed             = (int)jCelestialObject["speed"],
                        MaxSpeed          = (int)jCelestialObject["maxSpeed"],
                        Classification    = classification,
                        IsScanned         = (bool)jCelestialObject["isScanned"]
                    };

                    if (jCelestialObject["systems"] != null)
                    {
                        foreach (var allModulesSystems in jCelestialObject["systems"].ToArray())
                        {
                            if (allModulesSystems["propulsion"] != null)
                            {
                                foreach (var propulsionModule in allModulesSystems["propulsion"].ToArray())
                                {
                                    var compartment = 0;
                                    var slot        = 0;

                                    if (propulsionModule["compartment"] != null)
                                    {
                                        compartment = (int)propulsionModule["compartment"];
                                    }

                                    if (propulsionModule["slot"] != null)
                                    {
                                        slot = (int)propulsionModule["slot"];
                                    }


                                    var module = Factory.CreateMicroWarpDrive(spaceship.Id, (string)propulsionModule["id"]);

                                    module.Compartment = compartment;
                                    module.Slot        = slot;

                                    spaceship.Modules.Add(module);
                                }
                            }

                            if (allModulesSystems["weapon"] != null)
                            {
                                foreach (var weaponModule in allModulesSystems["weapon"].ToArray())
                                {
                                    var compartment = 0;
                                    var slot        = 0;

                                    if (weaponModule["compartment"] != null)
                                    {
                                        compartment = (int)weaponModule["compartment"];
                                    }

                                    if (weaponModule["slot"] != null)
                                    {
                                        slot = (int)weaponModule["slot"];
                                    }

                                    var module = Factory.CreateWeaponModule(spaceship.Id, (string)weaponModule["id"]);

                                    module.Compartment = compartment;
                                    module.Slot        = slot;

                                    spaceship.Modules.Add(module);
                                }
                            }

                            if (allModulesSystems["general"] != null)
                            {
                                foreach (var generalModule in allModulesSystems["general"].ToArray())
                                {
                                    var compartment = 0;
                                    var slot        = 0;

                                    if (generalModule["compartment"] != null)
                                    {
                                        compartment = (int)generalModule["compartment"];
                                    }

                                    if (generalModule["slot"] != null)
                                    {
                                        slot = (int)generalModule["slot"];
                                    }

                                    var module = Factory.CreateGeneralModule(spaceship.Id, (string)generalModule["id"]);

                                    module.Compartment = compartment;
                                    module.Slot        = slot;

                                    spaceship.Modules.Add(module);
                                }
                            }

                            if (allModulesSystems["shields"] != null)
                            {
                                foreach (var generalModule in allModulesSystems["shields"].ToArray())
                                {
                                    spaceship.Modules.Add(Factory.CreateShieldModule(spaceship.Id, (string)generalModule["id"]));
                                }
                            }
                        }
                    }

                    spaceship.Initialization();

                    celestialMap.CelestialObjects.Add(spaceship);
                    break;

                case 300:
                    var a = "";
                    break;
                }
            }

            gameSession.SpaceMap = celestialMap;



            return(gameSession);
        }