Example #1
0
        private static bool CheckRevealMedbay(IMyCubeGrid grid, ulong steamId)
        {
            // Live dangerously
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks, x => x.FatBlock != null);
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                    //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                    if (medical.HasPlayerAccess(playerId))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static Dictionary <string, List <IMyCubeBlock> > GetZonesInGrid(IMyCubeGrid cubeGrid)
        {
            Dictionary <String, List <IMyCubeBlock> > testList = new Dictionary <string, List <IMyCubeBlock> >();
            List <IMySlimBlock> cubeBlocks = new List <IMySlimBlock>();

            cubeGrid.GetBlocks(cubeBlocks);
            foreach (IMySlimBlock entityBlock in cubeBlocks)
            {
                if (entityBlock.FatBlock == null)
                {
                    continue;
                }

                if (!(entityBlock.FatBlock is IMyCubeBlock))
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = (IMyCubeBlock)entityBlock.FatBlock;

                if (!(cubeBlock is IMyBeacon))
                {
                    continue;
                }

                IMyBeacon beacon = (IMyBeacon)cubeBlock;
                if (beacon.CustomName == null || beacon.CustomName == "")
                {
                    continue;
                }

                if (testList.ContainsKey(beacon.CustomName))
                {
                    testList[beacon.CustomName].Add(entityBlock.FatBlock);
                }
                else
                {
                    List <IMyCubeBlock> testBeaconList = new List <IMyCubeBlock>();
                    testBeaconList.Add(entityBlock.FatBlock);
                    testList.Add(beacon.CustomName, testBeaconList);
                }
            }

            Dictionary <String, List <IMyCubeBlock> > resultList = new Dictionary <string, List <IMyCubeBlock> >();

            foreach (KeyValuePair <String, List <IMyCubeBlock> > p in testList)
            {
                if (p.Value.Count == 4)
                {
                    resultList.Add(p.Key, p.Value);
                }
            }

            return(resultList);
        }
		public static Dictionary<string, List<IMyCubeBlock>> GetZonesInGrid(IMyCubeGrid cubeGrid)
		{
			Dictionary<String, List<IMyCubeBlock>> testList = new Dictionary<string, List<IMyCubeBlock>>();
			List<IMySlimBlock> cubeBlocks = new List<IMySlimBlock>();
			cubeGrid.GetBlocks(cubeBlocks);
			foreach (IMySlimBlock entityBlock in cubeBlocks)
			{
				if (entityBlock.FatBlock == null)
					continue;

				if (!(entityBlock.FatBlock is IMyCubeBlock))
					continue;

				IMyCubeBlock cubeBlock = (IMyCubeBlock)entityBlock.FatBlock;

				if (!(cubeBlock is IMyBeacon))
					continue;

				IMyBeacon beacon = (IMyBeacon)cubeBlock;
				if (beacon.CustomName == null || beacon.CustomName == "")
					continue;

				if (testList.ContainsKey(beacon.CustomName))
				{
					testList[beacon.CustomName].Add(entityBlock.FatBlock);
				}
				else
				{
					List<IMyCubeBlock> testBeaconList = new List<IMyCubeBlock>();
					testBeaconList.Add(entityBlock.FatBlock);
					testList.Add(beacon.CustomName, testBeaconList);
				}
			}

			Dictionary<String, List<IMyCubeBlock>> resultList = new Dictionary<string, List<IMyCubeBlock>>();
			foreach (KeyValuePair<String, List<IMyCubeBlock>> p in testList)
			{
				if (p.Value.Count == 4)
				{
					resultList.Add(p.Key, p.Value);
				}
			}

			return resultList;
		}
