/// <summary>
 /// Shot from weapon which is bind at fire key. Fire is delayed because we want to shoot from already simulated ship
 /// </summary>
 /// <param name="key">Fire key</param>
 public void Fire(MyMwcObjectBuilder_FireKeyEnum key)
 {
     if (!m_keysToShot.Contains((int)key))
     {
         m_keysToShot.Enqueue((int)key);
     }
 }
 public MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum fireKey, 
     MyMwcObjectBuilder_AmmoGroupEnum group, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType)
 {
     FireKey = fireKey;
     Group = group;
     AmmoType = ammoType;
 }
 public MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum fireKey,
                                            MyMwcObjectBuilder_AmmoGroupEnum group, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType)
 {
     FireKey  = fireKey;
     Group    = group;
     AmmoType = ammoType;
 }
Example #4
0
 /// <summary>
 /// Returns ammo assignment by fire key (ammo group, ammo type)
 /// </summary>
 /// <param name="fireKey">Fire key</param>
 /// <param name="ammoGroup">Ammo group</param>
 /// <param name="ammoType">Ammmo type</param>
 /// <returns></returns>
 public MyAmmoAssignment GetAmmoAssignment(MyMwcObjectBuilder_FireKeyEnum fireKey)
 {
     if (m_ammoAssignmentCollection.ContainsKey((int)fireKey))
     {
         return(m_ammoAssignmentCollection[(int)fireKey]);
     }
     return(null);
 }
Example #5
0
        /// <summary>
        /// Returns ammo special text by fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        /// <returns></returns>
        public StringBuilder GetAmmoSpecialText(MyMwcObjectBuilder_FireKeyEnum key)
        {
            //Get ammo type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = GetAmmoType(key);

            if (ammoType == 0)
            {
                return(null);
            }

            return(GetAmmoSpecialText(ammoType));
        }
Example #6
0
        /// <summary>
        /// Returns ammo type by fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        /// <returns></returns>
        public MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum GetAmmoType(MyMwcObjectBuilder_FireKeyEnum key)
        {
            MyAmmoAssignment ammoAssignment = GetAmmoAssignment(key);

            if (ammoAssignment == null)
            {
                return(0);
            }
            else
            {
                return(ammoAssignment.AmmoType);
            }
        }
