Ejemplo n.º 1
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                m_texture = Game.Content.Load <Texture2D>("Images/gravity_field");
            }

            var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

            var angle = StaticObject.ForceDirection.Angle();

            var scaleVector =
                CoordinatesTransformer.CreateScaleVector(
                    new Size(StaticObject.AbsoluteGeometry.BoundingRectangle.LongSide,
                             StaticObject.AbsoluteGeometry.BoundingRectangle.ShortSide),
                    new Size(m_texture.Width, m_texture.Height));

            spriteBatch.Draw(m_texture,
                             CoordinatesTransformer.Transform(StaticObject.AbsoluteGeometry.Center),
                             null,
                             m_color,
                             (float)Helper.ToRadians(angle),
                             origin,
                             scaleVector,
                             SpriteEffects.None,
                             LayersDepths.GravityField);
        }
Ejemplo n.º 2
0
            /// <summary>Class that allow some high level control over the wheels. To be controlled, the wheels must be on the same grid than <paramref name="controller"/> and contain the keyword "Power"</summary>
            /// <param name="command">Command line where the commands will be registered</param>
            /// <param name="controller">Controller on the same grid than the wheels to get some physics information</param>
            /// <param name="gts">To retrieve the wheels</param>
            /// <param name="ini">Contains some serialized information for persistence</param>
            /// <param name="manager">To spawn the updater process</param>
            /// <param name="transformer">Transformer that transform world coordinates into the vehicules coordinate: Z must be parallel to the vehicle's forward direction an Y must be parallel to the vehicle's up direction</param>
            public WheelsController(CommandLine command, IMyShipController controller, IMyGridTerminalSystem gts, MyIni ini, ISaveManager manager, CoordinatesTransformer transformer)
            {
                this.transformer = transformer;
                this.controller  = controller;
                var wheels = new List <IMyMotorSuspension>();

                gts.GetBlocksOfType(wheels, w => w.CubeGrid == controller.CubeGrid && w.DisplayNameText.Contains("Power"));
                this.wheels = wheels.Select(w => new PowerWheel(w, this.WheelBase, transformer)).ToList();
                this.wheels.Sort((w1, w2) => Math.Sign(w1.Position.Z - w2.Position.Z)); // needed for calibration

                this.registerCommands(command);
                manager.Spawn(this.updateWheels, "wheels-controller", period: 10);
                manager.AddOnSave(this.save);

                if (ini.ContainsKey(SECTION, "cal-weight"))
                {
                    this.calibration = new Calibration()
                    {
                        Weight  = ini.Get(SECTION, "cal-weight").ToSingle(),
                        MinZ    = ini.Get(SECTION, "cal-min-z").ToDouble(),
                        MaxZ    = ini.Get(SECTION, "cal-max-z").ToDouble(),
                        MinMult = ini.Get(SECTION, "cal-min-mult").ToSingle(),
                        MaxMult = ini.Get(SECTION, "cal-max-mult").ToSingle()
                    };
                }

                this.targetRatio = ini.Get(SECTION, "target-ratio").ToSingle(0.35f);
                this.WheelBase.CenterOfTurnZOffset = ini.Get(SECTION, "turn-center-offset").ToDouble();
                this.WheelBase.TurnRadiusOverride  = ini.Get(SECTION, "turn-radius").ToDouble();
            }
Ejemplo n.º 3
0
        public Minimap(PlanesGame game, Rectangle positionRecangle, GameWorldXna gameWorldXna)
            : base(game, positionRecangle)
        {
            m_gameWorldXna = gameWorldXna;

            m_coordinatesTransformer = new CoordinatesTransformer(gameWorldXna.GameWorld.Size, positionRecangle);
        }
Ejemplo n.º 4
0
        public void DrawOnMinimap(GameTime gameTime, SpriteBatch minimapSpriteBatch, CoordinatesTransformer coordinatesTransformer)
        {
            if (m_minimapImage == null)
            {
                m_minimapImage = Game.Content.Load <Texture2D>("Minimap/circle");
            }

            var origin = new Vector2((float)m_minimapImage.Width / 2.0f,
                                     (float)m_minimapImage.Height / 2.0f);

            var scaleVector =
                coordinatesTransformer.CreateScaleVector(StaticObject.AbsoluteGeometry.BoundingRectangle.Size,
                                                         new Size(m_minimapImage.Width,
                                                                  m_minimapImage.Height));

            minimapSpriteBatch.Draw(m_minimapImage,
                                    coordinatesTransformer.Transform(StaticObject.AbsoluteGeometry.Center),
                                    null,
                                    Color.Red,
                                    0,
                                    origin,
                                    scaleVector,
                                    SpriteEffects.None,
                                    LayersDepths.StaticObject);
        }
