[HarmonyPriority(-10000)] // Extremely low priority. We want this to happen last, since this will only overwrite RotatablePump results public static void Postfix(Pump __instance, ref bool __result, Element.State expected_state) { if (__instance is RotatablePump) { Rotatable rotatable = __instance.GetComponent <Rotatable>(); RotatableElementConsumer consumer = __instance.GetComponent <RotatableElementConsumer>(); //Debug.Log("IsPumpable call " + consumer.rotatableCellOffset + ", " + consumer.sampleCellOffset); // Basically a copy of vanilla Pump IsPumpable, but with different initial int num = Grid.PosToCell(__instance.transform.GetPosition() + Rotatable.GetRotatedOffset(consumer.rotatableCellOffset, rotatable.GetOrientation())); for (int i = 0; i < consumer.consumptionRadius; i++) { for (int j = 0; j < consumer.consumptionRadius; j++) { int num2 = num + j + Grid.WidthInCells * i; bool flag = Grid.Element[num2].IsState(expected_state); if (flag) { __result = true; return; } } } __result = false; return; } }
/// <summary> /// A fixed version of Pump.IsPumpable that matches the detect and absorb radii. /// </summary> /// <param name="pump">The pump which will be pumping the material.</param> /// <param name="state">The element state to pump.</param> /// <param name="element">The element to pump, or SimHashes.Vacuum to pump any /// element.</param> /// <param name="radius">The pump radius.</param> /// <returns>true if there is matching material to pump, or false otherwise.</returns> protected static bool IsPumpableFixed(GameObject pump, Element.State state, SimHashes element, int radius) { bool hasMatch = false; if (radius < 1) { throw new ArgumentException("radius"); } int offset = Math.Max(0, radius - 1), diameter = 2 * radius - 1; // Adjust for larger than radius 1 (same tile) or 2 (2x2) int baseCell = Grid.PosToCell(pump); if (offset > 0) { baseCell = Grid.OffsetCell(baseCell, new CellOffset(-offset, -offset)); } for (int i = 0; i < diameter && !hasMatch; i++) { for (int j = 0; j < diameter && !hasMatch; j++) { int cell = baseCell + j + Grid.WidthInCells * i; // Added this valid cell check to avoid pumping off the map if (Grid.IsValidCell(cell) && Math.Abs(i - offset) + Math.Abs(j - offset) <= offset) { var ge = Grid.Element[cell]; hasMatch = ge.IsState(state) && (element == SimHashes.Vacuum || element == ge.id); } } } return(hasMatch); }
private bool IsPumpable(Element.State expected_state, int radius) { int cell; if (DrainOptions.Instance.UseSolidDrain) { cell = Grid.CellAbove(Grid.PosToCell(transform.GetPosition())); } else { cell = Grid.PosToCell(transform.GetPosition()); } for (var index1 = 0; index1 < (int)consumer.consumptionRadius; ++index1) { for (var index2 = 0; index2 < (int)consumer.consumptionRadius; ++index2) { var index3 = cell + index2 + Grid.WidthInCells * index1; if (Grid.Element[index3].IsState(expected_state)) { return(true); } } } return(false); }
public static Substance CreateRegisteredSubstance(string name, Element.State state, KAnimFile kanim, Material material, Color32 colour) { Substance result = CreateSubstance(name, state, kanim, material, colour); SimHashUtil.RegisterSimHash(result.elementID, name); if (!substanceList.ContainsKey(result.elementID)) { substanceList.Add(result.elementID, result); } return(result); }
/// <summary> /// Gets the default <see cref="KAnimFile"/> for a given <see cref="Element.State"/>. /// </summary> /// <param name="state">The state</param> /// <param name="substanceTable">The table of vanilla substances</param> /// <returns>The anim</returns> public static KAnimFile GetDefaultKAnimForState(Element.State state, SubstanceTable substanceTable) { switch (state) { case Element.State.Liquid: return(substanceTable.GetSubstance(SimHashes.Water).anim); case Element.State.Gas: return(substanceTable.GetSubstance(SimHashes.Hydrogen).anim); default: return(substanceTable.GetSubstance(SimHashes.Unobtanium).anim); } }
/// <summary> /// Gets the base material for a given <see cref="Element.State"/> /// </summary> /// <param name="state">The state</param> /// <param name="substanceTable">The table of vanilla substances</param> /// <returns>The material (which can be null)</returns> public static Material GetBaseMaterialForState(Element.State state, SubstanceTable substanceTable) { switch (state) { case Element.State.Liquid: return(substanceTable.liquidMaterial); case Element.State.Solid: return(substanceTable.solidMaterial); default: return(null); } }
/// <summary> /// Checks for pumpable media of the right type in the pump's radius. /// /// This version has the detect radius synchronized with the absorb radius. /// </summary> /// <param name="state">The media state required.</param> /// <param name="radius">The radius to check.</param> /// <returns>Whether the pump can run.</returns> protected override bool IsPumpable(Element.State state, int radius) { var element = ElementLoader.GetElementID(filterable.SelectedTag); bool validElement = element != SimHashes.Void && element != SimHashes.Vacuum; // Force sim update if the element changed if (validElement && element != lastElement) { consumer.elementToConsume = element; RecreateSimHandle(); consumer.RefreshConsumptionRate(); lastElement = element; } return(validElement && IsPumpableFixed(gameObject, state, element, radius)); }
private bool IsPumpable(Element.State expected_state, int radius) { int num = Grid.PosToCell(base.transform.GetPosition()); for (int i = 0; i < consumer.consumptionRadius; i++) { for (int j = 0; j < consumer.consumptionRadius; j++) { int num2 = num + j + Grid.WidthInCells * i; if (Grid.Element[num2].IsState(expected_state)) { return(true); } } } return(false); }
private bool IsPumpable(Element.State expected_state, int radius) { var cell = Grid.PosToCell(transform.GetPosition()); for (var index1 = 0; index1 < (int)consumer.consumptionRadius; ++index1) { for (var index2 = 0; index2 < (int)consumer.consumptionRadius; ++index2) { var index3 = cell + index2 + Grid.WidthInCells * index1; if (Grid.Element[index3].IsState(expected_state)) { return(true); } } } return(false); }
private bool UpdatePumpOperational() { Element.State expected_state = Element.State.Vacuum; switch (conduitType) { case ConduitType.Gas: expected_state = Element.State.Gas; break; case ConduitType.Liquid: expected_state = Element.State.Liquid; break; } bool flag = IsPumpable(expected_state); noElementStatusGuid = selectable.ToggleStatusItem(expected_state != Element.State.Gas ? Db.Get().BuildingStatusItems.NoLiquidElementToPump : Db.Get().BuildingStatusItems.NoGasElementToPump, noElementStatusGuid, !flag, null); operational.SetFlag(FanInFlag, flag); return(flag); }
private bool UpdateOperational() { Element.State state = Element.State.Vacuum; switch (dispenser.conduitType) { case ConduitType.Gas: state = Element.State.Gas; break; case ConduitType.Liquid: state = Element.State.Liquid; break; } bool flag = IsPumpable(state, consumer.consumptionRadius); StatusItem status_item = (state != Element.State.Gas) ? Db.Get().BuildingStatusItems.NoLiquidElementToPump : Db.Get().BuildingStatusItems.NoGasElementToPump; selectable.ToggleStatusItem(status_item, !flag, null); operational.SetFlag(PumpableFlag, !storage.IsFull() && flag); return(flag); }
/// <summary> /// Checks for pumpable media of the right type in the pump's radius. /// /// This version has the detect radius synchronized with the absorb radius. /// </summary> /// <param name="state">The media state required.</param> /// <param name="radius">The radius to check.</param> /// <returns>Whether the pump can run.</returns> protected virtual bool IsPumpable(Element.State state, int radius) { return(IsPumpableFixed(gameObject, state, SimHashes.Vacuum, radius)); }
private bool IsPumpable(Element.State expected_state) { return(Grid.Element[inputCell].IsState(expected_state)); }
public static Substance CreateSubstance(string name, Element.State state, KAnimFile kanim, Material material, Color32 colour) { return(ModUtil.CreateSubstance(name, state, kanim, material, colour, colour, colour)); }
public StateGrowthRule(Element.State state) { this.state = state; }