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); }
/// <summary> /// removes one waypoint or centreDestination of the specified type /// </summary> /// <param name="typeToRemove"></param> public void atWayDest(TypeOfWayDest typeToRemove) { onWayDestAddedRemoved(); switch (typeToRemove) { case TypeOfWayDest.BLOCK: case TypeOfWayDest.COORDINATES: case TypeOfWayDest.GRID: case TypeOfWayDest.OFFSET: case TypeOfWayDest.LAND: log("clearing destination variables", "atWayDest()", Logger.severity.TRACE); CurrentGridDest = null; coordDestination = null; destination_offset = Vector3.Zero; match_direction = null; match_roll = null; landLocalBlock = null; landDirection = null; jump_to_dest = false; ignoreAsteroids = false; SpecialFlyingInstructions = SpecialFlying.None; goto case TypeOfWayDest.WAYPOINT; case TypeOfWayDest.WAYPOINT: myWaypoint = null; return; default: log("unknown type " + typeToRemove, "atWayDest()", Logger.severity.ERROR); return; } }
void DoInit() { //MyLogger.Default.WriteLine("Got inside doinit"); if (_didInit) { return; } _didInit = true; if (Entity == null) { //MyLogger.Default.WriteLine("Block was null! bailin"); _didInit = false; return; } //MyLogger.Default.ToScreen = true; //MyLogger.Default.WriteLine("Initting a warhead"); block = (IMyCubeBlock)Entity; if (block.BlockDefinition.SubtypeName == SubTypeNameLarge) { //MyLogger.Default.WriteLine("Just Placed a breach charge"); block.OnMarkForClose += OnMarkForClose; } else { return; } }
/// <summary> /// gets the local postion relative to a block (including block orientation) /// </summary> public Vector3 getBlock(Sandbox.ModAPI.IMyCubeBlock cubeBlock) { cubeBlock.throwIfNull_argument("cubeBlock"); if (this.cubeBlock == cubeBlock) { return((Vector3)value__block); } Vector3 v3; MatrixD matrix; if (value__world != null || value__worldAbsolute != null) { v3 = getWorld(); matrix = cubeBlock.WorldMatrix; } else // assume we can get local //if (value__grid != null) { // create from local v3 = getLocal(); matrix = cubeBlock.LocalMatrix; } //else // assuming (world != null) Vector3 resultant = v3.Dot(matrix.Right) * Base6Directions.GetVector(Base6Directions.Direction.Right); resultant += v3.Dot(matrix.Up) * Base6Directions.GetVector(Base6Directions.Direction.Up); resultant += v3.Dot(matrix.Backward) * Base6Directions.GetVector(Base6Directions.Direction.Backward); return(resultant); }
internal GridDimensions(Sandbox.ModAPI.IMyCubeBlock RC) { this.myRC = RC; myLogger = new Logger(myGrid.DisplayName, "GridDimensions"); Vector3 start = new Vector3(), end = new Vector3(); Vector3[] allCorners = myGrid.LocalAABB.GetCorners(); bool firstCorner = true; foreach (Vector3 corner in allCorners) { // 0,0,0 may not be part of ship, so start with a corner if (firstCorner) { start = corner; end = corner; firstCorner = false; continue; } //log("\tcorner: " + corner.ToString()); if (corner.X > start.X) { start.X = corner.X; } else if (corner.X < end.X) { end.X = corner.X; } if (corner.Y > start.Y) { start.Y = corner.Y; } else if (corner.Y < end.Y) { end.Y = corner.Y; } if (corner.Z > start.Z) { start.Z = corner.Z; } else if (corner.Z < end.Z) { end.Z = corner.Z; } } log("ship bounds are " + end.X + ":" + start.X + ", " + end.Y + ":" + start.Y + ", " + end.Z + ":" + start.Z); centre_grid = myGrid.LocalAABB.Center; rc_pos_grid = myRC.Position * myGrid.GridSize; log("middle is " + centre_grid + ", RC is " + rc_pos_grid, "..ctor", Logger.severity.DEBUG); width = getDimension(myRC.Orientation.Left, start, end); height = getDimension(myRC.Orientation.Up, start, end); length = getDimension(myRC.Orientation.Forward, start, end); distance_to_front_from_centre = calcDistToEdge(myRC.Orientation.Forward, centre_grid, start, end); //distance_to_front_from_RC = calcDistToEdge(myRC.Orientation.Forward, rc_pos_grid, start, end); }
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 override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder) { // Type Sandbox.Common.Components.MyEntityComponentBase used in Init not allowed in script logRefCount++; myDoor = this.Entity as IMyDoor; myDoorBlock = this.Entity as Sandbox.ModAPI.IMyCubeBlock; // hook up events myDoor.DoorStateChanged += MyAutoDoor_DoorStateChanged; myDoor.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SetupToggleAction(); // try to setup the action //LogMessage("Started Logging", 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 = 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); }
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); }
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; } } }