Ejemplo n.º 5
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                if (Equipment.RelatedGameObject is XWingPlane)
                {
                    m_texture = Game.Content.Load <Texture2D>("Images/x_wing_shield");
                    m_color   = Color.YellowGreen;
                }
                else
                {
                    throw new Exception("Unknown plane to create shield");
                }
            }

            if (Equipment.IsActive)
            {
                ++m_drawCounter;

                var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

                var scaleVector = CoordinatesTransformer.CreateScaleVector(Equipment.RelatedGameObject.RelativeGeometry.BoundingRectangle.Size,
                                                                           new Size(m_texture.Width, m_texture.Height));

                spriteBatch.Draw(m_texture,
                                 CoordinatesTransformer.Transform(Equipment.GetAbsolutePosition()),
                                 null,
                                 Color.FromNonPremultiplied(m_color.R, m_color.G, m_color.B, (int)(195 + 60 * Math.Sin(m_drawCounter / 3.0))),
                                 MathHelper.ToRadians((float)Equipment.GetAbsoluteRotation()),
                                 origin,
                                 scaleVector,
                                 SpriteEffects.None,
                                 LayersDepths.Shield);
            }
        }
Ejemplo n.º 6
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                m_texture = Game.Content.Load <Texture2D>("Images/rocket");
            }

            if (GameObject.TimeToLive > TimeSpan.Zero)
            {
                m_trailDrawer.PathPoints.Add(GameObject.Position);

                m_trailDrawer.DrawTrail(spriteBatch);

                var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

                var scaleVector = CoordinatesTransformer.CreateScaleVector(GameObject.RelativeGeometry.BoundingRectangle.Size,
                                                                           new Size(m_texture.Width, m_texture.Height));

                spriteBatch.Draw(m_texture,
                                 CoordinatesTransformer.Transform(GameObject.Position),
                                 null,
                                 Color.White,
                                 MathHelper.ToRadians((float)GameObject.Rotation),
                                 origin,
                                 scaleVector,
                                 SpriteEffects.None,
                                 LayersDepths.Bullet);
            }
        }
Ejemplo n.º 7
0
            /// <summary>Creates a new power wheel</summary>
            /// <param name="wheel">The actual wheel it wraps</param>
            /// <param name="wb">The wheel base, to which the power wheel will be added</param>
            /// <param name="tform">Coordinates transformer, should be one that makes the Z axis parallel the wheel direction and Y axis the up axis</param>
            public PowerWheel(IMyMotorSuspension wheel, WheelBase wb, CoordinatesTransformer tform)
            {
                this.wheelBase   = wb;
                this.CubeSize    = wheel.CubeGrid.GridSizeEnum;
                this.Position    = tform.Pos(wheel.GetPosition());
                this.IsRight     = RIGHT.Dot(tform.Dir(wheel.WorldMatrix.Up)) > 0;
                this.reverseY    = UP.Dot(tform.Dir(wheel.WorldMatrix.Backward)) > 0;
                this.transformer = tform;
                this.wheel       = wheel;

                wheel.Height = 10;
                this.maxY    = wheel.Height;
                wheel.Height = -10;
                this.minY    = wheel.Height;
                if (this.reverseY)
                {
                    float tmp = this.minY;
                    this.minY = -this.maxY;
                    this.maxY = -tmp;
                }
                this.WheelSize = (wheel.Top.Max - wheel.Top.Min).X + 1;
                this.Mass      = this.CubeSize == MyCubeSize.Small
          ? this.WheelSize == 1 ? 105 : (this.WheelSize == 3 ? 205 : 310)
          : this.WheelSize == 1 ? 420 : (this.WheelSize == 3 ? 590 : 760);
                // real center of rotation of the wheel
                this.Position += tform.Dir(wheel.WorldMatrix.Up) * wheel.CubeGrid.GridSize;
                this.wheelBase.AddWheel(this);
            }
Ejemplo n.º 8
0
 public LaserGunXna(PlanesGame game, LaserGun weapon, CoordinatesTransformer coordinatesTransformer)
     : base(game, weapon, coordinatesTransformer)
 {
     m_particlesEmitter = new SymmetricParticlesEmitter(game.GameManager.GameWorldXna)
     {
         PositionDeviationRadius      = 0.4,
         VelocityDeviationRadius      = 3,
         AlphaVelocityDeviationFactor = 0.3
     };
 }
Ejemplo n.º 9
0
        public HomingRocketXna(PlanesGame game, HomingRocket bullet, CoordinatesTransformer coordinatesTransformer)
            : base(game, bullet, coordinatesTransformer)
        {
            var sound = game.GameManager.GameWorldXna.SoundManager.CreateBasicSoundEffect("bullet_sound");

            sound.Position = bullet.Position;
            sound.Play();

            m_trailDrawer = new TrailDrawer(game.Content.Load <Texture2D>("Other/line_3px"), coordinatesTransformer, Color.White, 0.3, 0.2f, 0.05f, 15, 3);
        }