Example #4
0
        private List <Sandbox.ModAPI.IMySlimBlock> GetGateList()
        {
            HashSet <IMyEntity> hash = new HashSet <IMyEntity>();
            List <Sandbox.ModAPI.IMySlimBlock> gateList = new List <Sandbox.ModAPI.IMySlimBlock>();

            Sandbox.ModAPI.MyAPIGateway.Entities.GetEntities(hash, (x) => x is Sandbox.ModAPI.IMyCubeGrid);


            foreach (var entity in hash)
            {
                List <Sandbox.ModAPI.IMySlimBlock> blocks = new List <Sandbox.ModAPI.IMySlimBlock>();
                Sandbox.ModAPI.IMyCubeGrid         grid   = entity as Sandbox.ModAPI.IMyCubeGrid;

                try
                {
                    grid.GetBlocks(blocks, (x) => x.FatBlock is IMyDoor &&
                                   (x.FatBlock as IMyTerminalBlock).CustomName.Contains("Portal"));
                }
                catch
                {
                    MyAPIGateway.Utilities.ShowNotification("Error When trying to find Portals", 250);
                }


                foreach (var block in blocks)
                {
                    try
                    {
                        String name = (block.FatBlock as IMyTerminalBlock).CustomName;
                        gateList.Add(block);
                        //MyAPIGateway.Utilities.ShowNotification("Added Door,  Pos = " + block.FatBlock.Position.ToString() +
                        // " Name = " + name, 250);
                    }
                    catch
                    {
                        MyAPIGateway.Utilities.ShowNotification("Error", 250);
                    }
                }
            }


            return(gateList);
        }
Example #5
0
        /*
         * let me explain this stupid method....... nope, not much to explain because this is what I Had to do to get it to work.
         */
        private void FindWeapons()
        {
            if (Ship == null)
            {
                return;
            }


            _allWeapons.Clear();
            _allReactors.Clear();
            _manualGuns.Clear();
            _manualRockets.Clear();


            Ship.GetBlocks(_manualRockets, (x) => x.FatBlock != null && (x.FatBlock is IMySmallMissileLauncher));
            Ship.GetBlocks(_manualGuns, (x) => x.FatBlock != null && (x.FatBlock is IMySmallGatlingGun));

            Ship.GetBlocks(_allReactors, (x) => x.FatBlock != null && x.FatBlock is IMyReactor);
            Ship.GetBlocks(_allWeapons, (x) => x.FatBlock != null && (x.FatBlock is IMyUserControllableGun));
        }
