Esempio n. 1
0
        public static bool CanTrade(MyEntity entityToTrade, params object[] args)
        {
            if (!ControlIsInPlayerShip() || IsBlocked(entityToTrade, args))
            {
                return(false);
            }

            bool hasRightType = /*(entityToTrade is MySmallShip) || */ (entityToTrade is MyPrefabHangar);

            if (!hasRightType)
            {
                return(false);
            }

            MySmallShip           smallShip       = GetSmallShipFromArguments(args);
            MyFactionRelationEnum factionRelation = MyFactions.GetFactionsRelation(entityToTrade, smallShip);

            if (entityToTrade is MyPrefabHangar)
            {
                MyPrefabHangar prefabHangar = entityToTrade as MyPrefabHangar;
                return((factionRelation == MyFactionRelationEnum.Neutral || factionRelation == MyFactionRelationEnum.Friend || prefabHangar.UseProperties.IsHacked) &&
                       prefabHangar.IsWorking() && prefabHangar.PrefabHangarType == MyMwcObjectBuilder_PrefabHangar_TypesEnum.VENDOR && IsTargetVisible(smallShip, prefabHangar));
            }
            else
            {
                Debug.Fail("This shouldn't happen! You can't trade with bot");
                return(factionRelation == MyFactionRelationEnum.Neutral &&
                       !IsShipLootable(entityToTrade as MySmallShip) &&
                       IsLookAtTarget(smallShip, entityToTrade));
            }
        }
Esempio n. 2
0
        static void MyFactions_OnFactionStatusChanged(MyMwcObjectBuilder_FactionEnum faction1, MyMwcObjectBuilder_FactionEnum faction2, MyFactionRelationEnum previousRelation, bool display, bool save)
        {
            if (!display)
            {
                return;
            }

            MyTextsWrapperEnum    relationChangeEnum = MyTextsWrapperEnum.General;
            MyFactionRelationEnum newRelation        = MyFactions.GetFactionsRelation(faction1, faction2);

            switch (newRelation)
            {
            case MyFactionRelationEnum.Friend:
                relationChangeEnum = MyTextsWrapperEnum.GlobalEventFactionRelationChange_NeutralToFriends;
                break;

            case MyFactionRelationEnum.Neutral:
                if (previousRelation == MyFactionRelationEnum.Friend)
                {
                    relationChangeEnum = MyTextsWrapperEnum.GlobalEventFactionRelationChange_FriendsToNeutral;
                }
                else
                {
                    relationChangeEnum = MyTextsWrapperEnum.GlobalEventFactionRelationChange_EnemyToNeutral;
                }
                break;

            case MyFactionRelationEnum.Enemy:
                relationChangeEnum = MyTextsWrapperEnum.GlobalEventFactionRelationChange_NeutralToEnemy;
                break;
            }

            MyHudNotification.AddNotification(new MyHudNotification.MyNotification(relationChangeEnum, 5000, null, new object[] { MyFactionConstants.GetFactionProperties(faction1).Name.ToString(), MyFactionConstants.GetFactionProperties(faction2).Name.ToString() }));
        }
        private void AddStatRowToListbox(MyStatsRow statsRow)
        {
            StringBuilder pingText   = GetStringBuilderLong();
            StringBuilder killsText  = GetStringBuilderShort();
            StringBuilder deathsText = GetStringBuilderShort();

            pingText.Append(statsRow.Ping.HasValue ? statsRow.Ping.Value.ToString() + "ms" : "");
            killsText.Append(statsRow.Kills.ToString());
            deathsText.Append(statsRow.Deaths.ToString());

            Vector4?rowColor = null;

            if (statsRow.IsFaction)
            {
                if (MySession.Static.Player.Faction == statsRow.Faction)
                {
                    rowColor = new Vector4(0, 1f, 0, 0.07f);
                }
                else
                {
                    rowColor = new Vector4(1f, 0, 0, 0.07f);
                }
            }
            else if (statsRow.Id == (byte)MyClientServer.LoggedPlayer.GetUserId())
            {
                rowColor = new Vector4(1f, 1f, 1f, 0.02f);
            }

            int rowIndex = m_statsListbox.AddRow(rowColor);

            var textColor = Color.White;


            MyGuiFont textFont;

            if (MyFactions.GetFactionsRelation(MySession.Static.Player.Faction, statsRow.Faction) == MyFactionRelationEnum.Friend || statsRow.Id == m_playerId)
            {
                textFont = MyGuiManager.GetFontMinerWarsGreen();
            }
            else
            {
                textFont = MyGuiManager.GetFontMinerWarsRed();
            }

            m_statsListbox.AddItem(new MyGuiControlListboxItem(rowIndex * 4 + 0,
                                                               new MyColoredText(statsRow.Name, textColor, textFont, GetRowScale(statsRow)),
                                                               null, new MyToolTips(statsRow.Name)), rowIndex, 0);

            m_statsListbox.AddItem(new MyGuiControlListboxItem(rowIndex * 4 + 1,
                                                               new MyColoredText(killsText, textColor, textFont, GetRowScale(statsRow)),
                                                               null, new MyToolTips(killsText)), rowIndex, 1);

            m_statsListbox.AddItem(new MyGuiControlListboxItem(rowIndex * 4 + 2,
                                                               new MyColoredText(deathsText, textColor, textFont, GetRowScale(statsRow)),
                                                               null, new MyToolTips(deathsText)), rowIndex, 2);

            m_statsListbox.AddItem(new MyGuiControlListboxItem(rowIndex * 4 + 3,
                                                               new MyColoredText(pingText, textColor, textFont, GetRowScale(statsRow)),
                                                               null, new MyToolTips(pingText)), rowIndex, 3);
        }