Ejemplo n.º 10
0
        public override void Draw(GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                switch (Type)
                {
                case ParticleType.Circle:
                    m_texture = Game.Content.Load <Texture2D>("Particles/circle");
                    break;

                case ParticleType.BluredCircle:
                    m_texture = Game.Content.Load <Texture2D>("Particles/circle_blured");
                    break;

                case ParticleType.Star:
                    m_texture = Game.Content.Load <Texture2D>("Particles/star");
                    break;

                case ParticleType.Diamond:
                    m_texture = Game.Content.Load <Texture2D>("Particles/diamond");
                    break;

                case ParticleType.Cross:
                    m_texture = Game.Content.Load <Texture2D>("Particles/cross");
                    break;

                case ParticleType.Debris:
                    int num = RandomProvider.Next() % 3 + 1;
                    m_texture = Game.Content.Load <Texture2D>(string.Format("Particles/debris_{0}", num));
                    break;

                default:
                    throw new Exception("Unknown particle type");
                }
            }

            if (!IsGarbage)
            {
                var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

                var scaleVector = CoordinatesTransformer.CreateScaleVector(
                    new Size(Size.Width * SizeFactor.X, Size.Height * SizeFactor.Y),
                    new Size(m_texture.Width, m_texture.Height));

                spriteBatch.Draw(m_texture,
                                 CoordinatesTransformer.Transform(Position),
                                 null,
                                 new Color(this.Color.R / 255f, this.Color.G / 255f, this.Color.B / 255f, (float)Alpha),
                                 MathHelper.ToRadians((float)Rotation),
                                 origin,
                                 scaleVector,
                                 SpriteEffects.None,
                                 Depth);
            }
        }
Ejemplo n.º 11
0
        public TrailDrawer(Texture2D pixelTexture, CoordinatesTransformer coordinatesTransformer, Color color, double width, float maxAlpha, float minAlpha, int segmentsCount, double segmentLen)
        {
            PathPoints = new List <Vector>();

            CoordinatesTransformer = coordinatesTransformer;
            Color         = color;
            Width         = width;
            MaxAlpha      = maxAlpha;
            MinAlpha      = minAlpha;
            SegmentsCount = segmentsCount;
            SegmentLen    = segmentLen;

            m_pixelTexture = pixelTexture;
        }
Ejemplo n.º 12
0
        public BonusXna(PlanesGame game, Bonus bonus, CoordinatesTransformer coordinatesTransformer, Color color, Texture2D texture)
            : base(game, bonus, coordinatesTransformer)
        {
            Bonus = bonus;
            Color = color;

            m_texture = texture;

            m_emitter = new SymmetricParticlesEmitter(game.GameManager.GameWorldXna)
            {
                PositionDeviationRadius      = Bonus.RelativeGeometry.BoundingRectangle.LongSide * 2.0 / 3.0,
                VelocityDeviationRadius      = 10,
                AlphaVelocityDeviationFactor = 0.3
            };
        }
Ejemplo n.º 13
0
        public RocketEngineXna(PlanesGame game, RocketEngine rocketEngine, CoordinatesTransformer coordinatesTransformer)
            : base(game, rocketEngine, coordinatesTransformer)
        {
            m_workSoundEffect = game.GameManager.GameWorldXna.SoundManager.CreateFadeInOutSoundEffect("engine_work",
                                                                                                      TimeSpan.FromSeconds(0.4), TimeSpan.FromSeconds(0.1));

            m_particlesEmitter = new AsymmetricParticlesEmitter(game.GameManager.GameWorldXna)
            {
                LongitualPositionDeviationRadius  = 2,
                TransversePositionDeviationRadius = 0.4,
                LongitualVelocityDeviationRadius  = 0.1,
                TransverseVelocityDeviationRadius = 0.02,
                AlphaVelocityDeviationFactor      = 0.3
            };
        }
Ejemplo n.º 14
0
        public ExplosionXna(PlanesGame game, GameObject exploded, CoordinatesTransformer coordinatesTransformer)
            : base(game, coordinatesTransformer)
        {
            m_exploded          = exploded;
            m_explosionPosition = new Rect(exploded.Position, exploded.RelativeGeometry.BoundingRectangle.Size);

            if (exploded is NRPlanes.Core.Common.Plane || exploded is Bullet)
            {
                m_particlesEmitter = new SymmetricParticlesEmitter(game.GameManager.GameWorldXna)
                {
                    PositionDeviationRadius = m_explosionPosition.Width / 2,
                    VelocityDeviationRadius = 5
                };
            }
            else if (exploded is Bonus)
            {
                m_particlesEmitter = new SymmetricParticlesEmitter(game.GameManager.GameWorldXna)
                {
                    PositionDeviationRadius   = m_explosionPosition.Width / 3,
                    VelocityDeviationRadius   = 20,
                    RotationDeviation         = 180,
                    RotationVelocityDeviation = 60
                };
            }

            BasicSoundEffect sound = null;

            if (exploded is NRPlanes.Core.Common.Plane)
            {
                sound = game.GameManager.GameWorldXna.SoundManager.CreateBasicSoundEffect("plane_explosion");
            }
            else if (exploded is Bullet)
            {
                sound = game.GameManager.GameWorldXna.SoundManager.CreateBasicSoundEffect("bullet_explosion");
            }
            else if (exploded is Bonus)
            {
                sound = game.GameManager.GameWorldXna.SoundManager.CreateBasicSoundEffect("debris_explosion");
            }

            if (sound != null)
            {
                sound.Position = m_explosionPosition.Center;
                sound.Play();
            }

            //m_angle = (float) (2 * Math.PI * m_random.NextDouble());
        }
