public MyUseObjectCryoChamberDoor(MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int key) { CryoChamber = owner as MyCryoChamber; Debug.Assert(CryoChamber != null, "MyUseObjectCryoChamberDoor should only be used with MyCryoChamber blocks!"); LocalMatrix = dummyData.Matrix; }
void CubeBlock_IsWorkingChanged(MyCubeBlock obj) { if (IsWorking) OnStartWorking(); else OnStopWorking(); }
public static IMyUseObject CreateUseObject(string detectorName, MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int shapeKey) { Type type; if (!m_useObjectTypesByDummyName.TryGetValue(detectorName, out type) || type == null) return null; return (IMyUseObject)Activator.CreateInstance(type, owner, dummyName, dummyData, shapeKey); }
public MyUseObjectPanelButton(MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int key) { m_buttonPanel = owner as MyButtonPanel; m_localMatrix = dummyData.Matrix; int orderNumber = 0; var parts = dummyName.Split('_'); int.TryParse(parts[parts.Length - 1], out orderNumber); m_index = orderNumber - 1; if (m_index >= m_buttonPanel.BlockDefinition.ButtonCount) { MyLog.Default.WriteLine(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName)); Debug.Fail(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName)); m_index = m_buttonPanel.BlockDefinition.ButtonCount - 1; } }
public override float GetSpeed() { MyCubeBlock block = (MyCubeBlock)m_constructionBlock.ConstructionBlock; return(NaniteConstructionManager.Settings.MiningDistanceDivisor + (block.UpgradeValues["SpeedNanites"] * (float)NaniteConstructionManager.Settings.SpeedIncreasePerUpgrade)); }
public static ConveyorLinePosition[] GetLinePositions(MyCubeBlock cubeBlock, string dummyName) { return(GetLinePositions(cubeBlock, VRage.Game.Models.MyModels.GetModelOnlyDummies(cubeBlock.BlockDefinition.Model).Dummies, dummyName)); }
public void UpdateVisual() { UpdateShowParts(); if (!ShowParts) { if (FatBlock == null) { FatBlock = new MyCubeBlock(); FatBlock.SlimBlock = this; FatBlock.Init(); CubeGrid.Hierarchy.AddChild(FatBlock); m_soundEmitter.Entity = FatBlock; m_soundEmitter.SetPosition(null); } else { FatBlock.UpdateVisual(); } } else if (FatBlock != null) { var pos = FatBlock.WorldMatrix.Translation; CubeGrid.Hierarchy.RemoveChild(FatBlock); FatBlock.Close(); FatBlock = null; m_soundEmitter.Entity = null; } CubeGrid.SetBlockDirty(this); if (CubeGrid.Physics != null) { CubeGrid.Physics.AddDirtyArea(Min, Max); } }
public void ChangeBlockOwnership(MyCubeBlock block, long oldOwner, long newOwner) { DecreaseValue(ref PlayerOwnedBlocks, oldOwner); IncreaseValue(ref PlayerOwnedBlocks, newOwner); if (IsValidBlock(block)) { DecreaseValue(ref PlayerOwnedValidBlocks, oldOwner); IncreaseValue(ref PlayerOwnedValidBlocks, newOwner); } NeedRecalculateOwners = true; }
void MyProgrammableBlock_IsWorkingChanged(MyCubeBlock obj) { UpdateEmissivity(); }
void MyUpgradeModule_IsWorkingChanged(MyCubeBlock obj) { RefreshEffects(); UpdateEmissivity(); }
private bool CanAffectBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { if (block.UpgradeValues.ContainsKey(upgrade.UpgradeType)) { return true; } } return false; }
void OnIsWorkingChanged(MyCubeBlock obj) { UpdateEmissivity(); }
void MyOxygenTank_IsWorkingChanged(MyCubeBlock obj) { SourceComp.Enabled = CanStore; UpdateEmissivity(); }
public static MyFixedPoint ItemPullRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId, MyFixedPoint?amount = null, bool remove = false) { MyFixedPoint transferred = 0; using (var invertedConductivity = new MyConveyorLine.InvertedConductivity()) { /*if (amount.HasValue) * Debug.Assert(itemId.TypeId == typeof(MyObjectBuilder_Ore) || * itemId.TypeId == typeof(MyObjectBuilder_Ingot) || * MyFixedPoint.Floor(amount.Value) == amount.Value);*/ SetTraversalPlayerId(playerId); SetTraversalInventoryItemDefinitionId(itemId); PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null); foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { MyCubeBlock owner = (conveyorEndpoint.CubeBlock != null && conveyorEndpoint.CubeBlock.HasInventory) ? conveyorEndpoint.CubeBlock : null; if (owner == null) { continue; } for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i) as MyInventory; System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!"); if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0) { continue; } if (inventory == destinationInventory) { continue; } var availableAmount = inventory.GetItemAmount(itemId); if (amount.HasValue) { availableAmount = amount.HasValue ? MyFixedPoint.Min(availableAmount, amount.Value) : availableAmount; if (availableAmount == 0) { continue; } if (remove) { transferred += inventory.RemoveItemsOfType(availableAmount, itemId); } else { transferred += MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount); } amount -= availableAmount; if (amount.Value == 0) { return(transferred); } } else { if (remove) { transferred += inventory.RemoveItemsOfType(availableAmount, itemId); } else { transferred += MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount); } } } } } return(transferred); }
private static bool ItemPullAllInternal(MyInventory destinationInventory, PullRequestItemSet requestedTypeIds, bool onlySmall) { bool pullCreated = false; SetTraversalInventoryItemDefinitionId(); Debug.Assert(m_tmpPullRequests.Count == 0, "m_tmpPullRequests is not empty!"); using (var invertedConductivity = new MyConveyorLine.InvertedConductivity()) { foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { MyCubeBlock owner = (conveyorEndpoint.CubeBlock != null && conveyorEndpoint.CubeBlock.HasInventory) ? conveyorEndpoint.CubeBlock : null; if (owner == null) { continue; } for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i) as MyInventory; System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!"); if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0) { continue; } if (inventory == destinationInventory) { continue; } m_tmpInventoryItems.Clear(); foreach (var item in inventory.GetItems()) { m_tmpInventoryItems.Add(item); } foreach (var item in m_tmpInventoryItems) { if (destinationInventory.VolumeFillFactor >= 1.0f) { m_tmpInventoryItems.Clear(); return(pullCreated); } var itemId = item.Content.GetId(); if (requestedTypeIds != null && !requestedTypeIds.Contains(itemId)) { continue; } if (onlySmall && NeedsLargeTube(itemId)) { continue; } var transferedAmount = item.Amount; var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_GasContainerObject; if (oxygenBottle != null && oxygenBottle.GasLevel == 1f) { continue; } if (!MySession.Static.CreativeMode) { var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId()); if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) && item.Content.TypeId != typeof(MyObjectBuilder_Ingot)) { fittingAmount = MyFixedPoint.Floor(fittingAmount); } transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount); } if (transferedAmount == 0) { continue; } // SK: this is mental m_tmpPullRequests.Add(new MyTuple <IMyConveyorEndpointBlock, MyPhysicalInventoryItem>(m_startingEndpoint.CubeBlock as IMyConveyorEndpointBlock, item)); //MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount); } } } } foreach (var tuple in m_tmpPullRequests) { if (destinationInventory.VolumeFillFactor >= 1.0f) { m_tmpPullRequests.Clear(); return(pullCreated); } var start = tuple.Item1; var item = tuple.Item2; var transferedAmount = item.Amount; var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId()); if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) && item.Content.TypeId != typeof(MyObjectBuilder_Ingot)) { fittingAmount = MyFixedPoint.Floor(fittingAmount); } transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount); if (transferedAmount == 0) { continue; } var itemId = item.Content.GetId(); SetTraversalInventoryItemDefinitionId(itemId); ItemPullRequest(start, destinationInventory, m_playerIdForAccessiblePredicate, itemId, transferedAmount); pullCreated = true; } m_tmpPullRequests.Clear(); return(pullCreated); }
public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint?amount = null) { var itemBuilder = toSend.Content; if (amount.HasValue) { Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) || toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) || MyFixedPoint.Floor(amount.Value) == amount.Value); } MyFixedPoint remainingAmount = toSend.Amount; if (amount.HasValue) { remainingAmount = amount.Value; } SetTraversalPlayerId(playerId); var toSendContentId = toSend.Content.GetId(); SetTraversalInventoryItemDefinitionId(toSendContentId); if (NeedsLargeTube(toSendContentId)) { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate); } else { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate); } bool success = false; foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { MyCubeBlock owner = (conveyorEndpoint.CubeBlock != null && conveyorEndpoint.CubeBlock.HasInventory) ? conveyorEndpoint.CubeBlock : null; if (owner == null) { continue; } for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i) as MyInventory; System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!"); if ((inventory.GetFlags() & MyInventoryFlags.CanReceive) == 0) { continue; } if (inventory == srcInventory) { continue; } var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId); fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount); if (!inventory.CheckConstraint(toSendContentId)) { continue; } if (fittingAmount == 0) { continue; } MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount); success = true; } } return(success); }
private void DamageCheck(object target, ref MyDamageInformation info) { if (file != null) { if (file.LogNeutralsDamagingEachOther || file.ShowFactionTagsOnDamageGrid) { try { if (!(target is MySlimBlock block)) { return; } long attackerId = GetAttacker(info.AttackerId); MyIdentity id = MySession.Static.Players.TryGetIdentity(attackerId); if (id == null) { return; } IMyFaction defender = FacUtils.GetPlayersFaction(FacUtils.GetOwner(block.CubeGrid)); IMyFaction attacker = FacUtils.GetPlayersFaction(id.IdentityId); if (file.ShowFactionTagsOnDamageGrid) { if (Sync.Players.TryGetPlayerId(id.IdentityId, out MyPlayer.PlayerId player)) { if (MySession.Static.Players.GetPlayerById(player) != null) { SendAttackNotification(attacker, defender, attackerId, player.SteamId, block.CubeGrid.PositionComp.GetPosition()); } } } MyCubeBlock cubeBlock = block.FatBlock; if (cubeBlock == null) { return; } if (cubeBlock as MyTerminalBlock == null) { return; } if (cubeBlock.EntityId == 0L) { return; } if (GetAttacker(info.AttackerId) > 0L) { //this is so messy if (attacker != null && defender != null) { if (attacker.Equals(defender)) { return; } if (MySession.Static.Factions.AreFactionsFriends(attacker.FactionId, defender.FactionId) || MySession.Static.Factions.AreFactionsNeutrals(attacker.FactionId, defender.FactionId)) { if (blockCooldowns.TryGetValue(cubeBlock.EntityId, out DateTime time)) { if (DateTime.Now < time) { return; } } if (file.ShowFactionTagsOnDamageGrid) { blockCooldowns.Remove(cubeBlock.EntityId); blockCooldowns.Add(cubeBlock.EntityId, DateTime.Now.AddSeconds(10)); CrunchUtilitiesPlugin.Log.Info("FACTIONLOG Attacking while not at war " + attackerId + " " + attacker.Tag + " " + attacker.FactionId + " against " + cubeBlock.CubeGrid.DisplayName + ", " + defender.Tag + " " + defender.FactionId); } } } else { return; } } } catch (Exception e) { Log.Error(e, "Error on Checking Damage!"); } } } }
void MyWheel_IsWorkingChanged(MyCubeBlock obj) { if(Stator != null) Stator.UpdateIsWorking(); }
private void CubeBlock_IsWorkingChanged(MyCubeBlock block) { if (IsWorking) { MyCubeBlock.UpdateEmissiveParts(Render.RenderObjectIDs[0], 1.0f, Color.Green, Color.White); if (IsProducing) OnStartProducing(); } else { MyCubeBlock.UpdateEmissiveParts(Render.RenderObjectIDs[0], 0.0f, Color.Red, Color.White); } }
public MyAttachableConveyorEndpoint(MyCubeBlock block) : base(block) { m_lines = new List <MyAttachableLine>(); }
private void AddEffectToBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { float val; if (block.UpgradeValues.TryGetValue(upgrade.UpgradeType, out val)) { if (upgrade.ModifierType == MyUpgradeModifierType.Additive) { val += upgrade.Modifier; } else { val *= upgrade.Modifier; } block.UpgradeValues[upgrade.UpgradeType] = val; } } block.CommitUpgradeValues(); }
private void MySpaceBall_IsWorkingChanged(MyCubeBlock obj) { UpdateRadios(IsWorking); }
void MyShipConnector_IsWorkingChanged(MyCubeBlock obj) { Debug.Assert(obj == this); if (Sync.IsServer && Connected && m_welded ==false) { if (!IsFunctional || !IsWorking) { m_connectionState.Value = State.Detached; NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; } } UpdateEmissivity(); }
public MyUseObjectTextPanel(MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int key) { m_textPanel = (MyTextPanel)owner; m_localMatrix = dummyData.Matrix; }
public void UpdateVisual(bool updatePhysics = true) { UpdateShowParts(); if (!ShowParts) { if (FatBlock == null) { FatBlock = new MyCubeBlock(); FatBlock.SlimBlock = this; FatBlock.Init(); CubeGrid.Hierarchy.AddChild(FatBlock); } else { FatBlock.UpdateVisual(); } } else if (FatBlock != null) { var pos = FatBlock.WorldMatrix.Translation; CubeGrid.Hierarchy.RemoveChild(FatBlock); FatBlock.Close(); FatBlock = null; } CubeGrid.SetBlockDirty(this); if (updatePhysics && CubeGrid.Physics != null) { CubeGrid.Physics.AddDirtyArea(Min, Max); } }
public NaniteAreaBeaconEffect(MyCubeBlock owner) { m_owner = owner as IMyFunctionalBlock; }
internal Target(MyCubeBlock firingCube = null) { ParentIsWeapon = firingCube != null; FiringCube = firingCube; }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); m_hits.Clear(); MyPhysics.CastRay(m_origin, FrontPoint, m_hits, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer); DetectionInfo value = new DetectionInfo(); bool encounteredModel = false; foreach (var hit in m_hits) { var hitInfo = hit.HkHitInfo; if (hitInfo.Body == null) { continue; } var entity = hitInfo.GetHitEntity(); if (entity == null) { continue; } var rootEntity = entity.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { Vector3D detectionPoint = hit.Position; MyCubeGrid grid = rootEntity as MyCubeGrid; if (grid != null) { var shape = hitInfo.Body.GetShape(); int shapeIdx = 0; if (grid.Physics.IsWelded || grid.GetPhysicsBody().WeldInfo.Children.Count != 0) { if (shape.IsContainer()) { shape = shape.GetContainer().GetShape(hitInfo.GetShapeKey(0)); shapeIdx = 1; } } if (!GetShapeCenter(shape, hitInfo.GetShapeKey(shapeIdx), grid, ref detectionPoint)) { if (grid.GridSizeEnum == MyCubeSize.Large) { detectionPoint += hit.HkHitInfo.Normal * -0.08f; } else { detectionPoint += hit.HkHitInfo.Normal * -0.02f; } } } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { var oldDistance = Vector3.DistanceSquared(value.DetectionPoint, m_origin); var newDistance = Vector3.DistanceSquared(detectionPoint, m_origin); if (oldDistance > newDistance) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } if (entity is MyEnvironmentSector && !encounteredModel) { var sector = entity as MyEnvironmentSector; var shapekey = hitInfo.GetShapeKey(0); var itemId = sector.GetItemFromShapeKey(shapekey); if (sector.DataView.Items[itemId].ModelIndex < 0) { continue; } encounteredModel = true; m_entitiesInRange[entity.EntityId] = new DetectionInfo(sector, detectionPoint, itemId); } } } LineD line = new LineD(m_origin, FrontPoint); using (m_raycastResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInRay(ref line, m_raycastResults); foreach (var segment in m_raycastResults) { if (segment.Element == null) { continue; } var rootEntity = segment.Element.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { MyCubeBlock block = segment.Element as MyCubeBlock; if (block == null) { continue; } Vector3D point = new Vector3D(); if (block.SlimBlock.HasPhysics == false) { MatrixD blockWorldMatrixNormalizedInv = block.PositionComp.WorldMatrixNormalizedInv; Vector3D localOrigin = Vector3D.Transform(m_origin, ref blockWorldMatrixNormalizedInv); Vector3D localFront = Vector3D.Transform(FrontPoint, ref blockWorldMatrixNormalizedInv); Ray ray = new Ray(localOrigin, Vector3.Normalize(localFront - localOrigin)); //MyRenderProxy.DebugDrawAABB(block.WorldAABB, Color.Red.ToVector3(), 1.0f, 1.0f, false); float?dist = ray.Intersects(block.PositionComp.LocalAABB); dist += 0.01f; if (dist.HasValue && dist <= m_rayLength) { point = m_origin + Vector3D.Normalize(FrontPoint - m_origin) * dist.Value; } else { continue; } } else { // This entity was caught by Havok raycast continue; } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { if (Vector3.DistanceSquared(value.DetectionPoint, m_origin) > Vector3.DistanceSquared(point, m_origin)) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } } } }
public virtual void RegisterInSystems(MyCubeBlock block) { if (ResourceDistributor != null) { var powerProducer = block.Components.Get<MyResourceSourceComponent>(); if (powerProducer != null) ResourceDistributor.AddSource(powerProducer); var powerConsumer = block.Components.Get<MyResourceSinkComponent>(); if (powerConsumer != null) ResourceDistributor.AddSink(powerConsumer); var socketOwner = block as IMyRechargeSocketOwner; if (socketOwner != null) socketOwner.RechargeSocket.ResourceDistributor = ResourceDistributor; } if (WeaponSystem != null) { var weapon = block as IMyGunObject<MyDeviceBase>; if (weapon != null) WeaponSystem.Register(weapon); } if (TerminalSystem != null) { var functionalBlock = block as MyTerminalBlock; if (functionalBlock != null) TerminalSystem.Add(functionalBlock); } // CH: We probably don't need to register controller blocks here. Block that's being added to a grid should not have a controller set var controllableBlock = block as MyShipController; Debug.Assert(controllableBlock == null || controllableBlock.ControllerInfo.Controller == null, "Controller of added block is not null. Call Cestmir"); /*if (ControlSystem != null) { var controllableBlock = block as MyShipController; if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null) ControlSystem.AddControllerBlock(controllableBlock); }*/ var inventoryBlock = (block != null && block.HasInventory) ? block : null; if (inventoryBlock != null) ConveyorSystem.Add(inventoryBlock); var conveyorBlock = block as IMyConveyorEndpointBlock; if (conveyorBlock != null) { conveyorBlock.InitializeConveyorEndpoint(); ConveyorSystem.AddConveyorBlock(conveyorBlock); } var segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); ConveyorSystem.AddSegmentBlock(segmentBlock); } var reflectorLight = block as MyReflectorLight; if (reflectorLight != null) ReflectorLightSystem.Register(reflectorLight); if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { var wheel = block as MyMotorSuspension; if (wheel != null) WheelSystem.Register(wheel); } var landingGear = block as IMyLandingGear; if (landingGear != null) LandingSystem.Register(landingGear); var gyro = block as MyGyro; if (gyro != null) GyroSystem.Register(gyro); var camera = block as MyCameraBlock; if (camera != null) CameraSystem.Register(camera); block.OnRegisteredToGridSystems(); }
public override float GetMinTravelTime() { MyCubeBlock block = (MyCubeBlock)m_constructionBlock.ConstructionBlock; return(Math.Max(1f, NaniteConstructionManager.Settings.MiningMinTravelTime - (block.UpgradeValues["SpeedNanites"] * NaniteConstructionManager.Settings.MinTravelTimeReductionPerUpgrade))); }
private void CubeBlock_OnWorkingChanged(MyCubeBlock block) { m_positionDirty = true; }
void MyShipToolBase_IsWorkingChanged(MyCubeBlock obj) { UpdateActivationState(); }
public static MyObjectBuilder_CubeBlock CreateObjectBuilder(MyCubeBlock cubeBlock) { MyObjectBuilder_CubeBlock objectBuilder = (MyObjectBuilder_CubeBlock)MyObjectBuilderSerializer.CreateNewObject(cubeBlock.BlockDefinition.Id); return(objectBuilder); }
private void MyShipMergeBlock_IsWorkingChanged(MyCubeBlock obj) { Debug.Assert(Physics != null || !InScene); if (Physics != null) Physics.Enabled = this.IsWorking; if (!this.IsWorking) { var otherBlock = GetOtherMergeBlock(); if (otherBlock != null) { } else if (InConstraint) RemoveConstraintInBoth(); } CheckConnectionAllowed = !this.IsWorking; CubeGrid.UpdateBlockNeighbours(this.SlimBlock); CheckEmissivity(); }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); m_hits.Clear(); MyPhysics.CastRay(m_origin, FrontPoint, m_hits, MyPhysics.ObjectDetectionCollisionLayer); DetectionInfo value = new DetectionInfo(); foreach (var hit in m_hits) { var hitInfo = hit.HkHitInfo; if (hitInfo.Body == null) { continue; } var entity = hitInfo.Body.GetEntity(); if (entity == null) { continue; } var rootEntity = entity.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { Vector3D detectionPoint = hit.Position; MyCubeGrid grid = rootEntity as MyCubeGrid; if (grid != null) { if (!GetShapeCenter(hitInfo.Body.GetShape(), hitInfo.GetShapeKey(0), grid, ref detectionPoint)) { if (grid.GridSizeEnum == Common.ObjectBuilders.MyCubeSize.Large) { detectionPoint += hit.HkHitInfo.Normal * -0.08f; } else { detectionPoint += hit.HkHitInfo.Normal * -0.02f; } } } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { var oldDistance = Vector3.DistanceSquared(value.DetectionPoint, m_origin); var newDistance = Vector3.DistanceSquared(detectionPoint, m_origin); if (oldDistance > newDistance) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity as MyEntity, detectionPoint); } } } LineD line = new LineD(m_origin, FrontPoint); using (m_raycastResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInRay(ref line, m_raycastResults); foreach (var segment in m_raycastResults) { if (segment.Element == null) { continue; } var rootEntity = segment.Element.GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { if (!(segment.Element is MyCubeBlock)) { continue; } Vector3D point = new Vector3D(); MyCubeBlock block = segment.Element as MyCubeBlock; if (block.SlimBlock.HasPhysics == false) { Vector3D localOrigin = Vector3D.Transform(m_origin, block.PositionComp.WorldMatrixNormalizedInv); Vector3D localFront = Vector3D.Transform(FrontPoint, block.PositionComp.WorldMatrixNormalizedInv); Ray ray = new Ray(localOrigin, Vector3.Normalize(localFront - localOrigin)); //MyRenderProxy.DebugDrawAABB(block.WorldAABB, Color.Red.ToVector3(), 1.0f, 1.0f, false); float?dist = ray.Intersects(block.PositionComp.LocalAABB); dist += 0.01f; if (dist.HasValue && dist <= m_rayLength) { point = m_origin + Vector3D.Normalize(FrontPoint - m_origin) * dist.Value; } else { continue; } } else { // This entity was caught by Havok raycast continue; } if (m_entitiesInRange.TryGetValue(rootEntity.EntityId, out value)) { if (Vector3.DistanceSquared(value.DetectionPoint, m_origin) > Vector3.DistanceSquared(point, m_origin)) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } else { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, point); } } } } }
public MyUseObjectWardrobe(MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int key) { Block = owner; LocalMatrix = dummyData.Matrix; }
private void RemoveEffectFromBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { float val; if (block.UpgradeValues.TryGetValue(upgrade.UpgradeType, out val)) { if (upgrade.ModifierType == MyUpgradeModifierType.Additive) { val -= upgrade.Modifier; if (val < 0f) { val = 0f; Debug.Fail("Additive modifier cannot be negative!"); } } else { val /= upgrade.Modifier; if (val < 1f) { val = 1f; Debug.Fail("Multiplicative modifier cannot be < 1.0f!"); } } block.UpgradeValues[upgrade.UpgradeType] = val; } } block.CommitUpgradeValues(); }
void UpdatePirateAntenna(MyCubeBlock obj) { UpdatePirateAntenna(); }
protected int GetBlockConnectionCount(MyCubeBlock cubeBlock) { int count = 0; foreach (var value in m_connectedBlocks.Values) { if (value == cubeBlock) { count++; } } return count; }
private bool FindFreeCargo(IMyEntity target, MyCubeBlock startBlock, bool transfer) { var list = Conveyor.GetConveyorListFromEntity(m_constructionBlock.ConstructionBlock); if (list == null) { return(false); } List <MyInventory> inventoryList = new List <MyInventory>(); foreach (var item in list) { IMyEntity entity; if (MyAPIGateway.Entities.TryGetEntityById(item, out entity)) { if (!(entity is IMyCubeBlock)) { continue; } if (entity is Ingame.IMyRefinery || entity is Ingame.IMyAssembler) { continue; } MyCubeBlock block = (MyCubeBlock)entity; if (!block.HasInventory) { continue; } inventoryList.Add(block.GetInventory()); } } MyFloatingObject floating = (MyFloatingObject)target; float amount = 0f; MyInventory targetInventory = null; foreach (var item in inventoryList.OrderByDescending(x => (float)x.MaxVolume - (float)x.CurrentVolume)) { amount = GetNaniteInventoryAmountThatFits(target, (MyCubeBlock)item.Owner); if ((int)amount == 0) { continue; } targetInventory = item; break; } if ((int)amount == 0) { return(false); } var def = MyDefinitionManager.Static.GetPhysicalItemDefinition(new VRage.Game.MyDefinitionId(floating.Item.Content.TypeId, floating.Item.Content.SubtypeId)); if ((int)amount > 1 && (amount / def.Volume) > m_carryVolume) { amount = m_carryVolume / def.Volume; } if ((int)amount < 1) { amount = 1f; } if (transfer) { targetInventory.PickupItem(floating, (int)amount); } return(true); }
void MyLandingGear_IsWorkingChanged(MyCubeBlock obj) { RaisePropertiesChanged(); UpdateEmissivity(); }
public MyUseObjectTerminal(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key) { Block = owner as MyCubeBlock; LocalMatrix = dummyData.Matrix; }
void MyShipConnector_IsWorkingChanged(MyCubeBlock obj) { Debug.Assert(obj == this); if (Connected) { if (!IsFunctional) { Detach(); } else if (!IsWorking) { m_defferedDisconnect = true; NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; } } UpdateEmissivity(); }
public virtual void RegisterInSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { MyCubeBlock block1; if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && (sink != null)) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block6 = block as MyTerminalBlock; if (block6 != null) { this.TerminalSystem.Add(block6); } } if ((block == null) || !block.HasInventory) { block1 = null; } else { block1 = block; } MyCubeBlock block2 = block1; if (block2 != null) { this.ConveyorSystem.Add(block2); } IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock; if (endpointBlock != null) { endpointBlock.InitializeConveyorEndpoint(); this.ConveyorSystem.AddConveyorBlock(endpointBlock); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); this.ConveyorSystem.AddSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Register(reflector); } if (block.Components.Contains(typeof(MyDataBroadcaster))) { MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); this.RadioSystem.Register(broadcaster); } if (block.Components.Contains(typeof(MyDataReceiver))) { MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); this.RadioSystem.Register(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Register(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Register(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Register(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Register(camera); } } block.OnRegisteredToGridSystems(); }
private bool IsValidBlock(MyCubeBlock block) { return block.IsFunctional; }
void MyProjector_IsWorkingChanged(MyCubeBlock obj) { if (!IsWorking && IsProjecting()) { RequestRemoveProjection(); } else { if (IsWorking && !IsProjecting()) { if (m_clipboard.HasCopiedGrids()) { InitializeClipboard(); } } UpdateEmissivity(); } }
public virtual void UnregisterFromSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.RemoveSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.RemoveSink(sink, true, false); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = null; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Unregister(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block5 = block as MyTerminalBlock; if (block5 != null) { this.TerminalSystem.Remove(block5); } } if (block.HasInventory) { this.ConveyorSystem.Remove(block); } IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock; if (block2 != null) { this.ConveyorSystem.RemoveConveyorBlock(block2); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { this.ConveyorSystem.RemoveSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Unregister(reflector); } MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); if (broadcaster != null) { this.RadioSystem.Unregister(broadcaster); } MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); if (reciever != null) { this.RadioSystem.Unregister(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Unregister(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Unregister(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Unregister(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Unregister(camera); } } block.OnUnregisteredFromGridSystems(); }
public static ConveyorLinePosition PositionToGridCoords(ConveyorLinePosition position, MyCubeBlock cubeBlock) { ConveyorLinePosition retval = new ConveyorLinePosition(); Matrix matrix = new Matrix(); cubeBlock.Orientation.GetMatrix(out matrix); Vector3 transformedPosition = Vector3.Transform(new Vector3(position.LocalGridPosition), matrix); retval.LocalGridPosition = Vector3I.Round(transformedPosition) + cubeBlock.Position; retval.Direction = cubeBlock.Orientation.TransformDirection(position.Direction); return(retval); }
void MyBeacon_IsWorkingChanged(MyCubeBlock obj) { if(RadioBroadcaster != null) RadioBroadcaster.Enabled = IsWorking; if (!MyFakes.ENABLE_RADIO_HUD) { if (IsWorking) { MyHud.LocationMarkers.RegisterMarker(this, new MyHudEntityParams() { FlagsEnum = MyHudIndicatorFlagsEnum.SHOW_ALL, Text = CustomName, OffsetText = true, }); } else { MyHud.LocationMarkers.UnregisterMarker(this); } } }
private void SetEmissive(Color color) { MyCubeBlock.UpdateEmissiveParts(Render.RenderObjectIDs[0], 1.0f, color, Color.White); }
public void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid, MyCubeBlock fatBlock) { ProfilerShort.Begin("SlimBlock.Init(objectBuilder, ...)"); Debug.Assert(cubeGrid != null); FatBlock = fatBlock; m_soundEmitter.Entity = FatBlock; if (objectBuilder is MyObjectBuilder_CompoundCubeBlock) BlockDefinition = MyCompoundCubeBlock.GetCompoundCubeBlockDefinition(); else BlockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId()); m_componentStack = new MyComponentStack(BlockDefinition, objectBuilder.IntegrityPercent, objectBuilder.BuildPercent); if (MyCubeGridDefinitions.GetCubeRotationOptions(BlockDefinition) == MyRotationOptionsEnum.None) { objectBuilder.BlockOrientation = MyBlockOrientation.Identity; } DeformationRatio = BlockDefinition.DeformationRatio; Min = objectBuilder.Min; Orientation = objectBuilder.BlockOrientation; if (!Orientation.IsValid) Orientation = MyBlockOrientation.Identity; Debug.Assert(Orientation.IsValid, "Orientation of block is not valid."); CubeGrid = cubeGrid; ColorMaskHSV = objectBuilder.ColorMaskHSV; if (BlockDefinition.CubeDefinition != null) { //Ensure we have always only one distinct orientation use Orientation = MyCubeGridDefinitions.GetTopologyUniqueOrientation(BlockDefinition.CubeDefinition.CubeTopology, Orientation); } ComputeMax(BlockDefinition, Orientation, ref Min, out Max); Matrix localMatrix; Orientation.GetMatrix(out localMatrix); Position = ComputePositionInGrid(ref localMatrix); UpdateShowParts(); if (FatBlock == null) { bool isRenderedAsModel = !String.IsNullOrEmpty(BlockDefinition.Model); bool showConstructionModel = BlockDefinition.BlockTopology == MyBlockTopology.Cube && !ShowParts; if (isRenderedAsModel || showConstructionModel) { FatBlock = new MyCubeBlock(); m_soundEmitter.Entity = FatBlock; } } if (FatBlock != null) { ProfilerShort.Begin("FatBlock.Init(objectBuilder, ...)"); FatBlock.SlimBlock = this; FatBlock.Init(objectBuilder, cubeGrid); ProfilerShort.End(); } if (objectBuilder.ConstructionStockpile != null) { EnsureConstructionStockpileExists(); m_stockpile.Init(objectBuilder.ConstructionStockpile); } else if (objectBuilder.ConstructionInventory != null) // Backwards compatibility { EnsureConstructionStockpileExists(); m_stockpile.Init(objectBuilder.ConstructionInventory); } if (FatBlock == null || FatBlock.GetType() == typeof(MyCubeBlock)) m_objectBuilder = new MyObjectBuilder_CubeBlock(); if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && BlockDefinition.RationEnoughForDamageEffect(Integrity / MaxIntegrity)) {//start effect if (CurrentDamage>0)//fix for weird simple blocks having FatBlock - old save? { FatBlock.SetDamageEffect(true); } } ProfilerShort.End(); }
public override void OnAddedToContainer() { base.OnAddedToContainer(); m_cubeBlock = Container.Entity as MyCubeBlock; }
void MyWarhead_IsWorkingChanged(MyCubeBlock obj) { if (IsCountingDown && !IsWorking) { StopCountdown(); } UpdateEmissivity(); }
public override int GetMaximumTargets() { MyCubeBlock block = (MyCubeBlock)m_constructionBlock.ConstructionBlock; return((int)Math.Min(NaniteConstructionManager.Settings.MiningNanitesNoUpgrade + (block.UpgradeValues["MiningNanites"] * NaniteConstructionManager.Settings.MiningNanitesPerUpgrade), NaniteConstructionManager.Settings.MiningMaxStreams)); }
public virtual void UnregisterFromSystems(MyCubeBlock block) { // Note: ResourceDistributor, WeaponSystem and TemrminalSystem can be null on closing (they are not in the ship but in the logical group). That's why they are null-checked if (ResourceDistributor != null) { ProfilerShort.Begin("Unregister Power producer"); var powerProducer = block.Components.Get<MyResourceSourceComponent>(); if (powerProducer != null) ResourceDistributor.RemoveSource(powerProducer); ProfilerShort.BeginNextBlock("Unregister Power consumer"); var powerConsumer = block.Components.Get<MyResourceSinkComponent>(); if (powerConsumer != null) ResourceDistributor.RemoveSink(powerConsumer); ProfilerShort.End(); var socketOwner = block as IMyRechargeSocketOwner; if (socketOwner != null) socketOwner.RechargeSocket.ResourceDistributor = null; } ProfilerShort.Begin("Unregister gun object"); if (WeaponSystem != null) { var weapon = block as IMyGunObject<MyDeviceBase>; if (weapon != null) WeaponSystem.Unregister(weapon); } ProfilerShort.BeginNextBlock("Unregister functional block"); if (TerminalSystem != null) { var functionalBlock = block as MyTerminalBlock; if (functionalBlock != null) TerminalSystem.Remove(functionalBlock); } // CH: We probably don't need to unregister controller blocks here. It's done in ShipController's OnUnregisteredFromGridSystems /*ProfilerShort.BeginNextBlock("Unregister controller block"); if (ControlSystem != null) { var controllableBlock = block as MyShipController; if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null) ControlSystem.RemoveControllerBlock(controllableBlock); }*/ ProfilerShort.BeginNextBlock("Unregister inventory block"); var inventoryBlock = (block != null && block.HasInventory) ? block : null ; if (inventoryBlock != null && inventoryBlock.HasInventory) ConveyorSystem.Remove(inventoryBlock); ProfilerShort.BeginNextBlock("Unregister conveyor block"); var conveyorBlock = block as IMyConveyorEndpointBlock; if (conveyorBlock != null) ConveyorSystem.RemoveConveyorBlock(conveyorBlock); ProfilerShort.BeginNextBlock("Unregister segment block"); var segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) ConveyorSystem.RemoveSegmentBlock(segmentBlock); ProfilerShort.BeginNextBlock("Unregister Reflector light"); var reflectorLight = block as MyReflectorLight; if (reflectorLight != null) ReflectorLightSystem.Unregister(reflectorLight); if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { ProfilerShort.BeginNextBlock("Unregister wheel"); var wheel = block as MyMotorSuspension; if (wheel != null) WheelSystem.Unregister(wheel); } ProfilerShort.BeginNextBlock("Unregister landing gear"); var gear = block as IMyLandingGear; if (gear != null) LandingSystem.Unregister(gear); ProfilerShort.BeginNextBlock("Unregister gyro"); var gyro = block as MyGyro; if (gyro != null) GyroSystem.Unregister(gyro); ProfilerShort.BeginNextBlock("Unregister camera"); var camera = block as MyCameraBlock; if (camera != null) CameraSystem.Unregister(camera); ProfilerShort.BeginNextBlock("block.OnUnregisteredFromGridSystems()"); block.OnUnregisteredFromGridSystems(); ProfilerShort.End(); }
public override float GetPowerUsage() { MyCubeBlock block = (MyCubeBlock)m_constructionBlock.ConstructionBlock; return(Math.Max(1, NaniteConstructionManager.Settings.MiningPowerPerStream - (int)(block.UpgradeValues["PowerNanites"] * NaniteConstructionManager.Settings.PowerDecreasePerUpgrade))); }