Example #6
0
        private static bool CheckRevealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players, out string reason)
        {
            reason = "";
            // This is actually faster, but doesn't include power checks

            // Live dangerously
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);
            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    //Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //	continue;


                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to beacon broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to antenna broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    if (!functionalBlock.IsFunctional)
                    {
                        continue;
                    }

                    //if (!functionalBlock.Enabled)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                                //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                                if (functionalBlock.OwnerId == playerId)
                                {
                                    reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                                    return(true);
                                }

                                if (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare)
                                {
                                    reason = string.Format("Grid has medbay and player is factionshare - playerid: {0}", playerId);
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      //if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        reason = string.Format("Grid has medbay and conceal can not include medbays");
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ProductionBlock))
                {
                    MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;
                    if (production.Queue.Length > 0)
                    {
                        reason = string.Format("Grid has production facility that has a queue");
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #7
0
        private static bool CheckConcealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            // Live dangerously
            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);

            int beaconCount = 0;

            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    beaconCount++;
                    // Keep this return here, as 4 beacons always means true
                    if (beaconCount >= 4)
                    {
                        return(true);
                    }

                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
//					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //{
//						continue;
                    //}

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
//								Console.WriteLine("Not concealed due to broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
//								Console.WriteLine("Not concealed due to antenna broadcast radius");
                                //found = true;
                                //break;
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;

                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    //if (!terminalBlock.IsWorking)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                                //continue;

                                //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);

                                if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare))
                                //if (functionalBlock.Owner == playerId || (functionalBlock.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(functionalBlock.Owner, playerId)))
                                //if (medical.HasPlayerAccess(playerId))
                                {
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      //if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
                         *              //continue;
                         *
                         *      //long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) || cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler))
                {
                    //MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyProductionBlock production = (IMyProductionBlock)cubeBlock;
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    if (production.IsProducing)
                    {
                        return(true);
                    }
                }

                foreach (string subType in PluginSettings.Instance.DynamicConcealIgnoreSubTypeList)
                {
                    if (cubeBlock.BlockDefinition.SubtypeName.Contains(subType))
                    {
//						Console.WriteLine("Not concealed due subtype");
                        //found = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #8
0
        //target key points on an enemy ship to disable them
        private bool FindTargetKeyPoint(IMyCubeGrid grid, Vector3D velocity)
        {
            //get position, get lenier velocity in each direction
            //add them like 10 times and add that to current coord
                if (grid != null)
                {
                    IMyGridTerminalSystem gridTerminal =
                        MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                    List<IMyTerminalBlock> reactorsTarget =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<IMyPowerProducer>(reactorsTarget);

                    List<IMyTerminalBlock> cockpitsTarget =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<IMyCockpit>(cockpitsTarget);

                    List<IMyTerminalBlock> allBlocksTarget =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<Sandbox.ModAPI.IMyTerminalBlock>(allBlocksTarget);

                    List<IMyTerminalBlock> missileLuanchersTarget =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<IMyMissileGunObject>(missileLuanchersTarget);

                    List<IMyTerminalBlock> batteriesTarget =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<IMyBatteryBlock>(batteriesTarget);

                    List<IMyTerminalBlock> mergeBlocks =
                        new List<IMyTerminalBlock>();
                    gridTerminal.GetBlocksOfType<IMyShipMergeBlock>(mergeBlocks);

                    MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_target);
                    List<IMySlimBlock> weaponsTarget = new List<IMySlimBlock>();

                    grid.GetBlocks(weaponsTarget,
                        (x) => x.FatBlock != null && x.FatBlock is IMyUserControllableGun);
                    //now that we have a list of reactors and guns lets primary one.
                    //try to find a working gun, if none are found then find a reactor to attack

                    //guns, rockets, cockpits,reactors,batteries
                    foreach (var merge in mergeBlocks.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (merge != null)
                        {
                            var item = ((IMyCubeBlock)merge);
                            if (item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                    foreach (var weapon in weaponsTarget.OrderBy(x=>(x.FatBlock.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (weapon != null)
                        {
                            var item = (weapon.FatBlock);

                            if (item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                    foreach (var missile in missileLuanchersTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (missile != null)
                        {
                            var item = ((IMyCubeBlock) missile);
                            if (item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                    foreach (var reactor in reactorsTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (reactor != null)
                        {
                            var item = ((IMyCubeBlock)reactor);
                            if (item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                    foreach (var battery in batteriesTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (battery != null)
                        {
                            var item = ((IMyCubeBlock)battery);
                            if ( item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                    foreach (var c*k in cockpitsTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                    {
                        if (c*k != null)
                        {
                            var item = ((IMyCubeBlock)c*k);
                            if (item.IsFunctional)
                            {
                                OrbitAttackTarget(item.GetPosition(), velocity);
                                return true;
                            }
                        }
                    }
                }
            return false;
        }
		private static bool CheckRevealMedbay( IMyCubeGrid grid, ulong steamId )
		{
			// Live dangerously
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );
			grid.GetBlocks( blocks, x => x.FatBlock != null );
                        long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( steamId );
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
                {
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
                    if ( !medical.Enabled )
                        continue;

                    //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                    if ( medical.HasPlayerAccess( playerId ) )
                    {
                        return true;
                    }
                }

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_CryoChamber ) )
                {
                    MyCryoChamber cryo = (MyCryoChamber)cubeBlock;
                    if ( cryo.Pilot == null )
                        continue;

                    if ( cryo.HasPlayerAccess( playerId ) )
                    {
                        return true;
                    }
                }
            }

            return false;
		}
		private static bool CheckRevealBlockRules( IMyCubeGrid grid, List<IMyPlayer> players, out string reason )
		{
			reason = "";
			// This is actually faster, but doesn't include power checks

			// Live dangerously
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );
			grid.GetBlocks( blocks, x => x.FatBlock != null );
			//CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);
			//bool found = false;
			//bool powered = false;
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Beacon ) )
				{
					//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
					IMyBeacon beacon = (IMyBeacon)cubeBlock;
					if ( !beacon.Enabled )
						continue;

					//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
					//if (!functionalBlock.Enabled)
					//	continue;

					//Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
					//if (!terminalBlock.IsWorking)
					//	continue;


					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < beacon.Radius )
							{
								//found = true;
								//break;
								reason = string.Format( "{0} distance to beacon broadcast: {1}", player.DisplayName, distance );
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_RadioAntenna ) )
				{
					//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
					IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

					if ( !antenna.Enabled )
						continue;

					//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
					//if (!functionalBlock.Enabled)
					//	continue;

					foreach ( IMyPlayer player in players )
					{
						double distance = 0d;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < antenna.Radius )
							{
								//found = true;
								//break;
								reason = string.Format( "{0} distance to antenna broadcast: {1}", player.DisplayName, distance );
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
				{
					//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
					IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
					if ( !medical.Enabled )
						continue;

					IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
					if ( !functionalBlock.IsFunctional )
						continue;

					//if (!functionalBlock.Enabled)
					//	continue;

					if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
					{
						lock ( Online )
						{
							foreach ( ulong connectedPlayer in Online )
							{
								long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );
								//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
								if ( functionalBlock.OwnerId == playerId )
								{
									reason = string.Format( "Grid has medbay and player is logged in - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }

								if ( functionalBlock.GetUserRelationToOwner( playerId ) == MyRelationsBetweenPlayerAndBlock.FactionShare )
								{
									reason = string.Format( "Grid has medbay and player is factionshare - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }
							}
						}

                        /*
						foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
						{
							long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
							//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
							//if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare))
							if(medical.HasPlayerAccess(playerId))
							{
								reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
								return true;
							}
						}
						 */
                    }
					else
					{
						reason = string.Format( "Grid has medbay and conceal can not include medbays" );
                        //return true;

                        //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                        RevealMedbays( (IMyEntity)grid, reason );
                        //return false so this grid doesn't get duplicated in the regular queue
                        return false;
                    }
                }

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_CryoChamber) )
                {
                        MyCryoChamber cryo = (MyCryoChamber)cubeBlock;
                        if ( cryo.Pilot == null )
                            continue;
                        
                    if ( !cryo.IsFunctional )
                        continue;                    

                    if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
                    {
                        lock ( Online )
                        {
                            foreach ( ulong connectedPlayer in Online )
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );
                                IMyPlayer cryoUser = (IMyPlayer) cryo.Pilot;

                                if ( cryoUser.PlayerID == playerId )
                                {
                                    reason = string.Format( "Grid has cryopod and player is inside - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }

                                if ( cryo.HasPlayerAccess( playerId ) )
                                {
                                    reason = string.Format( "Grid has cryopod and player can use - playerid: {0}", playerId );
                                    //return true;

                                    //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                                    RevealMedbays( (IMyEntity)grid, reason );
                                    //return false so this grid doesn't get duplicated in the regular queue
                                    return false;
                                }
                            }
                        }
                    }
                    else
                    {
                        reason = string.Format( "Grid has cryopod and conceal can not include cryopods" );
                        //return true;

                        //medbay is up for reveal, put it into the medbay queue to be revealed before other grids
                        RevealMedbays( (IMyEntity)grid, reason );
                        //return false so this grid doesn't get duplicated in the regular queue
                        return false;
                    }
                }

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_ProductionBlock ) )
				{
					MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock( );
					if ( !production.Enabled )
						continue;

					IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;
					if ( production.Queue.Length > 0 )
					{
						reason = string.Format( "Grid has production facility that has a queue" );
						return true;
					}
				}
			}

			return false;
		}
		private static bool CheckConcealForce( IMyCubeGrid grid, ulong steamId )
		{
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );

			// Live dangerously
			grid.GetBlocks( blocks, x => x.FatBlock != null );
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
				{
					MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock( );

					if ( !medical.Enabled )
						continue;

					IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
					long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( steamId );
					if ( medical.Owner == playerId || ( medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction( medical.Owner, playerId ) ) )
					{
						return true;
					}
				}
			}

			return false;
		}
		private static bool CheckConcealBlockRules( IMyCubeGrid grid, List<IMyPlayer> players )
		{
			List<IMySlimBlock> blocks = new List<IMySlimBlock>( );            

			// Live dangerously
			grid.GetBlocks( blocks, x => x.FatBlock != null );
			//CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);

			int beaconCount = 0;
			//bool found = false;
			//bool powered = false;
			foreach ( IMySlimBlock block in blocks )
			{
				IMyCubeBlock cubeBlock = block.FatBlock;

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Beacon ) )
				{
					IMyBeacon beacon = (IMyBeacon)cubeBlock;
					//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
					beaconCount++;
					// Keep this return here, as 4 beacons always means true
					if ( beaconCount >= 4 )
					{
						return true;
					}

					if ( !beacon.Enabled )
						continue;

					IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
					//					Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
					//if (!terminalBlock.IsWorking)
					//{
					//						continue;
					//}

					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < beacon.Radius )
							{
								//								Console.WriteLine("Not concealed due to broadcast radius");
								//found = true;
								//break;
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_RadioAntenna ) )
				{
					//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
					IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

					if ( !antenna.Enabled )
						continue;

					IMyTerminalBlock terminalBlock = (IMyTerminalBlock)cubeBlock;
					//if (!terminalBlock.IsWorking)
					//	continue;

					foreach ( IMyPlayer player in players )
					{
						double distance;
						if ( Entity.GetDistanceBetweenPointAndPlayer( grid.GetPosition( ), player, out distance ) )
						{
							if ( distance < antenna.Radius )
							{
								//								Console.WriteLine("Not concealed due to antenna broadcast radius");
								//found = true;
								//break;
								return true;
							}
						}
					}
				}

				if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_MedicalRoom ) )
				{
					//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
					IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;

					if ( !medical.Enabled )
						continue;

					IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
					//if (!terminalBlock.IsWorking)
					//	continue;

					if ( PluginSettings.Instance.DynamicConcealIncludeMedBays )
					{
						lock ( Online )
						{
							foreach ( ulong connectedPlayer in Online )
							{
								//if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
								//continue;

								//long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
								long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer );

								if ( functionalBlock.OwnerId == playerId || ( functionalBlock.GetUserRelationToOwner( playerId ) == MyRelationsBetweenPlayerAndBlock.FactionShare ) )
								//if (functionalBlock.Owner == playerId || (functionalBlock.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(functionalBlock.Owner, playerId)))
								//if (medical.HasPlayerAccess(playerId))
								{
									return true;
								}
							}
						}

						/*
						foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
						{
							//if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
								//continue;

							//long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).First();
							long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
							//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
							if(medical.HasPlayerAccess(playerId))
							{
								return true;
							}
						}
						 */
					}
					else
					{
						return true;
					}
				}

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_CryoChamber ) )
                {
                    MyCryoChamber cryo = (MyCryoChamber)cubeBlock;
                    
                    if ( cryo.Pilot != null )
                        return true;
                }            

                if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Refinery ) || cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Assembler ) )
				{
					//MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
					IMyProductionBlock production = (IMyProductionBlock)cubeBlock;
					if ( !production.Enabled )
						continue;

					if ( production.IsProducing )
						return true;
				}

				foreach ( string subType in PluginSettings.Instance.DynamicConcealIgnoreSubTypeList )
				{
					if ( cubeBlock.BlockDefinition.SubtypeName.Contains( subType ) )
					{
						//						Console.WriteLine("Not concealed due subtype");
						//found = true;
						return true;
					}
				}
			}

			return false;
		}