Ejemplo n.º 15
0
        public void ShouldConvertPointsFromWgs84ToLambert93()
        {
            var wgs84=new CoordinateSystem(new DotGeo.World().WGS1984);
            var lam93=new CoordinateSystem(new DotPrj.NationalGrids().RGF1993Lambert93);

            var ct=new CoordinatesTransformer(wgs84, lam93);

            foreach (var coordinates in new double[][][] { _Paris, _NewYorkCity })
            {
                var input=coordinates[0];
                var expected=coordinates[1];
                var result=ct.Convert(input);

                Assert.Equal(expected, result, new CoordinateComparer(2));
            }
        }
Ejemplo n.º 16
0
        public void ShouldConvertPointsFromWgs84ToLambert93()
        {
            var wgs84 = new CoordinateSystem(new DotGeo.World().WGS1984);
            var lam93 = new CoordinateSystem(new DotPrj.NationalGrids().RGF1993Lambert93);

            var ct = new CoordinatesTransformer(wgs84, lam93);

            foreach (var coordinates in new double[][][] { _Paris, _NewYorkCity })
            {
                var input    = coordinates[0];
                var expected = coordinates[1];
                var result   = ct.Convert(input);

                Assert.Equal(expected, result, new CoordinateComparer(2));
            }
        }
Ejemplo n.º 17
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_animationSpriteDrawer == null)
            {
                m_animationSpriteDrawer
                    = new AnimationSpriteDrawer(Game.Content.Load <Texture2D>("Animations/health_recovery"),
                                                new Size(400, 400), TimeSpan.FromMilliseconds(50), true, true);
            }

            var origin = new Vector2((float)m_animationSpriteDrawer.FrameSize.Width / 2.0f,
                                     (float)m_animationSpriteDrawer.FrameSize.Height / 2.0f);

            var scaleVector =
                CoordinatesTransformer.CreateScaleVector(
                    StaticObject.AbsoluteGeometry.BoundingRectangle.Size,
                    new Size(m_animationSpriteDrawer.FrameSize.Width,
                             m_animationSpriteDrawer.FrameSize.Height));

            m_animationSpriteDrawer.Draw(gameTime,
                                         spriteBatch,
                                         CoordinatesTransformer.Transform(StaticObject.AbsoluteGeometry.Center),
                                         Color.Red,
                                         0f,
                                         origin,
                                         scaleVector,
                                         SpriteEffects.None,
                                         LayersDepths.StaticObject);

            // do every 4 draw
            if (m_drawCount++ % 8 == 0)
            {
                foreach (var affectedObject in StaticObject.AffectedGameObjects)
                {
                    double crossSize = StaticObject.RecoverySpeed / 4;

                    m_particlesEmitter.Emit(new Particle(Game, CoordinatesTransformer, ParticleType.Cross)
                    {
                        Position      = affectedObject.Position,
                        Color         = Color.Red,
                        Size          = new Size(crossSize, crossSize),
                        Alpha         = 0.8f,
                        AlphaVelocity = -0.5f
                    }, 1);
                }
            }
        }
Ejemplo n.º 18
0
            public InventoriesController(CoordinatesTransformer tformer, IMyGridTerminalSystem gts, IMyCockpit cockpit, double idealCenterOfMass, IProcessSpawner spawner)
            {
                this._cpit     = cockpit;
                this._idealCoM = idealCenterOfMass;
                var containers = new List <IMyCargoContainer>();

                gts.GetBlocksOfType(containers, c => c.CubeGrid == cockpit.CubeGrid);
                this._invs = containers
                             .Select(c => new Inventory(c, tformer.Pos(c.GetPosition()).Z))
                             .OrderBy(inv => inv.Z)
                             .ToList();
                gts.GetBlocksOfType(this._lights, light => light.DisplayNameText.StartsWith("BM Spotlight") &&
                                    !light.DisplayNameText.Contains("Rear"));
                spawner.Spawn(p => this.updateDrills(), "drill-updater");

                this._invAction = spawner.Spawn(p => this.updateInventories(tformer.Pos(cockpit.CenterOfMass).Z), "inv-handle", period: 100);
            }