Example #7
0
        /// <summary>
        /// Assign ammo group, ammo type to fire key
        /// </summary>
        /// <param name="fireKey">Fire key</param>
        /// <param name="ammoGroup">Ammo group</param>
        /// <param name="ammoType">Ammmo type</param>
        public void AssignAmmo(MyMwcObjectBuilder_FireKeyEnum fireKey, MyMwcObjectBuilder_AmmoGroupEnum ammoGroup, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType)
        {
            MyAmmoAssignment ammoAssignment = GetAmmoAssignment(fireKey);

            if (ammoAssignment != null)
            {
                ammoAssignment.AmmoGroup = ammoGroup;
                ammoAssignment.AmmoType  = ammoType;
            }
            else
            {
                m_ammoAssignmentCollection.Add((int)fireKey, new MyAmmoAssignment(fireKey, ammoGroup, ammoType));
            }
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);

            m_isInvalid = false;
            m_target    = SourceDesire.GetEnemy();
            if (m_target != null)
            {
                Debug.Assert(m_target != bot);
            }
            findSmallship = new MyFindSmallshipHelper();

            m_visibilityCheckTimer = 0;       // force visibility test
            m_closingTimer         = 0;
            m_forcedClosingTimer   = 0;
            m_hologramTargetTimer  = 0;

            SwitchToClosing();

            PlanNextMissile();

            m_timeToAlarmCheck = 2;

            m_playerAttackDecisionTimer = 0;

            MyScriptWrapper.OnEntityAttackedByBot(bot, m_target);

            m_canShootWithAutocanon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Primary);
            m_canShootWithShotGun   = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Secondary);
            m_canShootWithSniper    = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Third);
            m_canShootMissile       = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fourth);
            m_canShootCannon        = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fifth);

            m_canShootFlash    = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront) && MyFakes.BOT_USE_FLASH_BOMBS;
            m_canShootSmoke    = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront) && MyFakes.BOT_USE_SMOKE_BOMBS;
            m_canShootHologram = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.HologramFront) && MyFakes.BOT_USE_HOLOGRAMS;

            m_weaponChangeTimer = 0;
            m_currentWeapon     = SelectWeapon((bot.GetPosition() - m_target.GetPosition()).Length());

            m_smokeBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_flashBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_hologramTimer  = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
        }
        /// <summary>
        /// Updates all weapons after integration
        /// </summary>
        public void UpdateAfterSimulation()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MySmallShipWeapons.UAI fire");
            while (m_keysToShot.Count > 0)
            {
                MyMwcObjectBuilder_FireKeyEnum keyToShot = (MyMwcObjectBuilder_FireKeyEnum)m_keysToShot.Dequeue();
                FirePrivate(keyToShot);
            }
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MySmallShipWeapons.UAI weapons");

            /*
             * foreach (MySmallShipGunBase gun in GetMountedWeaponstWithHarvesterAndDrill())
             * {
             *  gun.UpdateAfterSimulation();
             * }
             */

            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        //  Read this object from message-in
        internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            if (base.Read(binaryReader, senderEndPoint, gameVersion) == false)
            {
                return(NetworkError());
            }

            //  FireKey
            MyMwcObjectBuilder_FireKeyEnum?fireKey = MyMwcMessageIn.ReadObjectBuilderSmallShipAssignmentOfAmmoFireKeyEnumEx(binaryReader, senderEndPoint);

            if (fireKey == null)
            {
                return(NetworkError());
            }
            FireKey = fireKey.Value;
            MyMwcLog.IfNetVerbose_AddToLog("FireKey: " + FireKey);

            //  FireKey
            MyMwcObjectBuilder_AmmoGroupEnum?group = MyMwcMessageIn.ReadObjectBuilderSmallShipAssignmentOfAmmoGroupEnumEx(binaryReader, senderEndPoint);

            if (group == null)
            {
                return(NetworkError());
            }
            Group = group.Value;
            MyMwcLog.IfNetVerbose_AddToLog("Group: " + Group);

            //  Ammo Type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum?ammoType = MyMwcMessageIn.ReadObjectBuilderSmallShipAmmoTypesEnumEx(binaryReader, senderEndPoint);

            if (ammoType == null)
            {
                return(NetworkError());
            }
            AmmoType = ammoType.Value;
            MyMwcLog.IfNetVerbose_AddToLog("AmmoType: " + AmmoType);

            return(true);
        }
        /// <summary>
        /// Returns amount of ammo which is bind at fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        /// <returns></returns>
        public int GetAmountOfAmmo(MyMwcObjectBuilder_FireKeyEnum key)
        {
            if (AmmoInventoryItems.Count() == 0 || AmmoAssignments.Count() == 0)
            {
                return(0);
            }

            //Get ammo type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = AmmoAssignments.GetAmmoType(key);

            if (ammoType == 0)
            {
                return(0);
            }

            //Get amount
            int result = 0;

            foreach (MyInventoryItem ammoInventoryItem in AmmoInventoryItems.GetAmmoInventoryItems(ammoType))
            {
                result += (int)ammoInventoryItem.Amount;
            }
            return(result);
        }
Example #12
0
        private bool TryAssignAmmo(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum weaponType, MyMwcObjectBuilder_AmmoGroupEnum ammoGroup, MyMwcObjectBuilder_FireKeyEnum fireKey, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum[] ammoPriorities)
        {
            for (int i = 0; i < ammoPriorities.Length; i++)
            {
                if (Weapons.AmmoInventoryItems.GetAmmoInventoryItems(ammoPriorities[i]).Count > 0)
                {
                    Weapons.AmmoAssignments.AssignAmmo(fireKey, ammoGroup, ammoPriorities[i]);

                    MyBotParams botParamsOneSlot = SettingsForWeaponType(weaponType, ammoPriorities[i]);
                    botParamsOneSlot.FireKey = fireKey;
                    botParamsOneSlot.HasAmmo = true;
                    m_botWeaponParamsAllSlots[(int)fireKey - 1] = botParamsOneSlot;
                    return true;
                }
            }
            return false;
        }
Example #13
0
        public void Shoot(MyMwcObjectBuilder_FireKeyEnum fireKey)
        {
            if (m_botWeaponParamsAllSlots == null)
                return;

            MyBotParams weaponParams = m_botWeaponParamsAllSlots[(int)fireKey - 1];
            
            if (!weaponParams.Enabled || !weaponParams.HasAmmo)
            {
                return;
            }

            weaponParams.LastShotMilliseconds = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            Weapons.Fire(fireKey);
        }