Esempio n. 4
0
        /// <summary>
        /// Kill all cheat implementation
        /// </summary>
        static void KillAllEnabled(MyGameplayCheat cheat)
        {
            // We need player ship to recognize friends
            if (MySession.PlayerShip == null)
            {
                return;
            }

            foreach (var entity in MyEntities.GetEntities().ToArray())
            {
                MySmallShip smallShip = entity as MySmallShip;
                if (smallShip != null &&
                    smallShip.Visible &&
                    smallShip != MySession.PlayerShip &&
                    MyFactions.GetFactionsRelation(MySession.PlayerShip, smallShip) == MyFactionRelationEnum.Enemy)
                {
                    entity.DoDamage(0, 1000000, 0, MyDamageType.Unknown, MyAmmoType.Unknown, null);
                }

                MyPrefabContainer container = entity as MyPrefabContainer;
                if (container != null &&
                    MyFactions.GetFactionsRelation(MySession.PlayerShip, container) == MyFactionRelationEnum.Enemy)
                {
                    foreach (var prefab in container.GetPrefabs().ToArray())
                    {
                        MyPrefabLargeWeapon largeWeapon = prefab as MyPrefabLargeWeapon;
                        if (largeWeapon != null)
                        {
                            prefab.DoDamage(0, 1000000, 0, MyDamageType.Unknown, MyAmmoType.Unknown, null);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private static void GetDetectedObjects()
        {
            using (MyEntities.EntityCloseLock.AcquireSharedUsing())
            {
                using (m_detectedObjectsLock.AcquireSharedUsing())
                {
                    Debug.Assert(m_detectedObjectsHelperCollection.Count == 0);
                    foreach (IMyObjectToDetect obj in m_objectsToDetect)
                    {
                        // if we are in radar jammer's range or in sun wind jam range, then we detect only friends
                        if (IsNearRadarJammerOrSunWind() && obj is MyEntity && (MyFactions.GetFactionsRelation(GetOwner().Faction, ((MyEntity)obj).Faction) == MyFactionRelationEnum.Enemy))
                        {
                            continue;
                        }

                        //activeDetector.IsDetected(GetRadarPosition(), objectToDetect)
                        if (!CanBeDetected(obj))
                        {
                            continue;
                        }

                        BoundingSphere detectingSphere = new BoundingSphere(GetOwner().GetPosition(), DefaultRadarRange);
                        if (!detectingSphere.Intersects(obj.WorldAABB))
                        {
                            continue;
                        }

                        m_detectedObjectsHelperCollection.Add(obj);
                    }
                    m_objectsToDetect.Clear();
                }
            }
        }
Esempio n. 6
0
        public static bool CanBuild(MyPrefabContainer prefabContainer, params object[] args)
        {
            MySmallShip smallShip = GetSmallShipFromArguments(args);

            return((MyFactions.GetFactionsRelation(smallShip, prefabContainer) == MyFactionRelationEnum.Friend) &&
                   prefabContainer.ContainsPrefab(PrefabTypesFlagEnum.FoundationFactory) &&
                   ControlIsInPlayerShip());
        }
Esempio n. 7
0
        public static bool IsNearMothership(MyPrefabHangar prefabHangar, params object[] args)
        {
            MySmallShip smallShip = GetSmallShipFromArguments(args);

            return((prefabHangar.PrefabHangarType == MyMwcObjectBuilder_PrefabHangar_TypesEnum.HANGAR &&
                    MyFactions.GetFactionsRelation(smallShip, prefabHangar) == MyFactionRelationEnum.Friend) &&
                   IsTargetVisible(smallShip, prefabHangar) &&
                   ControlIsInPlayerShip());
        }
Esempio n. 8
0
        public float GetDeviatedAngleFromDamageRatio()
        {
            MyEntity topMostParent = GetTopMostParent();

            if (MySession.PlayerShip != null &&
                MyFactions.GetFactionsRelation(topMostParent, MySession.PlayerShip) == MyFactionRelationEnum.Enemy)
            {
                float degrees = (float)Math.Pow(120, topMostParent.GetDamageRatio() * 1.5 - 1.2) * 4f;
                return(MathHelper.ToRadians(degrees));
            }
            return(0f);
        }
        protected float GetDeviatedAngleByDamageRatio()
        {
            MyPrefabLargeWeapon prefabLargeWeapon = GetWeaponBase().PrefabParent;

            if (MySession.PlayerShip != null &&
                MyFactions.GetFactionsRelation(prefabLargeWeapon, MySession.PlayerShip) == MyFactionRelationEnum.Enemy)
            {
                float degrees = (float)Math.Pow(120, prefabLargeWeapon.GetDamageRatio() * 1.5 - 1.2) * 4f;
                return(MathHelper.ToRadians(degrees));
            }
            return(0f);
        }
Esempio n. 10
0
        private bool IsPotentialTarget(MySmallShip smallShip, params object[] args)
        {
            if (MyFactions.GetFactionsRelation(GetOwner(), smallShip) != MyFactionRelationEnum.Enemy)
            {
                return(false);
            }

            if (smallShip == MySession.PlayerShip && (Vector3.DistanceSquared(smallShip.GetPosition(), this.GetPosition()) > MyGameplayConstants.GameplayDifficultyProfile.LargeWeaponMaxAttackingDistanceForPlayer * MyGameplayConstants.GameplayDifficultyProfile.LargeWeaponMaxAttackingDistanceForPlayer))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
        public void Notify(BoundingBox bbox, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            results.Clear();
            m_dangerZoneStructure.OverlapAllBoundingBox <MyDangerZoneElement>(ref bbox, results);

            foreach (var dangerZone in results)
            {
                if (source == null || (dangerZone.Bot != source && MyFactions.GetFactionsRelation(dangerZone.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    dangerZone.Bot.AddCuriousLocation(source != null ? source.GetPosition() : bbox.GetCenter(), source);
                }
            }
        }
Esempio n. 12
0
        public void Notify(MyLine line, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            lineResults.Clear();
            m_dangerZoneStructure.OverlapAllLineSegment <MyDangerZoneElement>(ref line, lineResults);

            foreach (var resultItem in lineResults)
            {
                if (source == null || (resultItem.Element.Bot != source && MyFactions.GetFactionsRelation(resultItem.Element.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    resultItem.Element.Bot.AddCuriousLocation(source != null ? source.GetPosition() : line.From, source);
                }
            }
        }
        private Vector3 GetTargetPositionByDamageRatio(MySmallShipBot bot)
        {
            Vector3 targetPos = m_target.GetPosition();

            if (MySession.PlayerShip != null && MyFactions.GetFactionsRelation(bot, MySession.PlayerShip) == MyFactionRelationEnum.Enemy)
            {
                Vector3 botPos         = bot.GetPosition();
                Vector3 botToTarget    = targetPos - botPos;
                Vector3 dir            = Vector3.Normalize(botToTarget);
                float   degrees        = (float)Math.Pow(120, bot.GetDamageRatio() * 1.5 - 1.2) * 4f;
                float   deviatingAngle = MathHelper.ToRadians(degrees);
                dir       = MyUtilRandomVector3ByDeviatingVector.GetRandom(dir, deviatingAngle);
                targetPos = botPos + botToTarget.Length() * dir * 3;
            }
            return(targetPos);
        }
Esempio n. 14
0
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (damageSource != null && damageSource == MySession.PlayerShip)
            {
                var factionRelation = MyFactions.GetFactionsRelation(damageSource.Faction, Faction);
                if ((factionRelation == MyFactionRelationEnum.Friend || factionRelation == MyFactionRelationEnum.Neutral) &&
                    !MyGuiScreenGamePlay.Static.IsCheatEnabled(MyGameplayCheatsEnum.FRIEND_NEUTRAL_CANT_DIE) &&
                    !MyFakes.INDESTRUCTIBLE_PREFABS)
                {
                    MySession.PlayerShip.AddFriendlyFireDamage(this, damage);
                    return;
                }
            }

            base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
        }
Esempio n. 15
0
        /// <summary>
        /// Prepares the hologram ship for display.
        /// </summary>
        private void ActivateHologram()
        {
            //this.Physics.Enabled = false;
            //this.Physics.LinearVelocity = Vector3.Zero;

            MyEntity owner = OwnerEntity;

            if (owner != null)
            {
                var ownerShipBuilder = (owner.GetObjectBuilder(false) as MyMwcObjectBuilder_SmallShip);
                Debug.Assert(ownerShipBuilder != null, "ownerShipBuilder != null");

                m_hologramBuilder.ShipType                = ownerShipBuilder.ShipType;
                m_hologramBuilder.ShipMaxHealth           = ownerShipBuilder.ShipMaxHealth;
                m_hologramBuilder.ShipHealthRatio         = ownerShipBuilder.ShipHealthRatio;
                m_hologramBuilder.ArmorHealth             = ownerShipBuilder.ArmorHealth;
                m_hologramBuilder.Oxygen                  = ownerShipBuilder.Oxygen;
                m_hologramBuilder.Fuel                    = ownerShipBuilder.Fuel;
                m_hologramBuilder.ReflectorLight          = ownerShipBuilder.ReflectorLight;
                m_hologramBuilder.ReflectorLongRange      = ownerShipBuilder.ReflectorLongRange;
                m_hologramBuilder.ReflectorShadowDistance = ownerShipBuilder.ReflectorShadowDistance;
                m_hologramBuilder.PositionAndOrientation  = ownerShipBuilder.PositionAndOrientation;
                m_hologramBuilder.Faction                 = ownerShipBuilder.Faction;

                string displayName = ownerShipBuilder.DisplayName;
                if (MyFactions.GetFactionsRelation(m_hologramBuilder.Faction, MySession.Static.Player.Faction) == MyFactionRelationEnum.Friend || MySession.PlayerShip == owner)
                {
                    displayName = "Hologram";
                }

                m_hologramShip            = MyHologramShips.Add(displayName, m_hologramBuilder);
                m_hologramShip.AIPriority = 1;
                m_hologramShip.IsHologram = true;
                if (m_hologramShip != null)
                {
                    m_hologramBaseMatrix = this.WorldMatrix;

                    m_scale         = new Vector3(0, 1, 1);
                    m_hologramState = HologramState.Activating;

                    foreach (var bot in m_awareBots)
                    {
                        bot.SpoilHologram(m_hologramShip);
                    }
                }
            }
        }
Esempio n. 16
0
        public static void MakeEnemy(MyMwcObjectBuilder_FactionEnum shipFaction)
        {
            // Order bots to kill player
            foreach (var bot in MyBotCoordinator.GetBots())
            {
                var relation = MyFactions.GetFactionsRelation(shipFaction, bot.Faction);
                if (relation == MyFactionRelationEnum.Friend || relation == MyFactionRelationEnum.Neutral)
                {
                    bot.Attack(MySession.PlayerShip);
                }
            }

            MyScriptWrapper.SetPlayerFaction(MyMwcObjectBuilder_FactionEnum.Freelancers);


            MyMissions.DisableSaveObjectives();
        }
Esempio n. 17
0
        public void NotifyExplosion(Vector3 position, float radius, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            BoundingBox bbox = new BoundingBox(position - new Vector3(radius + EXTRA_EXPLOSION_RADIUS), position + new Vector3(radius + EXTRA_EXPLOSION_RADIUS));

            results.Clear();
            m_dangerZoneStructure.OverlapAllBoundingBox <MyDangerZoneElement>(ref bbox, results);

            foreach (var dangerZone in results)
            {
                if (source == null || (dangerZone.Bot != source && MyFactions.GetFactionsRelation(dangerZone.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    dangerZone.Bot.AddCuriousLocation(position, null);
                }
            }
        }
        void detector_OnEntityLeave(MyEntityDetector sender, MyEntity entity)
        {
            //MySpawnPoint spawnPoint = (MySpawnPoint)MyScriptWrapper.GetEntity((uint)EntityID.PatrolSpawnPoint);

            MyDummyPoint dummy = (MyDummyPoint)sender.Parent;


            if (MyFactions.GetFactionsRelation(dummy, entity) == MyFactionRelationEnum.Friend)
            {
            }


            uint            scannerId = (uint)dummy.Tag;
            MyPrefabScanner scanner   = (MyPrefabScanner)MyScriptWrapper.GetEntity(scannerId);

            scanner.Enabled = true;
        }
Esempio n. 19
0
        protected override bool IsObjectMeetDetectCriterium(IMyObjectToDetect objectToDetect)
        {
            MyEntity entity = objectToDetect as MyEntity;

            // TODO: temporary disable displaying mission entities on radar

            /*// we detect all mission entities
             * if(MyMissions.IsMissionEntity(entity))
             * {
             *  return true;
             * }
             * // we detect all friendly ship, foundation factories and hangars
             * else */if (entity is MyShip || entity is MyPrefabFoundationFactory || entity is MyPrefabHangar)
            {
                return(MyFactions.GetFactionsRelation(m_ship, entity) == MyFactionRelationEnum.Friend);
            }
            return(false);
        }
Esempio n. 20
0
        protected override void SetHudMarker()
        {
            MyHudIndicatorFlagsEnum hudFlags      = MyHudIndicatorFlagsEnum.SHOW_TEXT | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_HEALTH_BARS | MyHudIndicatorFlagsEnum.SHOW_DISTANCE | MyHudIndicatorFlagsEnum.SHOW_MISSION_MARKER;
            MyGuitargetMode?        guiTargetMode = MyGuitargetMode.Neutral;

            if (PrefabHangarType == MyMwcObjectBuilder_PrefabHangar_TypesEnum.HANGAR &&
                MyFactions.GetFactionsRelation(this.m_owner, MySession.PlayerShip) == MyFactionRelationEnum.Friend)
            {
                guiTargetMode = MyGuitargetMode.Friend;
            }
            else
            {
                hudFlags |= MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR | MyHudIndicatorFlagsEnum.ALPHA_CORRECTION_BY_DISTANCE;
            }


            MyHud.ChangeText(this, new StringBuilder(GetCorrectDisplayName()), guiTargetMode, 0, hudFlags);
        }
Esempio n. 21
0
        private static bool CanShout(IMyObjectToDetect detectedObject)
        {
            MyEntity detectedEntity = detectedObject as MyEntity;

            if (detectedEntity != null)
            {
                MyFactionRelationEnum factionRelation = MyFactions.GetFactionsRelation(MySession.PlayerShip, detectedEntity);
                if (detectedEntity is MySmallShipBot && factionRelation != MyFactionRelationEnum.Friend)
                {
                    MySmallShipBot bot = detectedEntity as MySmallShipBot;
                    return(!bot.IsParked() && !bot.IsPilotDead());
                }
                if (detectedEntity is MyPrefabLargeWeapon && factionRelation == MyFactionRelationEnum.Enemy)
                {
                    MyPrefabLargeWeapon largeWeapon = detectedEntity as MyPrefabLargeWeapon;
                    return(largeWeapon.IsWorking());
                }
            }
            return(false);
        }
Esempio n. 22
0
        protected override void OnContactStart(MyContactEventInfo contactInfo)
        {
            base.OnContactStart(contactInfo);

            if (m_state == MyCurrentState.ACTIVATED)
            {
                m_collidedEntity = contactInfo.GetOtherEntity(this);

                if (m_collidedEntity is MySmallShip && MyFactions.GetFactionsRelation(this, m_collidedEntity) == MyFactionRelationEnum.Enemy)
                {
                    if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && m_collidedEntity is MyStaticAsteroid && !m_collidedEntity.IsDestructible)
                    {
                        HUD.MyHud.ShowIndestructableAsteroidNotification();
                    }

                    //  Create explosion and close;
                    Explode();
                }
            }
        }
        public override void Load(MyMissionBase sender)
        {
            base.Load(sender);
            m_spawnPoints.Clear();

            if (m_spawnPointIDs == null)
            {   //Add all spawnpoints in mission
                List <uint> list = new List <uint>();
                foreach (MyEntity entity in MyEntities.GetEntities())
                {
                    MySpawnPoint spawnPoint = entity as MySpawnPoint;
                    if (spawnPoint != null && MyFactions.GetFactionsRelation(MySession.PlayerShip.Faction, spawnPoint.Faction) == MyFactionRelationEnum.Enemy && !m_excludedSpawnPointIDs.Contains(spawnPoint.EntityId.Value.NumericValue))
                    {
                        list.Add(spawnPoint.EntityId.Value.NumericValue);
                        spawnPoint.OnActivatedChanged += new Action <MySpawnPoint>(spawnPoint_OnActivatedChanged);
                    }
                }
                m_spawnPointIDs = list.ToArray();
            }

            foreach (uint spawnPointID in m_spawnPointIDs)
            {
                m_spawnPoints.Add(MyEntities.GetEntityById(new MyEntityIdentifier(spawnPointID)) as MySpawnPoint);
            }

            MyScriptWrapper.OnSpawnpointBotSpawned += OnSpawnpointBotSpawned;

            m_currentBotsCount = 0;

            foreach (MySpawnPoint spawnPoint in m_spawnPoints)
            {
                spawnPoint.LeftToSpawn     = 0;
                spawnPoint.FirstSpawnTimer = 0;
                spawnPoint.RespawnTimer    = 0;

                m_currentBotsCount += spawnPoint.GetShipCount();
                spawnPoint.Deactivate();
            }

            UpdateCurrentBotCount();
        }
Esempio n. 24
0
        private void SetTransparentParameters(out Vector4 color, out MyTransparentMaterialEnum?faceMaterial, out MyTransparentMaterialEnum?lineMaterial)
        {
            if (Game.Editor.MyEditor.Static.IsActive())
            {
                faceMaterial = MyTransparentMaterialEnum.ObjectiveDummyFace;
                lineMaterial = MyTransparentMaterialEnum.ObjectiveDummyLine;
            }
            else
            {
                faceMaterial = null;
                lineMaterial = null;
            }

            if (MyMissions.IsMissionEntity(this))
            {
                color = MyHudConstants.MISSION_CUBE_COLOR;
            }
            else
            {
                MyFactionRelationEnum status = MyFactions.GetFactionsRelation(this, MySession.PlayerShip);
                switch (status)
                {
                case MyFactionRelationEnum.Friend:
                    color = MyHudConstants.FRIEND_CUBE_COLOR;
                    break;

                case MyFactionRelationEnum.Enemy:
                    color = MyHudConstants.ENEMY_CUBE_COLOR;
                    break;

                case MyFactionRelationEnum.Neutral:
                    color = MyHudConstants.NEUTRAL_CUBE_COLOR;
                    break;

                default:
                    throw new MyMwcExceptionApplicationShouldNotGetHere();
                }
            }
        }
Esempio n. 25
0
        public static bool CanTradeForFree(MyEntity entityToTrade, params object[] args)
        {
            if (!ControlIsInPlayerShip() || IsBlocked(entityToTrade, args))
            {
                return(false);
            }

            // temporary disabled trading for free with smallships
            bool hasRightType = /*(entityToTrade is MySmallShip) || */ (entityToTrade is MyPrefabHangar || entityToTrade is MyDrone);

            if (!hasRightType)
            {
                return(false);
            }

            MySmallShip           smallShip       = GetSmallShipFromArguments(args);
            MyFactionRelationEnum factionRelation = MyFactions.GetFactionsRelation(entityToTrade, smallShip);

            if (entityToTrade is MyPrefabHangar)
            {
                MyPrefabHangar prefabHangar = entityToTrade as MyPrefabHangar;
                return(prefabHangar.PrefabHangarType == MyMwcObjectBuilder_PrefabHangar_TypesEnum.HANGAR &&
                       factionRelation == MyFactionRelationEnum.Friend &&
                       prefabHangar.IsWorking() && IsTargetVisible(smallShip, prefabHangar));
            }
            else if (entityToTrade is MyDrone)
            {
                return(factionRelation == MyFactionRelationEnum.Friend &&
                       !IsShipLootable(entityToTrade as MySmallShip) &&
                       IsCustomLookAtTarget(smallShip, entityToTrade, entityToTrade.WorldVolume.Radius * 1.0f));
            }
            else
            {
                return(factionRelation == MyFactionRelationEnum.Friend &&
                       !IsShipLootable(entityToTrade as MySmallShip) &&
                       IsLookAtTarget(smallShip, entityToTrade));
            }
        }
Esempio n. 26
0
 public void SendToTeam <T>(ref T multiplayerEvent, MyMwcObjectBuilder_FactionEnum senderFaction, NetDeliveryMethod delivery = NetDeliveryMethod.Unreliable, int sequenceChannel = 0, int maxSize = 512)
     where T : struct, IMyEvent
 {
     m_playerConnections.Clear();
     foreach (var p in Players)
     {
         var connection = p.Connection;
         if (connection != null && MyFactions.GetFactionsRelation(p.Faction, senderFaction) == MyFactionRelationEnum.Friend)
         {
             if (connection is MyRelayedConnection)
             {
                 m_peer.Send(ref multiplayerEvent, connection, delivery, sequenceChannel, maxSize);
             }
             else
             {
                 m_playerConnections.Add(connection);
             }
         }
     }
     if (m_playerConnections.Count > 0)
     {
         m_peer.SendToAll(ref multiplayerEvent, m_playerConnections, delivery, sequenceChannel);
     }
 }
Esempio n. 27
0
        public static bool CanBeScannedCriterium(MyEntity entity, params object[] args)
        {
            MyPrefabScanningPartBase scanningPart = args[0] as MyPrefabScanningPartBase;

            return(entity is MySmallShip && MyFactions.GetFactionsRelation(scanningPart.GetScanner(), entity) == MyFactionRelationEnum.Enemy);
        }
Esempio n. 28
0
 public bool CanBeHacked(MySmallShip hackedBy)
 {
     return(IsWorking() && (MyFactions.GetFactionsRelation(hackedBy, this) == MyFactionRelationEnum.Neutral ||
                            MyFactions.GetFactionsRelation(hackedBy, this) == MyFactionRelationEnum.Enemy));
 }
Esempio n. 29
0
 public bool CanBeUsed(MySmallShip usedBy)
 {
     return(IsWorking() && (MyFactions.GetFactionsRelation(usedBy, this) == MyFactionRelationEnum.Friend || UseProperties.IsHacked));
 }
        public void DoWork()
        {
            //  Search for target to attack
            ClosestEnemy  = null;
            ClosestVisual = null;

            float distanceSqr              = m_seeDistance * m_seeDistance;
            float closestEnemyDistanceSqr  = float.PositiveInfinity;
            float closestVisualDistanceSqr = float.PositiveInfinity;

            using (var rbFounded = PoolList <MyRBElement> .Get())
            {
                try
                {
                    MyEntities.EntityCloseLock.AcquireShared();

                    MyDynamicAABBTree prunningStructure = MyPhysics.physicsSystem.GetRigidBodyModule().GetPruningStructure();

                    BoundingBox rbInputElementGetWorldSpaceAABB = new BoundingBox(
                        m_botWorldMatrix.Translation - new Vector3(m_seeDistance),
                        m_botWorldMatrix.Translation + new Vector3(m_seeDistance));
                    prunningStructure.OverlapAllBoundingBox(ref rbInputElementGetWorldSpaceAABB, rbFounded, (uint)MyElementFlag.EF_RB_ELEMENT);

                    //now try find spot
                    foreach (MyRBElement rb in rbFounded)
                    {
                        if (m_bot == null)
                        {
                            return;
                        }

                        var rigidBody = rb.GetRigidBody();
                        if (rigidBody == null)
                        {
                            continue;
                        }

                        MyEntity entity = ((MyPhysicsBody)rigidBody.m_UserData).Entity;
                        if (entity == m_bot || entity == null || entity.AIPriority == -1)
                        {
                            continue;
                        }


                        entity = entity.GetBaseEntity();    // Large weapons

                        // Ignore spoiled holograms
                        if (m_bot.IsSpoiledHologram(entity))
                        {
                            continue;
                        }

                        // Don't attack disabled weapons
                        MyPrefabLargeWeapon largeWeapon = entity as MyPrefabLargeWeapon;
                        MySmallShip         smallShip   = entity as MySmallShip;
                        MyPrefabLargeShip   largeShip   = entity as MyPrefabLargeShip;

                        if (largeWeapon != null && !largeWeapon.IsWorking())
                        {
                            continue;
                        }

                        // Test smallships and largeweapons
                        if (smallShip != null || largeWeapon != null || largeShip != null)
                        {
                            // Is enemy?
                            if (MyFactions.GetFactionsRelation(m_bot, entity) == MyFactionRelationEnum.Enemy && CanSeeTarget(m_bot, entity))
                            {
                                var entityDistanceSqr = Vector3.DistanceSquared(entity.GetPosition(), m_position);

                                if (entityDistanceSqr < distanceSqr &&
                                    (ClosestEnemy == null || entity.AIPriority >= ClosestEnemy.AIPriority) &&
                                    (entityDistanceSqr < closestEnemyDistanceSqr || entity.AIPriority > ClosestEnemy.AIPriority))
                                {
                                    MyLine line   = new MyLine(m_position, entity.GetPosition(), true);
                                    var    result = MyEntities.GetIntersectionWithLine(ref line, m_bot, entity, true, ignoreChilds: true);
                                    if (!result.HasValue)
                                    {
                                        // Visual Detection - ignore visualy detected targets if they are further than any normaly detected target
                                        if (IsVisualyDetected(smallShip))
                                        {
                                            if (entityDistanceSqr < closestVisualDistanceSqr)
                                            {
                                                ClosestVisual            = entity;
                                                closestVisualDistanceSqr = entityDistanceSqr;
                                            }
                                        }
                                        else
                                        {
                                            closestEnemyDistanceSqr = entityDistanceSqr;
                                            ClosestEnemy            = entity;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    MyEntities.EntityCloseLock.ReleaseShared();
                }
            }
        }