Ejemplo n.º 19
0
            /// <summary>Creates a new Autopilot</summary>
            /// <param name="ini"></param>
            /// <param name="wheels"></param>
            /// <param name="cmd"></param>
            /// <param name="remote"></param>
            /// <param name="logger"></param>
            /// <param name="manager"></param>
            public Autopilot(MyIni ini, WheelsController wheels, CommandLine cmd, IMyRemoteControl remote, Action <string> logger, ISaveManager manager)
            {
                this.activated = ini.Get("auto-pilot", "activated").ToBoolean();
                this.logger    = logger;

                Process p = manager.Spawn(this.handle, "ap-handle");

                this.Network     = new WPNetwork(remote, logger, p);
                this.remote      = remote;
                this.transformer = new CoordinatesTransformer(remote, p);
                this.wheels      = wheels;

                cmd.RegisterCommand(new Command("ap-move", Command.Wrap(this.move), "Move forward", minArgs: 1, maxArgs: 2));
                cmd.RegisterCommand(new Command("ap-goto", Command.Wrap(this.GoTo), "Go to the waypoint", nArgs: 1));
                cmd.RegisterCommand(new Command("ap-switch", Command.Wrap(this.Switch), "Switches the autopilot on/off", nArgs: 1));
                cmd.RegisterCommand(new Command("ap-save", Command.Wrap(this.Save), "Save the current position", nArgs: 1));
                manager.AddOnSave(this.save);
            }
Ejemplo n.º 20
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            Vector2 origin      = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);
            Vector2 scaleVector = CoordinatesTransformer.CreateScaleVector(Bonus.RelativeGeometry.BoundingRectangle.Size, new Size(m_texture.Width, m_texture.Height));

            // pulsation
            scaleVector = Vector2.Multiply(scaleVector, (float)(1.0 + Math.Sin(gameTime.TotalGameTime.TotalSeconds * 5) / 10.0));

            spriteBatch.Draw(
                m_texture,
                CoordinatesTransformer.Transform(Bonus.Position),
                null,
                Color,
                (float)Bonus.Rotation,
                origin,
                scaleVector,
                SpriteEffects.None,
                LayersDepths.Bonuses);
        }
Ejemplo n.º 21
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            this.manager = Process.CreateManager(this.Echo);
            var screen = this.GridTerminalSystem.GetBlockWithName("SMB LCD (Rear Seat)") as IMyTextPanel;
            var logger = new Logger(this.manager, screen);

            this.cmd = new CommandLine("Small Mobile Base", logger.Log, this.manager);

            var ini              = new IniWatcher(this.Me, this.manager);
            var controller       = this.GridTerminalSystem.GetBlockWithName("SMB Remote Control (Forward)") as IMyShipController;
            var transformer      = new CoordinatesTransformer(controller, this.manager);
            var wheelsController = new WheelsController(this.cmd, controller, this.GridTerminalSystem, ini, this.manager, transformer);

            new ConnectionClient(ini, this.GridTerminalSystem, this.IGC, this.cmd, this.manager, logger.Log);

            new CameraTurret(this.GridTerminalSystem, this.manager);

            new PilotAssist(this.GridTerminalSystem, ini, logger.Log, this.manager, wheelsController);
        }
Ejemplo n.º 22
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                m_texture = Game.Content.Load <Texture2D>("Images/circle_bullet");
            }

            if (GameObject.TimeToLive > TimeSpan.Zero)
            {
                m_trailDrawer.PathPoints.Add(GameObject.Position);

                m_trailDrawer.DrawTrail(spriteBatch);

                //// particles trail
                //m_particlesEmitter.Emit(new Particle(Game, CoordinatesTransformer)
                //{
                //    Color = Color.FromNonPremultiplied(20, 20, 20, 255),
                //    Position = GameObject.Position,
                //    Size = new Size(1, 10),
                //    AlphaVelocity = -1f,
                //    TimeToLive = TimeSpan.FromSeconds(1),
                //    Rotation = GameObject.Velocity.Angle(),
                //    IsStatic = true
                //}, 1);

                var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

                var scaleVector = CoordinatesTransformer.CreateScaleVector(GameObject.RelativeGeometry.BoundingRectangle.Size,
                                                                           new Size(m_texture.Width, m_texture.Height));

                spriteBatch.Draw(m_texture,
                                 CoordinatesTransformer.Transform(GameObject.Position),
                                 null,
                                 Color.White,
                                 MathHelper.ToRadians((float)GameObject.Rotation),
                                 origin,
                                 scaleVector,
                                 SpriteEffects.None,
                                 LayersDepths.Bullet);
            }
        }