Example #14
0
 public bool CanShootWith(MyMwcObjectBuilder_FireKeyEnum fireKey)
 {
     var parameters = m_botWeaponParamsAllSlots[(int)fireKey - 1];
     return parameters.Enabled && parameters.HasAmmo;
 }
        //  Read this object from message-in
        internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            if (base.Read(binaryReader, senderEndPoint, gameVersion) == false) return NetworkError();

            //  FireKey
            MyMwcObjectBuilder_FireKeyEnum? fireKey = MyMwcMessageIn.ReadObjectBuilderSmallShipAssignmentOfAmmoFireKeyEnumEx(binaryReader, senderEndPoint);
            if (fireKey == null) return NetworkError();
            FireKey = fireKey.Value;
            MyMwcLog.IfNetVerbose_AddToLog("FireKey: " + FireKey);

            //  FireKey
            MyMwcObjectBuilder_AmmoGroupEnum? group = MyMwcMessageIn.ReadObjectBuilderSmallShipAssignmentOfAmmoGroupEnumEx(binaryReader, senderEndPoint);
            if (group == null) return NetworkError();
            Group = group.Value;
            MyMwcLog.IfNetVerbose_AddToLog("Group: " + Group);

            //  Ammo Type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum? ammoType = MyMwcMessageIn.ReadObjectBuilderSmallShipAmmoTypesEnumEx(binaryReader, senderEndPoint);
            if (ammoType == null) return NetworkError();
            AmmoType = ammoType.Value;
            MyMwcLog.IfNetVerbose_AddToLog("AmmoType: " + AmmoType);

            return true;
        }
 public static void WriteObjectBuilderSmallShipAssignmentOfAmmoFireKeyEnum(MyMwcObjectBuilder_FireKeyEnum val, BinaryWriter binaryWriter)
 {
     binaryWriter.Write((byte)val);
 }
