public BeltItemContainer([NotNull] BeltComponent component) { _parentComponent = component; _container = new ThingContainer(this); _thingCounter = new Dictionary<Thing, int>(); }
public override bool CanAcceptFrom(BeltComponent belt) { // If this is an Undertaker, make sure we are connected underground AND have the good oriantation ! if (belt.IsUndertaker() && IsConnectedUnder(belt)) { if (parent.Rotation.AsInt == 0) { return((belt.parent.Rotation.AsInt == 2) && (belt.parent.Position.x == this.parent.Position.x) && (belt.parent.Position.z > this.parent.Position.z)); } if (parent.Rotation.AsInt == 1) { return((belt.parent.Rotation.AsInt == 3) && (belt.parent.Position.z == this.parent.Position.z) && (belt.parent.Position.x > this.parent.Position.x)); } if (parent.Rotation.AsInt == 2) { return((belt.parent.Rotation.AsInt == 0) && (belt.parent.Position.x == this.parent.Position.x) && (belt.parent.Position.z < this.parent.Position.z)); } if (parent.Rotation.AsInt == 3) { return((belt.parent.Rotation.AsInt == 1) && (belt.parent.Position.z == this.parent.Position.z) && (belt.parent.Position.x < this.parent.Position.x)); } else { return(false); // Should never get here ... } } else { return(this.GetPositionFromRelativeRotation(Rot4.South) == belt.parent.Position); } }
/** * Calculates the chance for this BeltComponent to jam per check at a given health percentage **/ public static float JamChance(this BeltComponent belt, float health) { float delta = 1.0f - health; const float MIN_CHANCE = 0.01f; const float MAX_CHANCE = 1.00f; const float FLAT_RATE_THRESHOLD = 10.0f; const float START_THRESHOLD = 0.40f; // No chance to freeze above the start threshold if (delta < START_THRESHOLD) { return(0); } // Flat rate past a certain point if (delta >= FLAT_RATE_THRESHOLD) { return(MAX_CHANCE); } // Transform to [0, 1] (a percentage of the range) float percent = MathUtilities.LinearTransformInv(delta, 0, FLAT_RATE_THRESHOLD); // Transform to [MIN_CHANCE, MAX_CHANCE] return(MathUtilities.LinearTransform(percent, MIN_CHANCE, MAX_CHANCE)); }
public override void OnItemTransfer(Thing item, BeltComponent other) { if (this.IsReceiver()) { return; } int minPuffs = (A2BResearch.TeleporterHeat.IsResearched() ? 1 : 4); int maxPuffs = (A2BResearch.TeleporterHeat.IsResearched() ? 2 : 6); float heat = PowerComponent.PowerOutput / basePowerConsumption * DegreesPerDistance; Room room = GridsUtility.GetRoom(parent.Position); if (room != null) { room.PushHeat(heat); } for (int i = 0; i < Rand.RangeInclusive(minPuffs, maxPuffs); ++i) { MoteThrower.ThrowAirPuffUp(parent.DrawPos); } room = GridsUtility.GetRoom(ReceiverPos); if (room != null) { room.PushHeat(heat); } for (int i = 0; i < Rand.RangeInclusive(minPuffs, maxPuffs); ++i) { MoteThrower.ThrowAirPuffUp(Gen.TrueCenter(ReceiverPos, parent.Rotation, new IntVec2(2, 1), 0.5f)); } }
public virtual void OnItemTransfer(Thing item, BeltComponent other) { if (Rand.Range(0.0f, 1.0f) < DeteriorateChance) { parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, Rand.RangeInclusive(0, 2), parent)); } }
/** * Calculates the chance for this BeltComponent to freeze per check at a given temperature **/ public static float FreezeChance(this BeltComponent belt, float currentTemp) { float delta = belt.FreezeTemperature - currentTemp; const float MIN_CHANCE = 0.20f; const float MAX_CHANCE = 1.00f; const float FLAT_RATE_THRESHOLD = 20.0f; // No chance to freeze above the freezing temp if (delta < 0) { return(0); } // Flat rate past a certain point if (delta >= FLAT_RATE_THRESHOLD) { return(MAX_CHANCE); } // Transform to [0, 1] (a percentage of the range) float percent = MathUtilities.LinearTransformInv(delta, 0, FLAT_RATE_THRESHOLD); // Transform to [MIN_CHANCE, MAX_CHANCE] return(MathUtilities.LinearTransform(percent, MIN_CHANCE, MAX_CHANCE)); }
public override bool CanAcceptFrom(BeltComponent belt) { if (this.IsReceiver()) { return(belt.IsTeleporter() && belt.parent.Rotation == parent.Rotation && ((BeltTeleporterComponent)belt).ReceiverPos == parent.Position); } return(base.CanAcceptFrom(belt)); }
public override bool CanAcceptFrom( BeltComponent belt, bool onlyCheckConnection = false ) { if (this.IsReceiver()) { return (belt.IsTeleporter() && belt.parent.Rotation == parent.Rotation && ((BeltTeleporterComponent) belt).ReceiverPos == parent.Position); } return base.CanAcceptFrom(belt, onlyCheckConnection ); }
public override void OnItemTransfer(Thing item, BeltComponent other) { base.OnItemTransfer( item, other ); _mythingID = null; int index = Math.Max(_nextDest, Array.FindIndex(_dests, dir => (dir == _splitterDest))); _nextDest = FindNextDest( index ); }
public override void OnItemTransfer(Thing item, BeltComponent other) { // Tell the undercover which direction the item came from if( other.IsUndercover() ) { // Input is opposite side as output ((BeltUndercoverComponent) other).outputDirection = outputDirection; ((BeltUndercoverComponent) other).inputDirection = inputDirection; } // Do potential belt deterioration if (Rand.Range(0.0f, 1.0f) < A2BData.Durability.DeteriorateChance) parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, Rand.RangeInclusive(0, 2), parent)); }
// We can accept from any teleporter on our channel. If we are locked, we can only accept from // the sender that locked us. public override bool CanAcceptFrom(BeltComponent belt, bool onlyCheckConnection = false) { if (!belt.IsTeleporter()) return false; // If I can't accept from anyone, I certainly can't accept from you. if( !onlyCheckConnection && !CanAcceptSomething() ) return false; BeltSenderComponent tele = belt as BeltSenderComponent; // Does whomever holds the lock still operate on the same channel? if( IsLocked() ) return ( tele == Sender )&&( tele.Channel == Channel ); return (tele.Channel == Channel); }
public override void Tick() { base.Tick(); CompPowerTrader power = GetComp <CompPowerTrader>(); BeltComponent belt = GetComp <BeltComponent>(); if (Graphic.GetType() == typeof(AnimatedGraphic)) { AnimatedGraphic animation = (AnimatedGraphic)Graphic; if (animation.CurrentFrame != prevFrame) { Find.MapDrawer.MapChanged(Position, MapChangeType.Things, true, false); prevFrame = animation.CurrentFrame; } } }
// Check that two Undertakers are connected by Undercovers all the way. public bool IsConnectedUnder(BeltComponent belt) { var direction = (belt.parent.Position - this.parent.Position); var step = direction.ToVector3(); step.Normalize(); bool IsUndercover = false; // First, check if the two belts are in line if (belt.parent.Position.x == this.parent.Position.x || belt.parent.Position.z == this.parent.Position.z) { var myPosition = this.parent.Position.ToVector3() + step; // If this is already the destination, then there is no Undercover gap at all ! if (myPosition.ToIntVec3() == belt.parent.Position) { return(true); } do { IsUndercover = false; foreach (var target in Find.Map.thingGrid.ThingsAt(myPosition.ToIntVec3())) { // Check to see if this is an Undercover element. if (target.def.defName == "A2BUndercover") { // Also need to check if it is connected to power ! PowerComponent = target.TryGetComp <CompPowerTrader>(); if (PowerComponent.PowerOn) { IsUndercover = true; } } } myPosition += step; } while ((myPosition.ToIntVec3() != belt.parent.Position) && (IsUndercover)); return(IsUndercover); } return(false); }
public virtual bool CanAcceptFrom(BeltComponent belt) { // If I can't accept from anyone, I certainly can't accept from you. if (!CanAcceptSomething()) { return(false); } for (int i = 0; i < 4; ++i) { Rot4 dir = new Rot4(i); if (CanAcceptFrom(dir) && belt.parent.Position == this.GetPositionFromRelativeRotation(dir)) { return(true); } } return(false); }
public override bool CanAcceptFrom( BeltComponent belt, bool onlyCheckConnection = false ) { // If I can't accept from anyone, I certainly can't accept from you. if( !onlyCheckConnection && !CanAcceptSomething() ) return false; // This belt isn't on the other belts output level if( belt.OutputLevel != this.InputLevel ) return false; // Accepts from any direction, sends it out the opposite if( belt.IsUndercover() ) return true; // Check a slides orientation if( ( belt.IsSlide() )&& ( this.parent.Position == belt.GetPositionFromRelativeRotation( Rot4.North ) ) ) return true; // Not an undercover or slide in the corrent orientation return false; }
public override void OnItemTransfer(Thing item, BeltComponent other) { if (this.IsReceiver()) return; int minPuffs = (A2BResearch.TeleporterHeat.IsResearched() ? 1 : 4); int maxPuffs = (A2BResearch.TeleporterHeat.IsResearched() ? 2 : 6); float heat = PowerComponent.PowerOutput / basePowerConsumption * DegreesPerDistance; Room room = GridsUtility.GetRoom(parent.Position); if (room != null) room.PushHeat(heat); for (int i = 0; i < Rand.RangeInclusive(minPuffs, maxPuffs); ++i) MoteThrower.ThrowAirPuffUp(parent.DrawPos); room = GridsUtility.GetRoom(ReceiverPos); if (room != null) room.PushHeat(heat); for (int i = 0; i < Rand.RangeInclusive(minPuffs, maxPuffs); ++i) MoteThrower.ThrowAirPuffUp(Gen.TrueCenter(ReceiverPos, parent.Rotation, new IntVec2(2, 1), 0.5f)); }
// onlyCheckConnection - Skips all other checks except whether a physical link exists // between the two components. public virtual bool CanAcceptFrom( BeltComponent belt, bool onlyCheckConnection = false ) { // If I can't accept from anyone, I certainly can't accept from you. if( !onlyCheckConnection && !CanAcceptSomething() ) return false; // This belt isn't on the other belts output level if( belt.OutputLevel != this.InputLevel ) return false; for (int i = 0; i < 4; ++i) { Rot4 dir = new Rot4(i); if (CanAcceptFrom(dir) && belt.parent.Position == this.GetPositionFromRelativeRotation(dir)) return true; } return false; }
/** * Get the position corresponding to a rotation relative to the Thing's * current rotation. Used as a convenient way to specify left/right/front/back * without worrying about where the belt is currently facing. 'rotation' must be * one of IntRot.north, IntRot.south, IntRot.east, or IntRot.west. **/ public static IntVec3 GetPositionFromRelativeRotation(this BeltComponent belt, Rot4 rotation) { Rot4 rotTotal = new Rot4((belt.parent.Rotation.AsInt + rotation.AsInt) % 4); return(belt.parent.Position + rotTotal.FacingCell); }
public static void DrawIceGraphic(this BeltComponent belt) { IceGraphic.Draw(belt.parent.DrawPos, belt.parent.Rotation, belt.parent); }
public BeltItemRouter(BeltComponent parent) { _parent = parent; }
public override void OnItemTransfer(Thing item, BeltComponent other) { // Do potential belt deterioration if (Rand.Range(0.0f, 1.0f) < A2BData.Durability.DeteriorateChance) parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, Rand.RangeInclusive(0, 2), parent)); }
public static bool IsReceiver([NotNull] this BeltComponent belt) { return(belt.parent.def.defName == "A2BReceiver"); }
public static bool IsTeleporter([NotNull] this BeltComponent belt) { return(belt.parent.def.defName == "A2BTeleporter"); }
// Unlock the receiver after the item finishes. public override void OnItemTransfer( Thing item, BeltComponent other ) { base.OnItemTransfer( item, other ); BeltReceiverComponent recv = other as BeltReceiverComponent; // Play a nice teleport sound var sound = DefDatabase<SoundDef>.GetNamed( "A2B_Teleport" ); sound.PlayOneShot( SoundInfo.InWorld( parent.Position ) ); sound.PlayOneShot( SoundInfo.InWorld( recv.parent.Position ) ); // And blind anyone who's looking MoteThrower.ThrowLightningGlow( parent.DrawPos, Random.Range( 4.8f, 5.2f ) ); MoteThrower.ThrowLightningGlow( Receiver.parent.DrawPos, Random.Range( 4.8f, 5.2f ) ); // Reset power usage and mode PowerComponent.PowerOutput = -PowerComponent.props.basePowerConsumption; CurrentState = TeleportState.Default; Receiver.Unlock( this ); }
private bool IsFreeBelt(IntVec3 position) { BeltComponent destBelt = position.GetBeltComponent(); return(destBelt != null && destBelt.CanAcceptFrom(this)); }
/** * Called immediately before transferring an item. Returning false here * is your last chance to prevent the item from moving to the next belt. **/ public virtual bool PreItemTransfer(Thing item, BeltComponent other) { return true; }
/** * Called immediately after receiving an item. **/ public virtual void OnItemReceived(Thing item, BeltComponent other) { // stub }
public static bool IsUndertaker([NotNull] this BeltComponent belt) { return(belt.parent.def.defName == "A2BUndertaker"); }