Ejemplo n.º 23
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            var cockpits = new List <IMyCockpit>();

            this.GridTerminalSystem.GetBlocksOfType(cockpits, c => c.CubeGrid == this.Me.CubeGrid);
            IMyCockpit cockpit = cockpits.First();

            this.manager = Process.CreateManager(this.Echo);
            var ct     = new CoordinatesTransformer(cockpit, this.manager);
            var logger = new Logger(this.manager, cockpit.GetSurface(0), new Color(0, 39, 15), new Color(27, 228, 33), this.Echo, 1.0f);

            this.cmd = new CommandLine("Small welder", logger.Log, this.manager);
            var ini    = new IniWatcher(this.Me, this.manager);
            var wc     = new WheelsController(this.cmd, cockpit, this.GridTerminalSystem, ini, this.manager, ct);
            var ac     = new ArmController(ini, this, this.cmd, cockpit, wc, this.manager);
            var client = new ConnectionClient(ini, this.GridTerminalSystem, this.IGC, this.cmd, this.manager, logger.Log);
            var ah     = new PilotAssist(this.GridTerminalSystem, ini, logger.Log, this.manager, wc);

            ah.AddBraker(client);
        }
Ejemplo n.º 24
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                m_texture = Game.Content.Load <Texture2D>("Images/x_wing");
            }

            Vector2 origin      = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);
            Vector2 scaleVector = CoordinatesTransformer.CreateScaleVector(GameObject.RelativeGeometry.BoundingRectangle.Size,
                                                                           new Size(m_texture.Width, m_texture.Height));

            spriteBatch.Draw(m_texture,
                             CoordinatesTransformer.Transform(GameObject.Position),
                             null,
                             Color.White,
                             MathHelper.ToRadians((float)GameObject.Rotation),
                             origin,
                             scaleVector,
                             SpriteEffects.None,
                             LayersDepths.Plane);
        }
Ejemplo n.º 25
0
        public void DrawOnMinimap(GameTime gameTime, SpriteBatch minimapSpriteBatch, CoordinatesTransformer coordinatesTransformer)
        {
            if (m_minimapTexture == null)
            {
                m_minimapTexture = Game.Content.Load <Texture2D>("Minimap/bonus_location");
            }

            var origin     = new Vector2(m_minimapTexture.Width / 2.0f, m_minimapTexture.Height / 2.0f);
            var targetSize = new Vector2(10, 10);
            var scale      = new Vector2(targetSize.X / m_minimapTexture.Width, targetSize.Y / m_minimapTexture.Height);

            minimapSpriteBatch.Draw(m_minimapTexture,
                                    coordinatesTransformer.Transform(GameObject.Position),
                                    null,
                                    Color * 0.8f,
                                    (float)Helper.ToRadians(GameObject.Rotation),
                                    origin,
                                    scale,
                                    SpriteEffects.None,
                                    1.0f);
        }
            public AutoConnectionDispatcher(MyGridProgram program, CommandLine command, MyIni ini, Action <string> logger, IProcessManager manager)
            {
                this.logger  = logger;
                this.manager = manager;
                // Station level initialization
                this.stationName   = ini.GetThrow(INI_GENERAL_SECTION, INI_NAME_KEY).ToString();
                this.referenceName = ini.GetThrow(INI_GENERAL_SECTION, INI_REFERENCE_KEY).ToString();
                IMyTerminalBlock reference = program.GridTerminalSystem.GetBlockWithName(this.referenceName);

                if (reference == null)
                {
                    throw new ArgumentException($"Could not find reference block '{this.referenceName}'");
                }
                this.igc         = program.IGC;
                this.transformer = new CoordinatesTransformer(reference, manager);
                this.log("initializing");
                // Connectors initialization
                var sections = new List <string>();

                ini.GetSections(sections);
                foreach (string sectionName in sections.Where(s => s.StartsWith(AutoConnector.IniConnectorPrefix)))
                {
                    var connector = new AutoConnector(this.stationName, sectionName, program, this.logger, this.transformer, ini);
                    this.autoConnectors.Add(new AutoConnectionServer(ini, this.igc, connector, manager, this.logger));
                }
                this.log($"has {this.autoConnectors.Count} auto connectors");
                this.registerCommands(command, program);

                IMyBroadcastListener listener = this.igc.RegisterBroadcastListener("StationConnectionRequests");

                this.manager.Spawn(p => {
                    if (listener.HasPendingMessage)
                    {
                        MyIGCMessage msg = listener.AcceptMessage();
                        command.StartCmd($"{msg.As<string>()} {msg.Source}", CommandTrigger.Antenna);
                    }
                }, "ac-dispatcher");

                this.manager.AddOnSave(save);
            }
