public NaniteBeaconDeconstruct(IMyFunctionalBlock beaconBlock) : base(beaconBlock) { if (Sync.IsClient) { m_effects.Add(new NaniteBeaconEffect((MyCubeBlock)m_beaconBlock, Vector3.Zero, new Vector4(0.55f, 0.95f, 0.95f, 0.75f))); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); m_objectBuilder = objectBuilder; m_gasGenerator = Entity as IMyGasGenerator; m_terminalBlock = Entity as IMyTerminalBlock; m_functionalBlock = Container.Entity as IMyFunctionalBlock; m_inventory = (MyInventory)(Container.Entity as VRage.Game.Entity.MyEntity).GetInventoryBase(); var subtype = m_functionalBlock.BlockDefinition.SubtypeId; if (m_functionalBlock.CubeGrid.GridSizeEnum == MyCubeSize.Small) { m_sizeFactor = SmallShipRate; } else { m_sizeFactor = LargeShipRate; } var ramscoopDefinition = MyDefinitionManager.Static.GetDefinition(new MyDefinitionId(typeof(MyObjectBuilder_OxygenGenerator), (Container.Entity as IMyFunctionalBlock).BlockDefinition.SubtypeId)) as MyOxygenGeneratorDefinition; m_IceToGasRatio = ramscoopDefinition.ProducedGases[0].IceToGasRatio; m_terminalBlock.AppendingCustomInfo += AppendingCustomInfo; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; }
public GuidedMissileLauncher(WeaponTargeting weapon) { m_weaponTarget = weapon; FuncBlock = CubeBlock as IMyFunctionalBlock; myLogger = new Logger("GuidedMissileLauncher", CubeBlock); var defn = CubeBlock.GetCubeBlockDefinition(); Vector3[] points = new Vector3[3]; Vector3 forwardAdjust = Vector3.Forward * WeaponDescription.GetFor(CubeBlock).MissileSpawnForward; points[0] = CubeBlock.LocalAABB.Min + forwardAdjust; points[1] = CubeBlock.LocalAABB.Max + forwardAdjust; points[2] = CubeBlock.LocalAABB.Min + Vector3.Up * CubeBlock.GetCubeBlockDefinition().Size.Y * CubeBlock.CubeGrid.GridSize + forwardAdjust; MissileSpawnBox = BoundingBox.CreateFromPoints(points); if (m_weaponTarget.myTurret != null) { myLogger.debugLog("original box: " + MissileSpawnBox, "GuidedMissileLauncher()"); MissileSpawnBox.Inflate(CubeBlock.CubeGrid.GridSize * 2f); } myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()"); myInventory = (CubeBlock as Interfaces.IMyInventoryOwner).GetInventory(0); Registrar.Add(weapon.FuncBlock, this); m_weaponTarget.GuidedLauncher = true; }
public void AddBlocksFromIds(long[] blockIds) { foreach (long blockId in blockIds) { VRage.ModAPI.IMyEntity ent = MyAPIGateway.Entities.GetEntityById(blockId); if (ent == null) { Log.Write("problem finding entity with Id"); } IMyFunctionalBlock block = ent as IMyFunctionalBlock; if (block == null) { Log.Write("the block isn't a functional one"); } if (block != null && !_blocks.Contains(block)) { block.EnabledChanged += AssertValidActive; _blocks.Add(ent as IMyFunctionalBlock); Log.Write("added block successfully!"); } else { Log.Write("the block is already there"); } } }
public NaniteOreDetector(IMyFunctionalBlock entity) { m_block = entity as IMyOreDetector; m_lastUpdate = DateTime.MinValue; m_scanStart = DateTime.MinValue; m_scanEnd = DateTime.MinValue; m_lock = new FastResourceLock(); m_oreListCache = new StringBuilder(); m_detectorState = DetectorStates.Disabled; m_lastDetectorState = DetectorStates.Disabled; m_block.Components.TryGet(out Sink); ResourceInfo = new MyResourceSinkInfo() { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = 0f, RequiredInputFunc = () => (m_block.Enabled && m_block.IsFunctional) ? _power : 0f }; Sink.RemoveType(ref ResourceInfo.ResourceTypeId); Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo); Sink.AddType(ref ResourceInfo); m_effects.Add(new OreDetectorEffect((MyCubeBlock)m_block)); if (!NaniteConstructionManager.OreDetectors.ContainsKey(entity.EntityId)) { NaniteConstructionManager.OreDetectors.Add(entity.EntityId, this); } }
public override void SetBlock(SuperBlock block) { IMyTerminalBlock tblock = block.TBlock; this.block = block; if (tblock.ResourceSink != null || tblock is IMyPowerProducer || tblock is IMyFunctionalBlock) { resourceId = MyDefinitionId.FromContent(block.TBlock.SlimBlock.GetObjectBuilder()); sink = tblock.ResourceSink; powerProducer = tblock as IMyPowerProducer; functionalBlock = tblock as IMyFunctionalBlock; if (sink != null || powerProducer != null) { SubtypeId |= TBlockSubtypes.Powered; } if (functionalBlock != null) { SubtypeId |= TBlockSubtypes.Functional; } block.SubtypeId |= SubtypeId; block.subtypeAccessors.Add(this); } }
public LargeNaniteOreDetector(IMyFunctionalBlock block) : base(block) { supportFilter = true; maxScanningLevel = 2; minRange = 50f; basePower = 0.5f; }
private Action TurnBlockOn(long blockID) { return(() => { // ModLog.Info("TurnBlockOn(" + blockID + ")"); // ModLog.Info(cachedTerminalBlocks.Count.ToString() + " Cached Blocks"); foreach (IMyTerminalBlock tb in cachedTerminalBlocks) { if (tb.EntityId == blockID) { IMyFunctionalBlock fb = tb as IMyFunctionalBlock; if (fb != null) { fb.Enabled = true; } if (fb is IMySoundBlock) { // if it's a sound block, start it playing var sb = fb as IMySoundBlock; sb.Play(); } // ModLog.Info("Found"); break; // we found the only one } } }); }
public static DefenseShieldsEnforcement LoadEnforcement(IMyFunctionalBlock shield) { if (shield.Storage == null) { return(null); } string rawData; if (shield.Storage.TryGetValue(Session.Instance.ControllerEnforceGuid, out rawData)) { DefenseShieldsEnforcement loadedEnforce = null; var base64 = Convert.FromBase64String(rawData); loadedEnforce = MyAPIGateway.Utilities.SerializeFromBinary <DefenseShieldsEnforcement>(base64); if (Session.Enforced.Debug == 3) { Log.Line($"Enforcement Loaded {loadedEnforce != null} - Version:{loadedEnforce?.Version} - ShieldId [{shield.EntityId}]"); } if (loadedEnforce != null) { if (Session.Instance.Settings != null) { Session.Instance.Settings.ClientWaiting = false; } return(loadedEnforce); } } return(null); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { // WARNING: this cast will fail and prevent the block from spawning if the block does not have the on/off capability. // Cockpits/cryo/RC can use power but can't be turned off, for example. // If you do have such a block, replace IMyFunctionalBlock with IMyCubeBlock in both places and remove the Block.Enabled condition in the power method. Block = (IMyFunctionalBlock)Entity; NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME; }
private void OpenClose(string action, IMyFunctionalBlock door1, IMyFunctionalBlock door2 = null) { (door1 as IMyDoor).ApplyAction(action); if (door2 != null) { (door2 as IMyDoor).ApplyAction(action); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { if (MyAPIGateway.Session.IsServer) { oxygenFarm = Entity as IMyFunctionalBlock; NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; } }
public void AddBlock(IMyFunctionalBlock block) { if (!_blocks.Contains(block)) { block.EnabledChanged += AssertValidActive; _blocks.Add(block); } }
public BlockState(MyCubeBlock cubeBlock, uint startTick, uint endTick) { CubeBlock = cubeBlock; StartTick = startTick; Endtick = endTick; FunctBlock = cubeBlock as IMyFunctionalBlock; EnableState = ((IMyFunctionalBlock)cubeBlock).Enabled; }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { JumpGateLink = Container.Entity as IMyFunctionalBlock; base.Init(objectBuilder); Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; JumpGateLink.OnClose += OnClose; StaticLinkModCoreblock.stJumpGateLink = Entity; }
public override void Reset() { base.Reset(); resourceId = default(MyDefinitionId); sink = null; powerProducer = null; functionalBlock = null; }
private void AssertValidActive(IMyTerminalBlock block) { IMyFunctionalBlock test = block as IMyFunctionalBlock;; if (test != null) { test.Enabled = _isActive; } }
internal static void SetPowerRequirements(IMyFunctionalBlock block, Func <float> requiredInputFunc) { var resourceSink = block.Components.Get <MyResourceSinkComponent>(); if (resourceSink != null) { resourceSink.SetRequiredInputFuncByType(new MyDefinitionId(typeof(VRage.Game.ObjectBuilders.Definitions.MyObjectBuilder_GasProperties), "Electricity"), requiredInputFunc); } }
/// <summary> /// Gets all valid connected grids, and floating objects or players. /// </summary> /// <param name="ftl"></param> /// <returns></returns> public static HashSet <IMyEntity> GetAllValidObjects(this IMyFunctionalBlock ftl) { Logger.Instance.LogDebug("GetAllValidObjects()"); var objects = ftl.GetConnectedGrids(); var floatingobjs = new HashSet <IMyEntity>(); foreach (var entity in objects) { var collisions = new List <IMyEntity>(); var uniqueEntities = new HashSet <IMyEntity>(); VRageMath.BoundingBoxD shipBB = entity.PositionComp.WorldAABB; // Get a list of entities nearby collisions = MyAPIGateway.Entities.GetEntitiesInAABB(ref shipBB); // The collision list will contain every block on a entity // So we need to reduce it down to just the entities themselves foreach (var col in collisions) { if (col == null) { continue; } if (col.GetTopMostParent() is IMyCubeGrid) { if (!uniqueEntities.Contains(col.GetTopMostParent())) { uniqueEntities.Add(col.GetTopMostParent()); } } else { uniqueEntities.Add(col); } } Logger.Instance.LogDebug("uniqueEntities: " + uniqueEntities.Count); foreach (var unique in uniqueEntities) { if (!IsEntityValid(unique)) { continue; } // Check if the two entities actually intersect, otherwise we don't want to jump it if (!floatingobjs.Contains(unique.GetTopMostParent()) && shipBB.Intersects(unique.GetTopMostParent().PositionComp.WorldAABB)) { floatingobjs.Add(unique.GetTopMostParent()); } } } objects.UnionWith(floatingobjs); return(objects); }
/// <summary> /// This gets the FTL strData for a specific entity. /// If it doesn't exist, one is added and returned. /// </summary> /// <param name="obj"></param> /// <returns></returns> public static FTLData GetFTLData(this IMyFunctionalBlock ftl) { var gamelogic = ftl.GameLogic.GetAs <FTLBase>(); if (gamelogic.m_ftld == null) { gamelogic.InitFTLData(); } return(gamelogic.m_ftld); // Grab the strData that corresponds to the DHD }
public NaniteBeacon(IMyFunctionalBlock beaconBlock) { m_beaconBlock = beaconBlock; m_effects = new List <NaniteBlockEffectBase>(); if (!NaniteConstructionManager.BeaconList.ContainsKey(m_beaconBlock.EntityId)) { NaniteConstructionManager.BeaconList.Add(m_beaconBlock.EntityId, this); } }
public CommonInfo(IMyFunctionalBlock block, int index = 0) { Index = index; Name = block.CustomName; SubtypeId = block.BlockDefinition.SubtypeId; IsBeingHacked = block.IsBeingHacked; IsFunctional = block.IsFunctional; IsWorking = block.IsWorking; IsEnabled = block.Enabled; }
private void CreateTool(MyCubeSize size, string toolBuilderText) { var toolObject = toolBuilderText; if (size == MyCubeSize.Large) { toolObject = string.Format(toolObject, "Small"); } else { toolObject = string.Format(toolObject, "Tiny"); } MyObjectBuilder_CubeGrid cubeGrid = MyAPIGateway.Utilities.SerializeFromXML <MyObjectBuilder_CubeGrid>(toolObject); foreach (var item in cubeGrid.CubeBlocks) { item.Owner = m_constructionBlock.ConstructionBlock.OwnerId; } m_toolEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(cubeGrid); m_toolEntity.PositionComp.Scale = 0.001f; m_toolEntity.PositionComp.SetPosition(GetTargetPosition()); m_toolEntity.Physics.Enabled = false; m_toolEntity.Save = false; var toolGrid = (MyCubeGrid)m_toolEntity; toolGrid.IsSplit = true; toolGrid.IsPreview = true; List <IMySlimBlock> blocks = new List <IMySlimBlock>(); ((IMyCubeGrid)m_toolEntity).GetBlocks(blocks); foreach (var slimBlock in blocks) { if (slimBlock.FatBlock == null) { continue; } var block = slimBlock.FatBlock; if (block is Sandbox.ModAPI.Ingame.IMyShipWelder || block is Sandbox.ModAPI.Ingame.IMyShipGrinder) { MyCubeBlock toolBlock = (MyCubeBlock)block; toolBlock.IDModule.ShareMode = MyOwnershipShareModeEnum.Faction; IMyFunctionalBlock tool = (IMyFunctionalBlock)block; m_tool = tool; break; } } MyAPIGateway.Entities.AddEntity(m_toolEntity); //m_toolEntity.RemoveFromGamePruningStructure(); }
public static List <IMySlimBlock> GetFTLDrives(this IMyFunctionalBlock ftl) { List <IMySlimBlock> ftlDrives = new List <IMySlimBlock>(); (ftl.CubeGrid as IMyCubeGrid).GetBlocks(ftlDrives, (x) => x.FatBlock != null && x.FatBlock is IMyFunctionalBlock && (x.FatBlock as IMyFunctionalBlock).IsFTL()); return(ftlDrives); }
internal static bool HasRequiredPower(IMyFunctionalBlock constructionBlock, float powerRequired) { var resourceSink = constructionBlock.Components.Get <MyResourceSinkComponent>(); if (resourceSink != null) { return(resourceSink.IsPowerAvailable(new MyDefinitionId(typeof(VRage.Game.ObjectBuilders.Definitions.MyObjectBuilder_GasProperties), "Electricity"), powerRequired)); } return(true); }
public BaseEntity(IMyFunctionalBlock block) { Ini = new MyIni(); MyIniParseResult result; if (!Ini.TryParse(block.CustomData, out result)) { throw new Exception(result.ToString()); } }
void blocksToggleOnOff(List <IMyTerminalBlock> blocks) { foreach (var b in blocks) { IMyFunctionalBlock f = b as IMyFunctionalBlock; if (f == null) { continue; } f.Enabled = !f.Enabled; } }
internal static bool HasRequiredPowerForCurrentTarget(IMyFunctionalBlock constructionBlock) { if (!NaniteConstructionManager.NaniteBlocks.ContainsKey(constructionBlock.EntityId)) { return(false); } NaniteConstructionBlock block = NaniteConstructionManager.NaniteBlocks[constructionBlock.EntityId]; var powerRequired = block.Targets.Sum(x => x.TargetList.Count * x.GetPowerUsage()); return(HasRequiredPower(constructionBlock, powerRequired)); }
/* * This will cause CHAOS! * * void groupApplyAction(string sGroup, string sAction) * { * List<IMyBlockGroup> groups = new List<IMyBlockGroup>(); GridTerminalSystem.GetBlockGroups(groups); for (int groupIndex = 0; groupIndex < groups.Count; groupIndex++) * { * if (groups[groupIndex].Name == sGroup) * { * List<IMyTerminalBlock> theBlocks = null; * groups[groupIndex].GetBlocks(theBlocks, (x1 => x1.CubeGrid == Me.CubeGrid)); * ; for (int iIndex = 0; iIndex < theBlocks.Count; iIndex++) * { theBlocks[iIndex].ApplyAction(sAction); } * return; * } * } * return; * } * void listSetValueFloat(List<IMyTerminalBlock> theBlocks, string sProperty, float fValue) * { * for (int iIndex = 0; iIndex < theBlocks.Count; iIndex++) * { * if (theBlocks[iIndex].CubeGrid == Me.CubeGrid) * theBlocks[iIndex].SetValueFloat(sProperty, fValue); * } * return; * } * void blockApplyAction(string sBlock, string sAction) * { * List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>(); * blocks = GetBlocksNamed<IMyTerminalBlock>(sBlock); * blockApplyAction(blocks, sAction); * } * void blockApplyAction(IMyTerminalBlock sBlock, string sAction) * { * ITerminalAction ita; ita = sBlock.GetActionWithName(sAction); * if (ita != null) * ita.Apply(sBlock); * else * Echo("Unsupported action:" + sAction); * } * * void blockApplyAction(List<IMyTerminalBlock> lBlock, string sAction) * { * if (lBlock.Count > 0) * { * for (int i = 0; i < lBlock.Count; i++) * { * ITerminalAction ita; * ita = lBlock[i].GetActionWithName(sAction); * if (ita != null) * ita.Apply(lBlock[i]); * else * Echo("Unsupported action:" + sAction); * } * } * } */ void blocksOnOff(List <IMyTerminalBlock> blocks, bool bOn = true) { foreach (var b in blocks) { IMyFunctionalBlock f = b as IMyFunctionalBlock; if (f == null) { continue; } f.Enabled = bOn; } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); this.NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; IMyFunctionalBlock FBlock = Entity as IMyFunctionalBlock; Pair.Block = Entity as IMyFunctionalBlock; FBlock.OwnershipChanged += Lock; FBlock.IsWorkingChanged += Lock; //FBlock.PropertiesChanged += PropertiesChanged; FBlock.AppendingCustomInfo += AppInfo; }
/// <summary> /// Find the best reference orientation to use for jump drive coordinates. /// It will try one of several things: /// 1) Find a cockpit or RC block grouped to the FTL. If it find any, it will use the 'Main Cockpit', if set, otherwise random. /// 2) Search for a non-grouped cockpit or remote control block. If it finds only one, it uses that /// 3) If there are multiple, and one has 'FTL' in the name, it uses the first one found. /// 4) If there are multiple, and not named, it finds the first one with 'Main Cockpit' set /// 4) If there are multiple, and not named, it finds the first one with 'Control Thrusters' set /// 5) If there are no cockpits, it uses the original entity reference. /// </summary> /// <returns>Worldmatrix of entity to use for reference</returns> public static VRageMath.MatrixD GetShipReference(this IMyFunctionalBlock ftl) { VRageMath.MatrixD reference = ftl.GetTopMostParent().PositionComp.WorldMatrix; var controller = GetShipController(ftl); if (controller != null) { reference = controller.WorldMatrix; } return(reference); }
public GuidedMissileLauncher(FixedWeapon weapon) { myFixed = weapon; FuncBlock = CubeBlock as IMyFunctionalBlock; myLogger = new Logger("GuidedMissileLauncher", CubeBlock); MissileSpawnBox = CubeBlock.LocalAABB; // might need this again for shorter range missiles //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Min + CubeBlock.LocalMatrix.Forward * 10f); //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Max + CubeBlock.LocalMatrix.Forward * 10f); myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()"); myInventory = (CubeBlock as Interfaces.IMyInventoryOwner).GetInventory(0); myFixed.AllowedState = WeaponTargeting.State.GetOptions; Registrar.Add(weapon.FuncBlock, this); }
public TargetingBase(IMyEntity entity, IMyCubeBlock controllingBlock) { if (entity == null) throw new ArgumentNullException("entity"); if (controllingBlock == null) throw new ArgumentNullException("controllingBlock"); myLogger = new Logger("TargetingBase", entity); MyEntity = entity; CubeBlock = controllingBlock; FuncBlock = controllingBlock as IMyFunctionalBlock; myTarget = NoTarget.Instance; CurrentTarget = myTarget; Options = new TargetingOptions(); entity.OnClose += obj => { if (WeaponsTargetingProjectile != null) CurrentTarget = null; }; //myLogger.debugLog("entity: " + MyEntity.getBestName() + ", block: " + CubeBlock.getBestName(), "TargetingBase()"); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { try { base.Init(objectBuilder); m_objectBuilder = objectBuilder; m_block = Entity as IMyFunctionalBlock; if (m_block.BlockDefinition.SubtypeId == "LargeBlockBeaconSecurity" || m_block.BlockDefinition.SubtypeId == "SmallBlockBeaconSecurity" || m_block.BlockDefinition.SubtypeId == "LargeBlockBeaconSecurityCustom" || m_block.BlockDefinition.SubtypeId == "SmallBlockBeaconSecurityCustom") { Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; IsBeaconSecurity = true; IsMoving = false; Frame = frameShift++; //each other BS uses shifted frame, for balancing } } catch (Exception ex) { Logger.Log.Debug(ex.Message); } }
static void ToggleOn(IMyFunctionalBlock block) { if (block == null) throw new Exception(" ToggleOn(IMyFunctionalBlock): block is null"); block.GetActionWithName("OnOff_On").Apply(block); }
public static void ToggleOff(IMyFunctionalBlock block) { block.GetActionWithName("OnOff_Off").Apply(block); }