public MyEntity Spawn(MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner = null) { if (Content is MyObjectBuilder_BlockItem) { Debug.Assert(MyFixedPoint.IsIntegral(amount), "Spawning fractional number of grids!"); var blockItem = Content as MyObjectBuilder_BlockItem; var builder = MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid; builder.GridSizeEnum = MyCubeSize.Small; builder.IsStatic = false; builder.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; builder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); var block = MyObjectBuilderSerializer.CreateNewObject(blockItem.BlockDefId) as MyObjectBuilder_CubeBlock; builder.CubeBlocks.Add(block); MyCubeGrid firstGrid = null; for (int i = 0; i < amount; ++i) { builder.EntityId = MyEntityIdentifier.AllocateId(); block.EntityId = MyEntityIdentifier.AllocateId(); MyCubeGrid newGrid = MyEntities.CreateFromObjectBuilder(builder) as MyCubeGrid; firstGrid = firstGrid ?? newGrid; MyEntities.Add(newGrid); Sandbox.Game.Multiplayer.MySyncCreate.SendEntityCreated(builder); } return firstGrid; } else return MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount, Content),worldMatrix, owner != null ? owner.Physics : null); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory; float percent = MathHelper.Clamp((int)Math.Floor(110 - ((float)inventory.CurrentVolume / (float)inventory.MaxVolume * 100f)), 10, 100); terminalBlock.CustomData = "Efficiency: " + percent + "%"; while (new Random().Next(0, 100) < percent) { VRage.MyFixedPoint amount = (VRage.MyFixedPoint)(0.01); inventory.AddItems(amount, new MyObjectBuilder_Ingot() { SubtypeName = "UnstableMatter" }); terminalBlock.RefreshCustomInfo(); percent *= 0.3f; } if (new Random().Next(0, 30000) < 1) { inventory.AddItems((VRage.MyFixedPoint)(1), new MyObjectBuilder_Component() { SubtypeName = "SpecialTech" }); terminalBlock.RefreshCustomInfo(); } }
public static MyEntity Spawn(this MyPhysicalInventoryItem thisItem, MyFixedPoint amount, BoundingBoxD box, MyEntity owner = null) { if(amount < 0) { return null; } MatrixD spawnMatrix = MatrixD.Identity; spawnMatrix.Translation = box.Center; var entity = Spawn(thisItem, amount, spawnMatrix, owner); if (entity == null) return null; var size = entity.PositionComp.LocalVolume.Radius; var halfSize = box.Size / 2 - new Vector3(size); halfSize = Vector3.Max(halfSize, Vector3.Zero); box = new BoundingBoxD(box.Center - halfSize, box.Center + halfSize); var pos = MyUtils.GetRandomPosition(ref box); Vector3 forward = MyUtils.GetRandomVector3Normalized(); Vector3 up = MyUtils.GetRandomVector3Normalized(); while (forward == up) up = MyUtils.GetRandomVector3Normalized(); Vector3 right = Vector3.Cross(forward, up); up = Vector3.Cross(right, forward); entity.WorldMatrix = MatrixD.CreateWorld(pos, forward, up); return entity; }
public MyInventoryItem(MyFixedPoint amount, MyObjectBuilder_PhysicalObject content) { Debug.Assert(amount > 0, "Creating inventory item with zero amount!"); ItemId = 0; Amount = amount; Content = content; }
public MyInventoryItem(MyObjectBuilder_InventoryItem item) { Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!"); ItemId = 0; Amount = item.Amount; Content = item.PhysicalContent; }
private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false) { var cGun = gun; Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0); VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); if (point.RawValue > 1000000) return; //inv.Clear(); VRage.MyFixedPoint amount = new VRage.MyFixedPoint(); amount.RawValue = 2000000; MyObjectBuilder_InventoryItem ii; if (reactor) { ii = new MyObjectBuilder_InventoryItem() { Amount = 10, Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName } }; } else { ii = new MyObjectBuilder_InventoryItem() { Amount = 4, Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName } }; } inv.AddItems(amount, ii.PhysicalContent); point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); }
public MyRepairBlueprintToProduce(MyFixedPoint amount, MyBlueprintDefinitionBase blueprint, uint inventoryItemId, MyObjectBuilderType inventoryItemType, MyStringHash inventoryItemSubtypeId) : base(amount, blueprint) { System.Diagnostics.Debug.Assert(Blueprint is MyRepairBlueprintDefinition, "MyRepairBlueprintToProduce class should be used together with blueprints type of MyRepairBlueprintDefinition only!"); InventoryItemId = inventoryItemId; InventoryItemType = inventoryItemType; InventoryItemSubtypeId = inventoryItemSubtypeId; }
void Main() { // initialize VRage.MyFixedPoint totalVolume = 0; VRage.MyFixedPoint totalMaxVolume = 0; var blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyInventoryOwner>(blocks, FilterInventoryOwner); if (blocks.Count == 0) { throw new Exception("Did not find any cargo container."); } for (int i = 0; i < blocks.Count; ++i) { var invOwner = blocks[i] as IMyInventoryOwner; for (int j = 0; j < invOwner.InventoryCount; ++j) { var inv = invOwner.GetInventory(j); totalVolume += inv.CurrentVolume; totalMaxVolume += inv.MaxVolume; } } blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyBeacon>(blocks, FilterAntenna); GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(blocks, FilterAntenna); if (blocks.Count == 0) { throw new Exception("Did not find the specified antenna"); } var antenna = blocks[0]; StringBuilder sb = new StringBuilder(); sb.Append(antennaName).Append(" - "); sb.Append((long)(totalVolume * K)).Append(" / ").Append((long)(totalMaxVolume * K)); sb.Append(" (").Append(VRageMath.MathHelper.RoundOn2(100 * (float)(totalVolume * K) / (float)(totalMaxVolume * K))).Append("%)"); //antenna.SetCustomName(sb.ToString()); if (totalVolume == totalMaxVolume) { IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(stop); if (block == null) { throw new Exception("Could not find block with name: '" + stop + "'"); } block.SetCustomName(block.CustomName + "full,"); block.ApplyAction("Run"); } Echo(sb.ToString()); debug.Clear(); }
public MyInventory(MyFixedPoint maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) { m_maxVolume = MyPerGameSettings.ConstrainInventory() ? maxVolume * MySession.Static.InventoryMultiplier : MyFixedPoint.MaxValue; m_size = size; m_flags = flags; m_owner = owner; Clear(); SyncObject = new MySyncInventory(); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsWorking) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; //if (!inventory.ContainItems(amount, new MyObjectBuilder_PhysicalGunObject { SubtypeName = "AutomaticRifleItem" })) //{ // inventory.AddItems(amount, new MyObjectBuilder_PhysicalGunObject { SubtypeName = "AutomaticRifleItem" }); // terminalBlock.RefreshCustomInfo(); //} //if (!inventory.ContainItems(amount, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_5p56x45mm" })) //{ // inventory.AddItems(10, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_5p56x45mm" }); // terminalBlock.RefreshCustomInfo(); //} //if (!inventory.ContainItems(10000, new MyObjectBuilder_Ore { SubtypeName = "Iron" })) //{ // inventory.AddItems(amount, new MyObjectBuilder_Ore { SubtypeName = "Iron" }); // terminalBlock.RefreshCustomInfo(); //} float cur = (float)inventory.CurrentVolume; float max = (float)inventory.MaxVolume; if (cur / max < 0.9 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply" }); BlackShop.AddSupply(inventory); terminalBlock.RefreshCustomInfo(); } if (cur / max < 0.9 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply2" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply2" }); BlackShop.AddSupply(inventory, true); terminalBlock.RefreshCustomInfo(); } } }
public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) { m_maxVolume = maxVolume; m_maxMass = maxMass; m_size = size; m_flags = flags; m_owner = owner; Clear(); SyncObject = new MySyncInventory(); //ContentsChanged += OnContentsChanged; }
/// <summary> /// Transfers safely given item from one to another inventory, uses ItemsCanBeAdded and ItemsCanBeRemoved checks /// </summary> /// <returns>true if items were succesfully transfered, otherwise, false</returns> public static bool TransferItems(MyInventoryBase sourceInventory, MyInventoryBase destinationInventory, IMyInventoryItem item, MyFixedPoint amount) { if (sourceInventory == null) { System.Diagnostics.Debug.Fail("Source inventory is null!"); return false; } if (destinationInventory == null) { System.Diagnostics.Debug.Fail("Destionation inventory is null!"); return false; } if (item == null) { System.Diagnostics.Debug.Fail("Item is null!"); return false; } if (amount == 0) { return true; } if (destinationInventory.ItemsCanBeAdded(amount, item) && sourceInventory.ItemsCanBeRemoved(amount, item)) { if (Sync.IsServer) { if (destinationInventory.Add(item, amount)) { if (sourceInventory.Remove(item, amount)) { // successfull transaction return true; } else { System.Diagnostics.Debug.Fail("Error! Items were added to inventory, but can't be removed!"); } } } else { MySyncInventory.SendTransferItemsMessage(sourceInventory, destinationInventory, item, amount); } } return false; }
private void PostprocessAddSubblueprint(MyBlueprintDefinitionBase blueprint, MyFixedPoint blueprintAmount) { for (int i = 0; i < blueprint.Prerequisites.Length; ++i) { Item prerequisite = blueprint.Prerequisites[i]; prerequisite.Amount *= blueprintAmount; AddToItemList(m_tmpPrerequisiteList, prerequisite); } for (int i = 0; i < blueprint.Results.Length; ++i) { Item result = blueprint.Results[i]; result.Amount *= blueprintAmount; AddToItemList(m_tmpResultList, result); } }
private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false) { var cGun = gun; Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0); VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); if (point.RawValue > 1000000) { return; } //inv.Clear(); VRage.MyFixedPoint amount = new VRage.MyFixedPoint(); amount.RawValue = 2000000; MyObjectBuilder_InventoryItem ii; if (reactor) { ii = new MyObjectBuilder_InventoryItem() { Amount = 10, Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName } }; } else { ii = new MyObjectBuilder_InventoryItem() { Amount = 4, Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName } }; } inv.AddItems(amount, ii.PhysicalContent); point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); }
public MyEntity Spawn(MyFixedPoint amount, BoundingBoxD box, MyEntity owner = null) { var entity = Spawn(amount, MatrixD.Identity, owner); var size = entity.PositionComp.LocalVolume.Radius; var halfSize = box.Size / 2 - new Vector3(size); halfSize = Vector3.Max(halfSize, Vector3.Zero); box = new BoundingBoxD(box.Center - halfSize, box.Center + halfSize); var pos = MyUtils.GetRandomPosition(ref box); Vector3 forward = MyUtils.GetRandomVector3Normalized(); Vector3 up = MyUtils.GetRandomVector3Normalized(); while (forward == up) up = MyUtils.GetRandomVector3Normalized(); Vector3 right = Vector3.Cross(forward, up); up = Vector3.Cross(right, forward); entity.WorldMatrix = MatrixD.CreateWorld(pos, forward, up); return entity; }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsFunctional) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; if (!inventory.ContainItems(10000, new MyObjectBuilder_Ore { SubtypeName = "Iron" })) { inventory.AddItems(5, new MyObjectBuilder_Ore { SubtypeName = "Iron" }); terminalBlock.RefreshCustomInfo(); } } }
public MyEntity Spawn(MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner = null) { if(Content is MyObjectBuilder_BlockItem) { var blockItem = Content as MyObjectBuilder_BlockItem; var builder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid; builder.EntityId = MyEntityIdentifier.AllocateId(); builder.GridSizeEnum = MyCubeSize.Small; builder.IsStatic = false; builder.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; builder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); var block = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(blockItem.BlockDefId) as MyObjectBuilder_CubeBlock; builder.CubeBlocks.Add(block); var newGrid = MyEntities.CreateFromObjectBuilder(builder) as MyCubeGrid; MyEntities.Add(newGrid); Sandbox.Game.Multiplayer.MySyncCreate.SendEntityCreated(builder); return newGrid; } else return MyFloatingObjects.Spawn(new MyInventoryItem(amount, Content),worldMatrix, owner != null ? owner.Physics : null); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsFunctional) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; float cur = (float)inventory.CurrentVolume; float max = (float)inventory.MaxVolume; if (cur / max < 0.8 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "RandomItem" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "RandomItem" }); RandomShop.AddRandomItem(inventory); terminalBlock.RefreshCustomInfo(); } } }
public override void UpdateBeforeSimulation100() { w_density = atmoDet.AtmosphereDetectionVaporator(this.Entity); IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; //check to see if the block is on if (m_vaporator.Enabled && m_vaporator.IsWorking && m_vaporator.IsFunctional) { try { var sink = Entity.Components.Get <MyResourceSinkComponent>(); poweruse = 0.4f * (1f + m_vaporator.UpgradeValues["Productivity"]) * (1f / m_vaporator.UpgradeValues["PowerEfficiency"]); if (sink != null) { sink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, poweruse); } } catch (Exception e) { MyAPIGateway.Utilities.ShowNotification("[ Error in " + GetType().FullName + ": " + e.Message + " ]", 10000, MyFontEnum.Red); MyLog.Default.WriteLine(e); } //m_vaporator.PowerConsumptionMultiplier = 10 * (1f + m_vaporator.UpgradeValues["Productivity"]) * (1f / m_vaporator.UpgradeValues["PowerEfficiency"]); VRage.MyFixedPoint amount = (VRage.MyFixedPoint)(0.2 * (w_density * m_vaporator.UpgradeValues["Effectiveness"]) * (1 + m_vaporator.UpgradeValues["Productivity"])); inventory.AddItems(amount, new MyObjectBuilder_Ore() { SubtypeName = "Ice" }); } terminalBlock.RefreshCustomInfo(); base.UpdateBeforeSimulation100(); }
private bool CheckInventoryContents(MyInventory inventory, MyBlueprintDefinitionBase.Item item, MyFixedPoint amountMultiplier) { return inventory.ContainItems(item.Amount * amountMultiplier, item.Id); }
private bool CheckInventoryCapacity(MyInventory inventory, MyBlueprintDefinitionBase.Item[] items, MyFixedPoint amountMultiplier) { if (MySession.Static.CreativeMode) return true; MyFixedPoint resultVolume = 0; foreach (var item in items) { var def = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Id); resultVolume += (MyFixedPoint)def.Volume * item.Amount * amountMultiplier; } return inventory.CurrentVolume + resultVolume <= inventory.MaxVolume; }
private bool CheckInventoryCapacity(MyInventory inventory, MyBlueprintDefinitionBase.Item item, MyFixedPoint amountMultiplier) { return inventory.CanItemsBeAdded(item.Amount * amountMultiplier, item.Id); }
public static MyFixedPoint Round(MyFixedPoint a) { a.RawValue = (a.RawValue + Divider / 2) / Divider; return a; }
public static MyFixedPoint Min(MyFixedPoint a, MyFixedPoint b) { return a < b ? a : b; }
public static MyFixedPoint Ceiling(MyFixedPoint a) { a.RawValue = ((a.RawValue + Divider - 1) / Divider) * Divider; return a; }
protected override void InsertQueueItem(int idx, MyBlueprintDefinitionBase blueprint, MyFixedPoint amount) { if (idx == 0) { var queueItem = TryGetFirstQueueItem(); if (queueItem.HasValue && queueItem.Value.Blueprint != blueprint) CurrentProgress = 0f; } base.InsertQueueItem(idx, blueprint, amount); }
private bool CheckInventoryContents(MyInventory inventory, MyBlueprintDefinitionBase.Item[] item, MyFixedPoint amountMultiplier) { for (int i = 0; i < item.Length; ++i) { if (!inventory.ContainItems(item[i].Amount * amountMultiplier, item[i].Id)) return false; } return true; }
public static MyFixedPoint Floor(MyFixedPoint a) { a.RawValue = (a.RawValue / Divider) * Divider; return(a); }
public static MyFixedPoint Min(MyFixedPoint a, MyFixedPoint b) { return(a < b ? a : b); }
public static MyFixedPoint AddSafe(MyFixedPoint a, MyFixedPoint b) { return(new MyFixedPoint(AddSafeInternal(a.RawValue, b.RawValue))); }
public static MyFixedPoint Max(MyFixedPoint a, MyFixedPoint b) { return(a > b ? a : b); }
public static MyFixedPoint Round(MyFixedPoint a) { a.RawValue = (a.RawValue + Divider / 2) / Divider; return(a); }
protected override void RemoveFirstQueueItem(MyFixedPoint amount, float progress = 0f) { CurrentProgress = progress; base.RemoveFirstQueueItem(amount); }
public void Main(string argument, UpdateType updateSource) { foreach (IMyTerminalBlock _container in cargoContainers) { maxCargoVolume += _container.GetInventory().MaxVolume; currentCargoVolume += _container.GetInventory() .CurrentVolume; //Detect add use amount of total and used space in each container //Max cargo example when Inventory x1: // 2x Connectors a 1152 L // 3x MedCargoConts a 3375 L // 2x Drills a 3375 L // 2x Ejectors a 64 L // TOTAL a 19307 L } double cargoSpace = ((double)currentCargoVolume / (double)maxCargoVolume * 100); //Percentage of used space //BRAKING DISTANCE AND BRAKING TIME: totalMass = (controlBlock as IMyShipController).CalculateShipMass().TotalMass; currentSpeed = (controlBlock as IMyShipController).GetShipSpeed(); maxAcceleration = reverseThrustersForce / totalMass; brakingTime = (float)currentSpeed / maxAcceleration; brakingDistance = (maxAcceleration * brakingTime * brakingTime) / 2; //INFO PANEL if ((controlBlock as IMyCockpit).IsUnderControl == true) //Works when pilot onboard { //if (currentSpeed < 2 ) sbInfo.Append(" CHECK OXYGEN + EOL + BOTTLES ONBOARD"); if (cargoSpace > 0.5) { sbInfo.Append(" Cargo Load: " + Math.Round(cargoSpace, 2) + " %" + EOL); greeting = false; } if (currentSpeed > 2) { sbInfo.Append(" Until stop: " + Math.Round(brakingTime) + " s. " + Math.Round(brakingDistance) + " m." + EOL); greeting = false; } if (currentSpeed < 2 && cargoSpace <= 0.5 && greeting == true) { sbInfo.Append(" ALL SYSTEMS ONLINE" + EOL + " CHECK OXYGEN" + EOL + " BOTTLES ONBOARD"); } } //DEBUG PANEL sbDebug.Append(" Reverse thrusters amount: " + reverseIonThrusters.Count + EOL); sbDebug.Append(" Braking force, N = " + reverseThrustersForce + " N " + EOL); sbDebug.Append(" Mass, kg: " + totalMass + EOL); sbDebug.Append(" Speed, m/s: " + currentSpeed + EOL); sbDebug.Append(" Acceleration, m/ss: " + maxAcceleration + EOL + EOL); sbDebug.Append(" Containers: " + cargoContainers.Count + EOL); // amount of objects in list sbDebug.Append(" MaxVolume: " + maxCargoVolume.ToString() + EOL); sbDebug.Append(" CurrentVolume: " + currentCargoVolume.ToString() + EOL); sbDebug.Append(" Cargo: " + Math.Round(cargoSpace, 2) + " %" + EOL); sbDebug.Append(" "); sbDebug.Append(" "); sbDebug.Append(" "); //Zeroing values after this tick maxCargoVolume = 0; currentCargoVolume = 0; cargoSpace = 0; if ((controlBlock as IMyCockpit).IsUnderControl == false) { greeting = true; } if (infoLcd != null) //Solving exception during LCD identification by tag. If no LCD found, keep working { infoLcd.WritePublicText(sbInfo.ToString(), REWRITE); //What to write: sbInfo turned into text infoLcd.ShowPublicTextOnScreen(); //Show text on debugLcd_0 sbInfo.Clear(); //Remove everything was displayed by sbInfo in this tick and write again in the next tick } else { Echo("No Info LCD found" + EOL + "See README part of code"); } if (debugLcd != null) //Solving exception during LCD identification by tag. If no LCD found, keep working { debugLcd.WritePublicText(sbDebug.ToString(), REWRITE); //What to write: sbDebug turned into text debugLcd.ShowPublicTextOnScreen(); //Show text on debugLcd_0 sbDebug.Clear(); //Remove everything was displayed by sbDebug in this tick and write again in the next tick } }
public static bool IsIntegral(MyFixedPoint fp) { return fp.RawValue % Divider == 0; }
public override ChangeInfo Update(MyEntity owner, long playerID = 0) { ChangeInfo changed = ChangeInfo.None; bool enable = true; if (MyCubeBuilder.Static == null) return changed; var blockDefinition = MyCubeBuilder.Static.IsActivated ? MyCubeBuilder.Static.ToolbarBlockDefinition : null; var blockDef = (this.Definition as Sandbox.Definitions.MyCubeBlockDefinition); if ((MyCubeBuilder.Static.BlockCreationIsActivated || MyCubeBuilder.Static.MultiBlockCreationIsActivated) && blockDefinition != null && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle)) { if (blockDefinition.BlockPairName == blockDef.BlockPairName) { WantsToBeSelected = true; } else if (blockDef.BlockStages != null && blockDef.BlockStages.Contains(blockDefinition.Id)) { WantsToBeSelected = true; } else { WantsToBeSelected = false; } } else { WantsToBeSelected = false; } var character = MySession.Static.LocalCharacter; if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID) { if (blockDef.CubeSize == MyCubeSize.Small && character != null) { var inventory = character.GetInventory(); MyFixedPoint amount = inventory != null ? inventory.GetItemAmount(Definition.Id) : 0; if (m_lastAmount != amount) { m_lastAmount = amount; changed |= ChangeInfo.IconText; } if (MySession.Static.SurvivalMode) { enable &= m_lastAmount > 0; } else { // so that we correctly set icontext when changing from enabled to disabled even when the amount is the same changed |= ChangeInfo.IconText; } } } if (MyPerGameSettings.EnableResearch && MySessionComponentResearch.Static != null && (blockDef.CubeSize == MyCubeSize.Large)) enable &= MySessionComponentResearch.Static.CanUse(character, Definition.Id); changed |= SetEnabled(enable); return changed; }
public static MyFixedPoint Floor(MyFixedPoint a) { a.RawValue = (a.RawValue / Divider) * Divider; return a; }
public static bool IsIntegral(MyFixedPoint fp) { return(fp.RawValue % Divider == 0); }
public static MyFixedPoint Max(MyFixedPoint a, MyFixedPoint b) { return a > b ? a : b; }
public static MyFixedPoint MultiplySafe(int a, MyFixedPoint b) { return(MultiplySafe((MyFixedPoint)a, b)); }
public void Consume(MyFixedPoint amount, MyConsumableItemDefinition definition) { if (definition == null) return; MyEntityStat stat; var regenEffect = new MyObjectBuilder_EntityStatRegenEffect(); regenEffect.Interval = 1.0f; regenEffect.MaxRegenRatio = 1.0f; regenEffect.MinRegenRatio = 0.0f; foreach (var statValue in definition.Stats) { if (Stats.TryGetValue(MyStringHash.GetOrCompute(statValue.Name), out stat)) { regenEffect.TickAmount = statValue.Value*(float)amount; regenEffect.Duration = statValue.Time; stat.AddEffect(regenEffect); } } }
public bool CheckConveyorResources(MyFixedPoint? amount, MyDefinitionId contentId) { foreach (var inv in m_inventoryOwners) { if (inv != null && inv is IMyInventoryOwner) { var cargo = inv as IMyInventoryOwner; var flags = cargo.GetInventory(0).GetFlags(); var flag = MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive; List<MyInventory> inventories = new List<MyInventory>(); for (int i = 0; i < cargo.InventoryCount; i++) { inventories.Add(cargo.GetInventory(i)); } foreach(var inventory in inventories) { if (inventory.ContainItems(amount, contentId) && ((flags == flag || flags == MyInventoryFlags.CanSend) || cargo == this)) { return true; } } } } return false; }
public static MyFixedPoint Ceiling(MyFixedPoint a) { a.RawValue = ((a.RawValue + Divider - 1) / Divider) * Divider; return(a); }
private void RemoveItemsAt_Request(int itemIndex, MyFixedPoint? amount = null, bool sendEvent = true, bool spawn = false, MatrixD? spawnPos = null) { RemoveItemsAt(itemIndex, amount, sendEvent, spawn, spawnPos); }
public MyEntity RemoveItems(uint itemId, MyFixedPoint? amount = null, bool sendEvent = true, bool spawn = false, MatrixD? spawnPos = null) { var item = GetItemByID(itemId); var am = amount.HasValue ? amount.Value : (item.HasValue ? item.Value.Amount : 1); MyEntity spawned = null; if (Sync.IsServer) { if (item.HasValue && RemoveItemsInternal(itemId, am, sendEvent)) { if (spawn) { MyEntity owner; if (Owner is MyEntity) { owner = Owner as MyEntity; } else { owner = Container.Entity as MyEntity; } if (!spawnPos.HasValue) spawnPos = MatrixD.CreateWorld(owner.PositionComp.GetPosition() + owner.PositionComp.WorldMatrix.Forward + owner.PositionComp.WorldMatrix.Up, owner.PositionComp.WorldMatrix.Forward, owner.PositionComp.WorldMatrix.Up); spawned = item.Value.Spawn(am, spawnPos.Value, owner); if (spawned != null && spawnPos.HasValue) { if (owner == MySession.Static.LocalCharacter) { MyGuiAudio.PlaySound(MyGuiSounds.PlayDropItem); } else { MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter(); if (emitter != null) { emitter.SetPosition(spawnPos.Value.Translation); emitter.PlaySound(dropSound); } } } } } } return spawned; }
public static MyFixedPoint MultiplySafe(MyFixedPoint a, int b) { return(MultiplySafe(a, (MyFixedPoint)b)); }
private void ChangeRequirementsToResults(MyBlueprintDefinitionBase queueItem, MyFixedPoint blueprintAmount) { Debug.Assert(Sync.IsServer); if (!MySession.Static.CreativeMode) { blueprintAmount = MyFixedPoint.Min(OutputInventory.ComputeAmountThatFits(queueItem), blueprintAmount); } if (blueprintAmount == 0) return; foreach (var prerequisite in queueItem.Prerequisites) { var obPrerequisite = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(prerequisite.Id); var prerequisiteAmount = blueprintAmount * prerequisite.Amount; InputInventory.RemoveItemsOfType(prerequisiteAmount, obPrerequisite); } foreach (var result in queueItem.Results) { var resultId = result.Id; var obResult = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(resultId); var conversionRatio = result.Amount * m_refineryDef.MaterialEfficiency * UpgradeValues["Effectiveness"]; if (conversionRatio > (MyFixedPoint)1.0f) { conversionRatio = (MyFixedPoint)1.0f; } var resultAmount = blueprintAmount * conversionRatio; OutputInventory.AddItems(resultAmount, obResult); } RemoveFirstQueueItemAnnounce(blueprintAmount); }
void Main() { // initialize VRage.MyFixedPoint totalVolume = 0; VRage.MyFixedPoint totalMaxVolume = 0; var blocks = new List <IMyTerminalBlock>(); if (ejectors == null) { ejectors = new List <IMyShipConnector>(); GridTerminalSystem.GetBlocksOfType <IMyShipConnector>(blocks, FilterEjector); if (ejectors.Count == 0) { GridTerminalSystem.GetBlocksOfType <IMyShipConnector>(blocks); } for (int i = 0; i < blocks.Count; ++i) { ejectors.Add(blocks[i] as IMyShipConnector); } } if (drills == null) { drills = new List <IMyShipDrill>(); GridTerminalSystem.GetBlocksOfType <IMyShipDrill>(blocks); for (int i = 0; i < blocks.Count; ++i) { drills.Add(blocks[i] as IMyShipDrill); } } GridTerminalSystem.GetBlocksOfType <IMyInventoryOwner>(blocks, FilterInventoryOwner); if (blocks.Count == 0) { throw new Exception("Did not find any cargo container."); } for (int i = 0; i < ejectors.Count; ++i) { var invOwner = ejectors[i] as IMyInventoryOwner; IMyInventory inv = invOwner.GetInventory(0); var items = inv.GetItems(); for (int j = 0; j < items.Count; ++j) { IMyInventoryItem item = items[j]; if (item.Content.TypeId == ORE && item.Content.SubtypeName.Equals("Stone")) { continue; } VRage.MyFixedPoint amount = item.Amount; for (int k = 0; k < drills.Count; ++k) { var connInv = ((IMyInventoryOwner)drills[k]).GetInventory(0); VRage.MyFixedPoint available = connInv.MaxVolume - connInv.CurrentVolume; if (available < 0) { continue; } debug.Append("available = ").Append(available).AppendLine(); debug.Append("amount = ").Append(item.Amount).AppendLine(); VRage.MyFixedPoint transAmount = VRage.MyFixedPoint.Min(available * 3 * K, item.Amount); if (inv.TransferItemTo(connInv, j, connInv.GetItems().Count, true, transAmount)) { amount -= transAmount; } if (amount <= 0) { break; } } } } for (int i = 0; i < blocks.Count; ++i) { var invOwner = blocks[i] as IMyInventoryOwner; for (int j = 0; j < invOwner.InventoryCount; ++j) { var inv = invOwner.GetInventory(j); totalVolume += inv.CurrentVolume; totalMaxVolume += inv.MaxVolume; var items = inv.GetItems(); for (int k = 0; k < items.Count; ++k) { var item = items[k]; if (item.Content.TypeId == ORE && item.Content.SubtypeName.Equals("Stone")) { for (int l = 0; l < ejectors.Count; ++l) { if (!ejectors[l].Enabled) { continue; } var connInv = ((IMyInventoryOwner)ejectors[l]).GetInventory(0); VRage.MyFixedPoint available = connInv.MaxVolume - connInv.CurrentVolume; inv.TransferItemTo(connInv, k, 0, true, amount: VRage.MyFixedPoint.Min(available, item.Amount) * 3 * K); } } } } } for (int l = 0; l < ejectors.Count; ++l) { var ejector = ejectors[l]; if (!ejector.Enabled) { continue; } var connInv = ((IMyInventoryOwner)ejector).GetInventory(0); var items = connInv.GetItems(); if (items.Count == 0) { if (ejector.ThrowOut) { ejector.GetActionWithName("ThrowOut").Apply(ejector); } continue; } var item = items[0]; if (item.Content.TypeId == ORE && item.Content.SubtypeName.Equals("Stone") && !ejector.ThrowOut || (item.Content.TypeId != ORE || !item.Content.SubtypeName.Equals("Stone")) && ejector.ThrowOut) { ejector.GetActionWithName("ThrowOut").Apply(ejector); } } blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyBeacon>(blocks, FilterAntenna); if (blocks.Count == 0) { GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(blocks, FilterAntenna); } if (blocks.Count == 0) { throw new Exception("Did not find the specified antenna"); } var antenna = blocks[0]; StringBuilder sb = new StringBuilder(); sb.Append(antennaName).Append(" - "); sb.Append((long)(totalVolume * K)).Append(" / ").Append((long)(totalMaxVolume * K)); sb.Append(" (").Append(VRageMath.MathHelper.RoundOn2(100 * (float)(totalVolume * K) / (float)(totalMaxVolume * K))).Append("%)"); antenna.SetCustomName(sb.ToString()); // stop condition for (int i = 0; i < drills.Count; ++i) { var drillInv = (drills[i] as IMyInventoryOwner).GetInventory(0); if (drillInv.IsFull) { stopDrill(); break; } } Debug(debug.ToString()); debug.Clear(); }