Example #17
0
        public static void Update()
        {
            if (m_isEnabled == false)
            {
                return;
            }

            foreach (KeyValuePair <MyEntity, Dictionary <int, MyPhysObjectTrackedTickData> > kvp in m_attachedPhysObjects)
            {
                MyEntity physObject = kvp.Key;

                Dictionary <int, MyPhysObjectTrackedTickData> ticks = kvp.Value;

                MyPhysObjectTrackedTickData tickData;

                //  Check if thick is in the dictionary, because if not, our trailer is probably running longer then tracked data and we don't want to throw exception
                //  So object just stops receiving data from here and start behaving normaly
                if (ticks.TryGetValue(m_activeTick, out tickData) == true)
                {
                    MySmallShip minerShip = (MySmallShip)physObject;

                    if (minerShip.IsDead())
                    {
                        continue;
                    }

                    Matrix tickMatrix = tickData.Orientation;
                    tickMatrix.Translation           = tickData.Position;
                    minerShip.Physics.LinearVelocity = (minerShip.WorldMatrix.Translation - tickData.Position) / MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                    minerShip.SetWorldMatrix(tickMatrix);
                    minerShip.TrailerUpdate(tickData.ReflectorLevel, tickData.EngineLevel);

                    if (tickData.GunShot != null)
                    {
                        MyMwcObjectBuilder_FireKeyEnum fireKey = MyMwcObjectBuilder_FireKeyEnum.Primary;
                        switch (tickData.GunShot.Value)
                        {
                        case MyTrailerGunsShotTypeEnum.PROJECTILE:
                            fireKey = MyMwcObjectBuilder_FireKeyEnum.Primary;
                            break;

                        case MyTrailerGunsShotTypeEnum.MISSILE:
                            fireKey = MyMwcObjectBuilder_FireKeyEnum.Secondary;
                            break;

                        case MyTrailerGunsShotTypeEnum.MISSILE_GUIDED:
                            fireKey = MyMwcObjectBuilder_FireKeyEnum.Third;
                            break;

                        case MyTrailerGunsShotTypeEnum.DRILLING_DEVICE:
                            fireKey = MyMwcObjectBuilder_FireKeyEnum.Fourth;
                            break;

                        case MyTrailerGunsShotTypeEnum.HARVESTING_ORE:
                            fireKey = MyMwcObjectBuilder_FireKeyEnum.Fifth;
                            break;

                        default:
                            throw new MyMwcExceptionApplicationShouldNotGetHere();
                            break;
                        }

                        minerShip.Weapons.Fire(fireKey);
                    }
                }
            }

            IncreaseActiveTick();
        }
        void HandleShooting(MySmallShipBot bot, float distance, float angleToTarget, bool targetVisible)
        {
            if (bot.InitTime > 0)
            {
                return;
            }

            if (!MyBotCoordinator.IsAllowedToAttack(bot, m_target))
            {
                return;
            }

            m_smokeBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_flashBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_hologramTimer  -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

            // Change weapon - 2sec CD
            if (m_weaponChangeTimer < 2)
            {
                m_weaponChangeTimer = 0;

                var oldWeapon = m_currentWeapon;
                m_currentWeapon = SelectWeapon(distance);

                if (m_currentWeapon != oldWeapon)
                {
                    m_fireState = FireStateEnum.WAIT;
                }
            }

            // Handle weapon shooting
            switch (m_currentWeapon)
            {
            case MyMwcObjectBuilder_FireKeyEnum.Primary:
                ShootAutocannon(bot, targetVisible, distance, angleToTarget);
                break;

            case MyMwcObjectBuilder_FireKeyEnum.Secondary:
                ShootShotgun(bot, targetVisible, distance, angleToTarget);
                break;

            case MyMwcObjectBuilder_FireKeyEnum.Third:
                ShootSniper(bot, targetVisible, distance, angleToTarget);
                break;
            }

            if (MyFakes.ENABLE_BOT_MISSILES_AND_CANNON)
            {
                if (m_canShootFlash &&
                    m_flashBombTimer <= 0 &&
                    targetVisible &&
                    distance > 125 && distance < 250 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_flashBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront);
                }

                if (m_canShootSmoke &&
                    m_smokeBombTimer <= 0 &&
                    targetVisible &&
                    distance > 150 && distance < 300 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_smokeBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront);
                }

                if (m_canShootHologram &&
                    m_hologramTimer <= 0 &&
                    distance > 100 && distance < 500)
                {
                    m_hologramTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.HologramFront);
                }

                // Handle missile and cannon shooting
                if (m_canShootMissile || m_canShootCannon)
                {
                    MyMwcObjectBuilder_FireKeyEnum firekey;
                    if (m_canShootMissile)
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fourth;
                    }
                    else
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fifth;
                    }

                    int missileFireTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_planedMissileTime;
                    if (missileFireTime > 0)
                    {
                        if (missileFireTime > 1500)
                        {
                            // if bot can't shoot in 1.5 sec, wait for next time window
                            PlanNextMissile();
                        }
                        else if (targetVisible &&
                                 distance >= MyFakes.BOT_MISSILE_FIRING_RANGE_MIN &&
                                 distance <= FIRING_RANGE_MAX &&
                                 angleToTarget < SHOOT_CONE)
                        {
                            // Successful shot
                            bot.Shoot(firekey);
                            PlanNextMissile();
                        }
                    }
                }
            }
        }
        void HandleShooting(MySmallShipBot bot, float distance, float angleToTarget, bool targetVisible)
        {
            if (bot.InitTime > 0)
                return;

            if (!MyBotCoordinator.IsAllowedToAttack(bot, m_target))
            {      
                return;
            }

            m_smokeBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_flashBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_hologramTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

            // Change weapon - 2sec CD
            if (m_weaponChangeTimer < 2)
            {
                m_weaponChangeTimer = 0;

                var oldWeapon = m_currentWeapon;
                m_currentWeapon = SelectWeapon(distance);
                
                if (m_currentWeapon != oldWeapon)
                {
                    m_fireState = FireStateEnum.WAIT;
                }
            }

            // Handle weapon shooting
            switch (m_currentWeapon)
            {
                case MyMwcObjectBuilder_FireKeyEnum.Primary:
                    ShootAutocannon(bot, targetVisible, distance, angleToTarget);
                    break;
                case MyMwcObjectBuilder_FireKeyEnum.Secondary:
                    ShootShotgun(bot, targetVisible, distance, angleToTarget);
                    break;
                case MyMwcObjectBuilder_FireKeyEnum.Third:
                    ShootSniper(bot, targetVisible, distance, angleToTarget);
                    break;
            }

            if (MyFakes.ENABLE_BOT_MISSILES_AND_CANNON)
            {
                if (m_canShootFlash &&
                    m_flashBombTimer <= 0 &&
                    targetVisible &&
                    distance > 125 && distance < 250 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_flashBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront);
                }

                if (m_canShootSmoke &&
                    m_smokeBombTimer <= 0 &&
                    targetVisible &&
                    distance > 150 && distance < 300 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_smokeBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront);
                }

                if (m_canShootHologram &&
                    m_hologramTimer <= 0 &&
                    distance > 100 && distance < 500)
                {
                    m_hologramTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.HologramFront);
                }

                // Handle missile and cannon shooting
                if (m_canShootMissile || m_canShootCannon)
                {
                    MyMwcObjectBuilder_FireKeyEnum firekey;
                    if (m_canShootMissile)
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fourth;
                    }
                    else
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fifth;
                    }

                    int missileFireTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_planedMissileTime;
                    if (missileFireTime > 0)
                    {

                        if (missileFireTime > 1500)
                        {
                            // if bot can't shoot in 1.5 sec, wait for next time window
                            PlanNextMissile();
                        }
                        else if (targetVisible &&
                            distance >= MyFakes.BOT_MISSILE_FIRING_RANGE_MIN &&
                            distance <= FIRING_RANGE_MAX &&
                            angleToTarget < SHOOT_CONE)
                        {
                            // Successful shot
                            bot.Shoot(firekey);
                            PlanNextMissile();
                        }
                    }
                }
            }
        }