Example #13
0
        //target key points on an enemy ship to disable them
        private bool FindTargetKeyPoint(IMyCubeGrid grid, Vector3D velocity)
        {
            //get position, get lenier velocity in each direction
            //add them like 10 times and add that to current coord
            if (grid != null)
            {
                IMyGridTerminalSystem gridTerminal =
                    MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                List <IMyTerminalBlock> reactorsTarget =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <IMyPowerProducer>(reactorsTarget);

                List <IMyTerminalBlock> cockpitsTarget =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <IMyCockpit>(cockpitsTarget);

                List <IMyTerminalBlock> allBlocksTarget =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <Sandbox.ModAPI.IMyTerminalBlock>(allBlocksTarget);

                List <IMyTerminalBlock> missileLuanchersTarget =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <IMyMissileGunObject>(missileLuanchersTarget);

                List <IMyTerminalBlock> batteriesTarget =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <IMyBatteryBlock>(batteriesTarget);

                List <IMyTerminalBlock> mergeBlocks =
                    new List <IMyTerminalBlock>();
                gridTerminal.GetBlocksOfType <IMyShipMergeBlock>(mergeBlocks);

                MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_target);
                List <IMySlimBlock> weaponsTarget = new List <IMySlimBlock>();

                grid.GetBlocks(weaponsTarget,
                               (x) => x.FatBlock != null && x.FatBlock is IMyUserControllableGun);
                //now that we have a list of reactors and guns lets primary one.
                //try to find a working gun, if none are found then find a reactor to attack

                //guns, rockets, cockpits,reactors,batteries
                foreach (var merge in mergeBlocks.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (merge != null)
                    {
                        var item = ((IMyCubeBlock)merge);
                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
                foreach (var weapon in weaponsTarget.OrderBy(x => (x.FatBlock.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (weapon != null)
                    {
                        var item = (weapon.FatBlock);

                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
                foreach (var missile in missileLuanchersTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (missile != null)
                    {
                        var item = ((IMyCubeBlock)missile);
                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
                foreach (var reactor in reactorsTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (reactor != null)
                    {
                        var item = ((IMyCubeBlock)reactor);
                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
                foreach (var battery in batteriesTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (battery != null)
                    {
                        var item = ((IMyCubeBlock)battery);
                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
                foreach (var c*k in cockpitsTarget.OrderBy(x => (x.GetPosition() - Ship.GetPosition()).Length()))
                {
                    if (c*k != null)
                    {
                        var item = ((IMyCubeBlock)c*k);
                        if (item.IsFunctional)
                        {
                            OrbitAttackTarget(item.GetPosition(), velocity);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        static public void FindByName(String pylonName, out Dictionary <String, List <IMyCubeBlock> > testList, out List <IMyCubeBlock> beaconList, long playerId)
        {
            IMyCubeGrid beaconParent = null;

            testList   = new Dictionary <string, List <IMyCubeBlock> >();
            beaconList = new List <IMyCubeBlock>();
            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            Wrapper.GameAction(() =>
            {
                MyAPIGateway.Entities.GetEntities(entities, null);
            });

            foreach (IMyEntity entity in entities)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                IMyCubeGrid cubeGrid = (IMyCubeGrid)entity;

                if (cubeGrid == null || cubeGrid.GridSizeEnum == MyCubeSize.Small)
                {
                    continue;
                }

                if (!cubeGrid.BigOwners.Contains(playerId) && !cubeGrid.SmallOwners.Contains(playerId))
                {
                    continue;
                }

                testList.Clear();
                beaconList.Clear();
                beaconParent = cubeGrid;

                List <IMySlimBlock> cubeBlocks = new List <IMySlimBlock>();
                cubeGrid.GetBlocks(cubeBlocks);
                foreach (IMySlimBlock entityBlock in cubeBlocks)
                {
                    if (entityBlock.FatBlock == null)
                    {
                        continue;
                    }

                    if (!(entityBlock.FatBlock is IMyCubeBlock))
                    {
                        continue;
                    }

                    IMyCubeBlock cubeBlock = (IMyCubeBlock)entityBlock.FatBlock;

                    if (!(cubeBlock is IMyBeacon))
                    {
                        continue;
                    }

                    IMyTerminalBlock beacon = (IMyTerminalBlock)cubeBlock;

                    /*
                     * MyObjectBuilder_CubeBlock blockObject;
                     * try
                     * {
                     *      blockObject = entityBlock.FatBlock.GetObjectBuilderCubeBlock();
                     *      if (blockObject == null)
                     *              continue;
                     * }
                     * catch
                     * {
                     *      continue;
                     * }
                     *
                     * if (!(blockObject is MyObjectBuilder_Beacon))
                     *      continue;
                     *
                     * MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)blockObject;
                     */

                    if (beacon.CustomName == null || beacon.CustomName == "")
                    {
                        continue;
                    }

                    if (beacon.IsFunctional &&
                        beacon.CustomName.ToLower() == pylonName.ToLower()
                        )
                    {
                        beaconList.Add(entityBlock.FatBlock);
                        Vector3D beaconPos = Entity.GetBlockEntityPosition(entityBlock.FatBlock);
                        continue;
                    }

                    if (testList.ContainsKey(beacon.CustomName))
                    {
                        testList[beacon.CustomName].Add(entityBlock.FatBlock);
                    }
                    else
                    {
                        List <IMyCubeBlock> testBeaconList = new List <IMyCubeBlock>();
                        testBeaconList.Add(entityBlock.FatBlock);
                        testList.Add(beacon.CustomName, testBeaconList);
                    }
                }

                if (beaconList.Count == 4)
                {
                    break;
                }
            }
        }