Ejemplo n.º 27
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            var            topLefts  = new List <IMyTextSurface>();
            var            topRights = new List <IMyTextSurface>();
            IMyTextSurface keyboard;
            IMyCockpit     cockpit;

            this.manager = Process.CreateManager(this.Echo);
            this.initCockpit(out cockpit, topLefts, topRights, out keyboard);
            var ct     = new CoordinatesTransformer(cockpit, this.manager);
            var logger = new Logger(this.manager, keyboard, new Color(0, 39, 15), new Color(27, 228, 33), this.Echo, 1.0f);

            this.cmd = new CommandLine("Boring machine", logger.Log, this.manager);
            var ini = new IniWatcher(this.Me, this.manager);
            var wc  = new WheelsController(this.cmd, cockpit, this.GridTerminalSystem, ini, this.manager, ct);
            var ac  = new ArmController(ini, this, this.cmd, cockpit, wc, this.manager);
            var iw  = new InventoryWatcher(this.cmd, this.GridTerminalSystem, cockpit);
            var cc  = new ConnectionClient(ini, this.GridTerminalSystem, this.IGC, this.cmd, this.manager, logger.Log);
            var rcs = new List <IMyRemoteControl>();

            this.GridTerminalSystem.GetBlocksOfType(rcs, r => r.CubeGrid == this.Me.CubeGrid);
            IMyRemoteControl frc = rcs.First(r => r.DisplayNameText.Contains("Forward"));
            IMyRemoteControl brc = rcs.First(r => r.DisplayNameText.Contains("Backward"));
            var ap = new Autopilot(ini, wc, this.cmd, frc, logger.Log, this.manager);
            var ah = new PilotAssist(this.GridTerminalSystem, ini, logger.Log, this.manager, wc);

            ah.AddBraker(cc);
            ah.AddDeactivator(ap);
            var ar = new AutoRoutineHandler(this.cmd);

            // TODO parse routines
            new MiningRoutines(ini, this.cmd, ap, this.manager);
            var progs = new List <IMyProgrammableBlock>();

            this.GridTerminalSystem.GetBlocksOfType(progs, pr => pr.CubeGrid == this.Me.CubeGrid);
            var genStatus = new GeneralStatus(this, ac, cc);

            new ScreensController(genStatus, iw, topLefts, topRights, this.scheme, cockpit.CustomData, this.manager);
        }
Ejemplo n.º 28
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (m_texture == null)
            {
                m_texture = Game.Content.Load <Texture2D>("Images/weapon");
            }

            if (m_lastShotDateTime != Equipment.LastShotDateTime)
            {
                m_lastShotDateTime = Equipment.LastShotDateTime;

                m_particlesEmitter.Emit(new Particle(Game, CoordinatesTransformer)
                {
                    Color              = Color.White,
                    Position           = Equipment.GetAbsolutePosition(),
                    Size               = new Size(1, 1),
                    AlphaVelocity      = -3.0f,
                    TimeToLive         = TimeSpan.FromSeconds(2),
                    Velocity           = Equipment.RelatedGameObject.Velocity + new Vector(0, 10).Rotate(Equipment.GetAbsoluteRotation()),
                    SizeFactorVelocity = new Vector(6, 6)
                }, 3);
            }

            var origin = new Vector2(m_texture.Width / 2.0f, m_texture.Height / 2.0f);

            var scaleVector = CoordinatesTransformer.CreateScaleVector(Equipment.Size,
                                                                       new Size(m_texture.Width, m_texture.Height));

            spriteBatch.Draw(m_texture,
                             CoordinatesTransformer.Transform(Equipment.GetAbsolutePosition()),
                             null,
                             Color.White,
                             MathHelper.ToRadians((float)Equipment.GetAbsoluteRotation()),
                             origin,
                             scaleVector,
                             SpriteEffects.None,
                             LayersDepths.Weapon);
        }