Example #20
0
 /// <summary>
 /// Returns ammo type by fire key
 /// </summary>
 /// <param name="key">Fire key</param>
 /// <returns></returns>
 public MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum GetAmmoType(MyMwcObjectBuilder_FireKeyEnum key)
 {
     MyAmmoAssignment ammoAssignment = GetAmmoAssignment(key);
     if (ammoAssignment == null)
     {
         return 0;
     }
     else
     {
         return ammoAssignment.AmmoType;
     }
 }
Example #21
0
        private float GetLevelOfAmmo(MyMwcObjectBuilder_FireKeyEnum fireKey)
        {
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = Weapons.AmmoAssignments.GetAmmoType(fireKey);
            float maxAmount = 1;
            if (ammoType != 0)
            {
                maxAmount = MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)ammoType, Faction).MaxAmount;
            }

            int amount = Weapons.GetAmountOfAmmo(fireKey);
            return amount / maxAmount;
        }
Example #22
0
 /// <summary>
 /// Assign ammo group, ammo type to fire key
 /// </summary>
 /// <param name="fireKey">Fire key</param>
 /// <param name="ammoGroup">Ammo group</param>
 /// <param name="ammoType">Ammmo type</param>
 public void AssignAmmo(MyMwcObjectBuilder_FireKeyEnum fireKey, MyMwcObjectBuilder_AmmoGroupEnum ammoGroup, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType)
 {
     MyAmmoAssignment ammoAssignment = GetAmmoAssignment(fireKey);
     if (ammoAssignment != null)
     {
         ammoAssignment.AmmoGroup = ammoGroup;
         ammoAssignment.AmmoType = ammoType;
     }
     else
     {
         m_ammoAssignmentCollection.Add((int)fireKey, new MyAmmoAssignment(fireKey, ammoGroup, ammoType));
     }
 }
