Example #1
0
        private void OnEntityAdd(MyEntity myEntity)
        {
            try
            {
                if (DsState.State.ReInforce)
                {
                    return;
                }
                if (myEntity?.Physics == null || !myEntity.InScene || myEntity.MarkedForClose || myEntity is MyFloatingObject || myEntity is IMyEngineerToolBase)
                {
                    return;
                }
                var isMissile = myEntity.DefinitionId.HasValue && myEntity.DefinitionId.Value.TypeId == typeof(MyObjectBuilder_Missile);
                if (!isMissile && !(myEntity is MyCubeGrid))
                {
                    return;
                }

                var aabb = myEntity.PositionComp.WorldAABB;
                if (!ShieldBox3K.Intersects(ref aabb))
                {
                    return;
                }

                Asleep = false;
                if (_isServer && isMissile)
                {
                    Missiles.Add(myEntity);
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Controller OnEntityAdd: {ex}"); }
        }
Example #2
0
        /// <summary>
        /// Called from the Arena, when a bot calls the Arena.Cannon() method
        ///
        /// The Cannon() function fires a missile heading a specified range and direction.
        /// Cannon() returns 1 (true) if a missile was fired, or 0 (false) if the cannon is reloading.
        /// Degree is forced into the range 0-359 as in Scan() and Drive().
        /// Range can be 0-700, with greater ranges truncated to 700.
        ///
        /// Examples:
        ///    degree = 45;                              // set a direction to test
        ///    if ((range=Scan(robot, degree, 2)) > 0)   // see if a target is there
        ///      Cannon(robot, degree, range);           // fire a missile
        /// </summary>
        /// <param name="robot"></param>
        /// <param name="degree"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        public bool FireCannon(Robot robot, int degree, int range)
        {
            degree = Arena.DegreeTo360(degree);
            if (range < 0)
            {
                range = 0;
            }
            if (range > 700)
            {
                range = 700;
            }

            BotAssembly bot = Bots.Find(botAssembly => botAssembly.Id == robot.Id);

            if (bot.MissilesInFlight < MaxMissles)
            {
                bot.MissilesInFlight++;
                Missiles.Add(new Missile
                {
                    Id       = robot.Id,
                    Speed    = 100,
                    Location = new PointF {
                        X = bot.Location.X, Y = bot.Location.Y
                    },
                    Direction = degree,
                    Range     = range
                });

                return(true);
            }

            return(false);
        }
Example #3
0
 public void CreateMissile(double fps)
 {
     if (_lastShot >= fps / _shotsPerSec)
     {
         Position p = Pos;
         p.Y += Height / 2;
         Missile m = new Missile(_grid, p, new GBsharp2.Primitives.Vector(Missile.Acceleration, 0) + Vec);
         m.Draw();
         Missiles.Add(m);
         _lastShot = 0;
     }
 }
Example #4
0
 public void Fire(ServerShip ship, bool isLeft, int number, int idTarget, Ecm jammer)
 {
     lock (m_locker)
     {
         if (ship.Missiles == 0)
         {
             return;
         }
         var target = Ships.ById(idTarget);
         if (target == null || isLeft != ship.IsLeftBoard(target))
         {
             return;
         }
         var board        = isLeft ? ship.Left : ship.Right;
         var missileClass = board.GetRack(number).MissileClass;
         if (!board.Fire(number))
         {
             return;
         }
         ship.Missiles--;
         int id      = Interlocked.Increment(ref IdNext);
         var missile = new Missile
         {
             Id           = id,
             Position     = ship.Position,
             Speed        = ship.Speed,
             Acceleration = ship.Acceleration,
         };
         var control = new MissileControl
         {
             Id          = id,
             Arrow       = missile,
             Origin      = ship,
             Target      = target,
             IdOrigin    = ship.Id,
             IdTarget    = target.Id,
             Jammer      = jammer,
             Thrust      = missileClass.Acceleration,
             Remaining   = missileClass.FlyTime,
             HitDistance = missileClass.HitDistance,
             Started     = Time.TotalSeconds,
         };
         Missiles.Add(id, control);
     }
 }