Ejemplo n.º 29
0
        public Program()
        {
            this.Runtime.UpdateFrequency = UpdateFrequency.Update1;
            IMyTextSurface topLeft, topRight, keyboard;
            IMyCockpit     cockpit;

            this.manager = Process.CreateManager(this.Echo);
            this.initCockpit(out cockpit, out topLeft, out topRight, out keyboard);
            var ct     = new CoordinatesTransformer(cockpit, this.manager);
            var logger = new Logger(this.manager, keyboard, this.scheme.Light, this.scheme.Dark, this.Echo);

            logger.Log("Booting up...");
            this.cmd = new CommandLine("Boring machine", logger.Log, this.manager);
            var genStatus = new GeneralStatus(this, this.cmd);
            var wb        = new WheelBase();
            var wheels    = new List <IMyMotorSuspension>();

            this.GridTerminalSystem.GetBlocksOfType(wheels, w => w.CubeGrid == this.Me.CubeGrid && w.DisplayNameText.Contains("Power"));
            wheels.ForEach(w => wb.AddWheel(new PowerWheel(w, wb, ct)));
            var ic = new InventoriesController(ct, this.GridTerminalSystem, cockpit, wb.CenterOfTurnZ + 2, this.manager);

            new ScreensController(genStatus, ic, topLeft, topRight, this.scheme, cockpit.CustomData, this.manager);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Re creates a serialized auto connector
 /// </summary>
 /// <param name="stationName"></param>
 /// <param name="sectionName"></param>
 /// <param name="program"></param>
 /// <param name="posTransformer"></param>
 /// <param name="orientationTransformer"></param>
 /// <param name="ini"></param>
 public AutoConnector(
     string stationName,
     string sectionName,
     MyGridProgram program,
     Action <string> logger,
     CoordinatesTransformer transformer,
     MyIni ini)
     : this(stationName, sectionName.Substring(IniConnectorPrefix.Length), program, logger, transformer)
 {
     // Parse ini
     this.log($"parsing configuration");
     this.initializationStage = ini.GetThrow(sectionName, INI_STAGE).ToInt32();
     this.log($"at stage {this.initializationStage} ({(this.IsInitialized() ? "" : "not ")}initialized)");
     if (this.initializationStage > 1)
     {
         this.max = ini.GetVector(sectionName, "max");
     }
     if (this.initializationStage > 3)
     {
         this.min = ini.GetVector(sectionName, "min");
         this.initRestPosition();
     }
     this.deserializeWaypoints(sectionName, ini);
 }
Ejemplo n.º 31
0
            /// <summary>
            /// Creates a new Auto connector
            /// </summary>
            /// <param name="stationName"></param>
            /// <param name="name"></param>
            /// <param name="program"></param>
            /// <param name="posTransformer"></param>
            /// <param name="orientationTransformer"></param>
            public AutoConnector(
                string stationName,
                string name,
                MyGridProgram program,
                Action <string> logger,
                CoordinatesTransformer transformer)
            {
                this.logger = logger;
                IMyGridTerminalSystem gts = program.GridTerminalSystem;

                this.Name = name;
                this.log($"initialization");
                // initialize moving parts
                this.initMandatoryField(gts, $"{stationName} Connector {this.Name} Down", out this.downConnector);
                this.initMandatoryField(gts, $"{stationName} Connector {this.Name} Front", out this.frontConnector);
                this.initMandatoryField(gts, $"{stationName} Rotor {this.Name}", out this.stator);
                if (this.downConnector == null && this.frontConnector == null)
                {
                    throw new InvalidOperationException("Need at least one connector");
                }
                this.transformer = transformer;
                string pistonPrefix = $"{stationName} Piston {this.Name}";
                var    pistons      = new List <IMyPistonBase>();

                gts.GetBlocksOfType(pistons, p => p.DisplayNameText.StartsWith(pistonPrefix));
                this.x = new Actuator(4);
                this.y = new Actuator(1);
                this.z = new Actuator(2);
                foreach (IMyPistonBase piston in pistons)
                {
                    Vector3D up  = this.transformer.Dir(piston.WorldMatrix.Up);
                    double   dot = FORWARD.Dot(up);
                    if (Math.Abs(dot) > 0.95)
                    {
                        bool isNegative = dot < 0;
                        piston.CustomName = pistonPrefix + " " + (isNegative ? "-" : "") + "Z";
                        this.z.AddPiston(piston, isNegative);
                        continue;
                    }
                    dot = LEFT.Dot(up);
                    if (Math.Abs(dot) > 0.95)
                    {
                        bool isNegative = dot < 0;
                        piston.CustomName = pistonPrefix + " " + (isNegative ? "-" : "") + "X";
                        this.x.AddPiston(piston, isNegative);
                        continue;
                    }
                    dot = UP.Dot(up);
                    if (Math.Abs(dot) > 0.95)
                    {
                        bool isNegative = dot < 0;
                        piston.CustomName = pistonPrefix + " " + (isNegative ? "-" : "") + "Y";
                        this.y.AddPiston(piston, isNegative);
                        continue;
                    }
                    this.log($"Could not place piston '{piston.DisplayNameText}'");
                }
                if (!this.x.IsValid)
                {
                    throw new InvalidOperationException($"Connector '{this.Name}': no piston on axis X");
                }
                if (!this.y.IsValid)
                {
                    throw new InvalidOperationException($"Connector '{this.Name}': no piston on axis Y");
                }
                if (!this.z.IsValid)
                {
                    throw new InvalidOperationException($"Connector '{this.Name}': no piston on axis Z");
                }
                if (this.frontConnector?.Status == MyShipConnectorStatus.Connected)
                {
                    this.lastConnectionType = ConnectionType.Front;
                }
                else if (this.downConnector?.Status == MyShipConnectorStatus.Connected)
                {
                    this.lastConnectionType = ConnectionType.Down;
                }
                gts.GetBlocksOfType(this.lights, l => l.CubeGrid == (this.frontConnector ?? this.downConnector).CubeGrid);
            }