Example #23
0
 /// <summary>
 /// Returns ammo assignment by fire key (ammo group, ammo type)
 /// </summary>
 /// <param name="fireKey">Fire key</param>
 /// <param name="ammoGroup">Ammo group</param>
 /// <param name="ammoType">Ammmo type</param>
 /// <returns></returns>
 public MyAmmoAssignment GetAmmoAssignment(MyMwcObjectBuilder_FireKeyEnum fireKey)
 {
     if (m_ammoAssignmentCollection.ContainsKey((int)fireKey)) 
     {
         return m_ammoAssignmentCollection[(int)fireKey];
     }
     return null;            
 }
        /// <summary>
        /// Shot from weapon which is bind at fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        void FirePrivate(MyMwcObjectBuilder_FireKeyEnum key)
        {
            //Do nothing if there are no ammo or weapons or assignments


            this.m_ship.InitGroupMaskIfNeeded();

            var drill = GetMountedDrill();

            if ((!MySession.Is25DSector && (drill != null && (drill.CurrentState == MyDrillStateEnum.Activated || drill.CurrentState == MyDrillStateEnum.Drilling))) ||
                (MySession.Is25DSector && drill != null && key == MyMwcObjectBuilder_FireKeyEnum.Secondary))
            {
                drill.Shot(null);
                return;
            }

            List <MySmallShipGunBase> mountedGuns = GetMountedWeaponsWithHarvesterAndDrill();

            /*if (AmmoInventoryItems.Count() == 0 || AmmoAssignments.Count() == 0 || mountedGuns.Count == 0)
             *  return;*/

            MyAmmoAssignment ammoAssignment = AmmoAssignments.GetAmmoAssignment(key);

            //If type or group is not found in object builders, do nothing
            if (ammoAssignment == null)
            {
                return;
            }

            //If type and group is bad combination, do nothing
            if (!MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).HasValue)
            {
                return;
            }

            MyInventoryItem usedAmmoInventoryItem = null;

            foreach (MyInventoryItem ammoItem in AmmoInventoryItems.GetAmmoInventoryItems(ammoAssignment.AmmoType))
            {
                if (ammoItem.Amount > 0)
                {
                    usedAmmoInventoryItem = ammoItem;
                    break;
                }
            }

            bool thereWasShot         = false;
            bool wasCountedMuzzleTime = false;

            //  Shot from gun
            foreach (MySmallShipGunBase gun in mountedGuns)
            {
                if (MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).Value == gun.WeaponType)
                {
                    bool shot = false;
                    if (usedAmmoInventoryItem != null && usedAmmoInventoryItem.Amount > 0)
                    {
                        shot = gun.Shot((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false));
                        if (shot && MyMultiplayerGameplay.IsRunning && !m_ship.IsDummy)
                        {
                            var ammo = ((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false)).AmmoType;
                            MyMultiplayerGameplay.Static.Shoot(this.m_ship, this.m_ship.WorldMatrix, gun.WeaponType, ammo, this.Ship.TargetEntity, gun.LastShotId);
                        }
                    }
                    else
                    {
                        if (m_noAmmoSoundDelay + 175 < MyMinerGame.TotalGamePlayTimeInMilliseconds)
                        {
                            Audio.MyAudio.AddCue2dOr3d(Ship, Audio.MySoundCuesEnum.WepNoAmmo, Ship.GetPosition(), Ship.WorldMatrix.Forward, Ship.WorldMatrix.Up, Ship.Physics.LinearVelocity);
                            m_noAmmoSoundDelay = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        }
                    }

                    if (shot)
                    {
                        Ship.Inventory.RemoveInventoryItemAmount(ref usedAmmoInventoryItem, 1f);
                        thereWasShot = true;
                        Ship.WeaponShot(gun, ammoAssignment);
                    }

                    //  If we shot from gun that uses projectiles, we need to remember it as last time of muzzle flash
                    if ((shot == true) &&
                        MyGuiSmallShipHelpers.IsAmmoInGroup(ammoAssignment.AmmoType, MyMwcObjectBuilder_AmmoGroupEnum.Bullet) &&
                        !wasCountedMuzzleTime)
                    {
                        MuzzleFlashLastTime  = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        wasCountedMuzzleTime = true;
                    }
                }
            }

            if (thereWasShot == true)
            {
                Ship.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_GUN_SHOT);
            }
        }
Example #25
0
        /// <summary>
        /// Returns ammo special text by fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        /// <returns></returns>
        public StringBuilder GetAmmoSpecialText(MyMwcObjectBuilder_FireKeyEnum key)
        {
            //Get ammo type
            MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType = GetAmmoType(key);
            if (ammoType == 0) return null;

            return GetAmmoSpecialText(ammoType);
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);
            
            m_isInvalid = false;
            m_target = SourceDesire.GetEnemy();
            if (m_target != null)
            {
                Debug.Assert(m_target != bot);
            }
            findSmallship = new MyFindSmallshipHelper();

            m_visibilityCheckTimer = 0;       // force visibility test
            m_closingTimer = 0;
            m_forcedClosingTimer = 0;
            m_hologramTargetTimer = 0;

            SwitchToClosing();
            
            PlanNextMissile();

            m_timeToAlarmCheck = 2;
            
            m_playerAttackDecisionTimer = 0;

            MyScriptWrapper.OnEntityAttackedByBot(bot, m_target);

            m_canShootWithAutocanon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Primary);
            m_canShootWithShotGun = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Secondary);
            m_canShootWithSniper = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Third);
            m_canShootMissile = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fourth);
            m_canShootCannon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fifth);

            m_canShootFlash = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront) && MyFakes.BOT_USE_FLASH_BOMBS;
            m_canShootSmoke = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront) && MyFakes.BOT_USE_SMOKE_BOMBS;
            m_canShootHologram = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.HologramFront) && MyFakes.BOT_USE_HOLOGRAMS;

            m_weaponChangeTimer = 0;
            m_currentWeapon = SelectWeapon((bot.GetPosition() - m_target.GetPosition()).Length());

            m_smokeBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_flashBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_hologramTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
        }