private void ProcessConnectedStorage(Vector3 side, ref List <SegmentEntity> segments, List <SegmentEntity> adjacentSegments) { PositionUtils.GetSegmentPos(side, mnX, mnY, mnZ, out long segmentX, out long segmentY, out long segmentZ); Segment adjacentSegment = AttemptGetSegment(segmentX, segmentY, segmentZ); if (adjacentSegment != null && CubeHelper.HasEntity(adjacentSegment.GetCube(segmentX, segmentY, segmentZ))) { var segmentEntity = adjacentSegment.SearchEntity(segmentX, segmentY, segmentZ); if (segmentEntity is IQuantumStorage quantumStorageEntity) { adjacentSegments.Add(segmentEntity); if (!segments.Contains(segmentEntity)) { segments.Add(segmentEntity); quantumStorageEntity.GetConnectedSegments(ref segments); } } else if (segmentEntity is IQuantumIo || segmentEntity is QuantumStorageControllerMachine) { if (!segments.Contains(segmentEntity)) { segments.Add(segmentEntity); } } } }
private void UpdateEntity(Boolean forceReset) { Int64 targetX = mnX + TargetXOffset; Int64 targetY = mnY + TargetYOffset; Int64 targetZ = mnZ + TargetZOffset; Segment segment = AttemptGetSegment(targetX, targetY, targetZ); if (segment == null) { return; } UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ); if (CubeHelper.HasEntity(cubeType)) { SegmentEntity entity = segment.SearchEntity(targetX, targetY, targetZ); Boolean reset = _node.ActiveInputCount == 0; // Reset the entity to defaults if the node can't be set if (entity != null) { UpdateTarget(entity, _node.InputValues, reset || forceReset); } } }
protected void findMk4AndMk5Bats() { VicisMod.log(getPrefix(), "Looking for T4 and T5 batteries"); long[] coords = new long[3]; for (int i = 0; i < 3; ++i) { for (int j = -1; j <= 1; j += 2) { Array.Clear(coords, 0, 3); coords[i] = j; long x = mnX + coords[0]; long y = mnY + coords[1]; long z = mnZ + coords[2]; Segment segment = base.AttemptGetSegment(x, y, z); // Check if segment was generated (skip this point if it doesn't if (segment == null) { continue; } ushort cube = segment.GetCube(x, y, z); // If this isn't an entity, skip it if (!CubeHelper.HasEntity((int)cube)) { continue; } PowerConsumerInterface pci = segment.SearchEntity(x, y, z) as PowerConsumerInterface; if (pci == null) { continue; } // We're only looking for T4 and T5 batteries if (!(pci is T4_Battery) && !(pci is T5_Battery)) { continue; } VicisMod.log(getPrefix(), "Found one: " + pci.ToString()); // Let's only keep track of PCIs that will accept power from the PowWow if (!pci.WantsPowerFromEntity(this)) { continue; } for (int l = mk4AndMk5Bats.Count - 1; l >= 0 && pci != null; --l) { PowerConsumerInterface pci2 = mk4AndMk5Bats[l]; if (pci2 != null && !(pci2 as SegmentEntity).mbDelete && pci2 == pci) { pci = null; } } VicisMod.log(getPrefix(), "End, checking " + pci); if (pci != null) { mk4AndMk5Bats.Add(pci); } } } }
private void UpdateTarget() { Int64 targetX = mnX - _sourceXOffset; Int64 targetY = mnY - _sourceYOffset; Int64 targetZ = mnZ - _sourceZOffset; Segment segment = AttemptGetSegment(targetX, targetY, targetZ); if (segment == null) { return; } UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ); ILogicReceiver logicReciever; Int32 inputIndex; if (CubeHelper.HasEntity(cubeType) && (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null && (inputIndex = logicReciever.FindFaceInputIndex(_targetDirection)) != -1) { // There is a connectable logic node at the target location var targetNode = logicReciever.GetLogicNode(); if (_node.OutNodes[OutIndex] == targetNode) { return; } // The node is not the same, so remove the old node and connect to the new one. _node.DisconnectFromHead(OutIndex); if (!targetNode.IsInputActive(inputIndex)) { try { _node.ConnectToHead(OutIndex, targetNode, inputIndex); } catch (InputEdgeAlreadyActiveException ex) { Debug.LogWarning( "Sensor attempted to connect to index that was already in use!\n" + $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" + "\nException: " + ex); } } // Else, the current node is the same, no changes needed } else { // No connectable logic node at the target location, make sure we're disconnected _node.DisconnectFromHead(OutIndex); } }
private void GetAdjacentBattery(long segmentX, long segmentY, long segmentZ, ref List <PowerStorageInterface> powerStoages) { Segment adjacentBattery = _quantumStorageController.AttemptGetSegment(segmentX, segmentY, segmentZ); if (adjacentBattery != null && CubeHelper.HasEntity(adjacentBattery.GetCube(segmentX, segmentY, segmentZ))) { if (adjacentBattery.SearchEntity(segmentX, segmentY, segmentZ) is PowerStorageInterface powerStorage) { powerStoages.Add(powerStorage); } } }
public ItemConsumerInterface GetItemConsumer() { PositionUtils.GetSegmentPos(_machineSides.Back, _machine.mnX, _machine.mnY, _machine.mnZ, out long segmentX, out long segmentY, out long segmentZ); Segment adjacentSegment = _machine.AttemptGetSegment(segmentX, segmentY, segmentZ); if (adjacentSegment != null && CubeHelper.HasEntity(adjacentSegment.GetCube(segmentX, segmentY, segmentZ)) && adjacentSegment.SearchEntity(segmentX, segmentY, segmentZ) is ItemConsumerInterface adjacentItemConsumer) { return(adjacentItemConsumer); } else { return(null); } }
public QuantumStorageControllerMachine GetStorageController() { Segment segment = _machine.AttemptGetSegment(_machine.GetControllerPos()[0], _machine.GetControllerPos()[1], _machine.GetControllerPos()[2]); if (segment != null && CubeHelper.HasEntity(segment.GetCube(_machine.GetControllerPos()[0], _machine.GetControllerPos()[1], _machine.GetControllerPos()[2])) && segment.SearchEntity(_machine.GetControllerPos()[0], _machine.GetControllerPos()[1], _machine.GetControllerPos()[2]) is QuantumStorageControllerMachine storageController) { return(storageController); } return(null); }
private SegmentEntity GetConnectedStorage() { PositionUtils.GetSegmentPos(_machineSides.Back, _quantumStorageController.mnX, _quantumStorageController.mnY, _quantumStorageController.mnZ, out long segmentX, out long segmentY, out long segmentZ); Segment segment = _quantumStorageController.AttemptGetSegment(segmentX, segmentY, segmentZ); if (segment == null || !CubeHelper.HasEntity(segment.GetCube(segmentX, segmentY, segmentZ))) { return(null); } var segmentEntity = segment.SearchEntity(segmentX, segmentY, segmentZ); if (segmentEntity is IQuantumStorage) { return(segmentEntity); } return(null); }
public static ushort getCubeForCryoCheckAt(Segment s, long x, long y, long z, ushort cryoToBuild) //their code returns false if the returned value from getCube == cryoToBuild { ushort real = s.GetCube(x, y, z); return(CubeHelper.IsMachine(real) || CubeHelper.HasEntity(real) ? cryoToBuild : real); }
protected void findPCIs() { for (int i = -1 * radius; i <= radius; ++i) { for (int j = -1 * radius; j <= radius; ++j) { for (int k = -1 * radius; k <= radius; ++k) { // Skip if we're looking at ourselves if (i == 0 && j == 0 && k == 0) { continue; } // Skip if the point is out of our radius if (i * i + j * j + k * k > radius * radius) { continue; } // Check the segment long x = this.mnX + i; long y = this.mnY + j; long z = this.mnZ + k; Segment segment = base.AttemptGetSegment(x, y, z); // Check if segment was generated (skip this point if it doesn't if (segment == null) { continue; } ushort cube = segment.GetCube(x, y, z); // If this isn't an entity, skip it if (!CubeHelper.HasEntity((int)cube)) { continue; } PowerConsumerInterface pci = segment.SearchEntity(x, y, z) as PowerConsumerInterface; if (pci == null) { continue; } // Don't feed power to T4 or T5 batteries if (pci is T4_Battery || pci is T5_Battery) { continue; } // Also, don't feed the power source (infinite loop of power, like a laser pointed at it's PSB) if (pci == powerSource) { continue; } // Let's only keep track of PCIs that will accept power from the PowWow if (!pci.WantsPowerFromEntity(this)) { continue; } for (int l = pcis.Count - 1; l >= 0 && pci != null; --l) { PowerConsumerInterface pci2 = pcis[l]; if (pci2 != null && !(pci2 as SegmentEntity).mbDelete && pci2 == pci) { pci = null; } } if (pci != null) { pcis.Add(pci); } } } } }
public override void LowFrequencyUpdate() { if (!_addedToGraph) { LogicManager.Instance.Graph.AddNode(_node); _addedToGraph = true; } UpdatePlayerDistanceInfo(); Int64 targetX = mnX + _xOffset * _searchDist; Int64 targetY = mnY + _yOffset * _searchDist; Int64 targetZ = mnZ + _zOffset * _searchDist; if (_searchDist > _foundDist) { // Uh oh, we've gone past the target, which means it's disappeared. Make sure we're disconnected from it. _node.DisconnectFromHead(OutIndex); _found = false; } if (_node.OutputValues.Length > 0) { _output = _node.OutputValues[0]; } Segment segment = AttemptGetSegment(targetX, targetY, targetZ); if (segment == null) { return; // We'll try again later. } UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ); ILogicReceiver logicReciever; Int32 inputIndex; if (CubeHelper.HasEntity(cubeType) && (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null && (inputIndex = logicReciever.FindFaceInputIndex(_targetDirection)) != -1) { var targetNode = logicReciever.GetLogicNode(); if (!targetNode.IsInputActive(inputIndex) && _node.OutNodes[OutIndex] != targetNode) { // Disconnect and reconnect if the target input is not active or the node is different than previously // The node we found is not the same as the old node if (_searchDist > _foundDist) { // ERROR: This shouldn't happen. We went past the old _foundDist and found something else? Debug.LogWarning("Logic Laser search went past _foundDist? _foundDist: " + _foundDist + "_searchDist" + _searchDist); } // We've found a different node, so connect to it instead. // Disconnect from logic node at _foundDist and connect to the one at _searchDist. _node.DisconnectFromHead(OutIndex); try { _node.ConnectToHead(OutIndex, targetNode, inputIndex); _foundDist = _searchDist; _found = true; _impactPosition = WorldScript.instance.mPlayerFrustrum.GetCoordsToUnity(targetX, targetY, targetZ); } catch (InputEdgeAlreadyActiveException ex) { Debug.LogWarning($"Laser attempted to connect to index that was already in use! Distance: {_searchDist}\n" + $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" + "\nException: " + ex); } } // Else, we've found what we were looking for, don't do anything else // Reset the search _searchDist = MinSearchDist; } else if (CubeHelper.IsCubeSolid(cubeType) && !CubeHelper.IsCubeGlass(cubeType) || _searchDist >= MaxSearchDist || CubeHelper.HasEntity(cubeType)) { // We hit a wall or the max range, reset the search and disconnect from target node _searchDist = MinSearchDist; _found = false; _node.DisconnectFromHead(OutIndex); } else { // Non solid or glass block, increment the search. _searchDist++; } }
public override void LowFrequencyUpdate() { if (!_addedToGraph) { LogicManager.Instance.Graph.AddNode(_node); _addedToGraph = true; } Int32 k = -1; for (Int32 i = 0; i < FaceCount / 2; i++) { for (Int32 j = 1; j > -2; j -= 2) { k++; if (k == 5) { continue; // Skip over the back direction since it's our input } // Get and check the block at the position Int64 targetX = mnX + _xOffsets[i] * j; Int64 targetY = mnY + _yOffsets[i] * j; Int64 targetZ = mnZ + _zOffsets[i] * j; Segment segment = AttemptGetSegment(targetX, targetY, targetZ); if (segment == null) { continue; // Ignore this one and check the other blocks } UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ); ILogicReceiver logicReciever; Int32 inputIndex; if (CubeHelper.HasEntity(cubeType) && (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null && (inputIndex = logicReciever.FindFaceInputIndex(_targetDirections[k])) != -1) { if (logicReciever == this) { Debug.LogError($"Laser Splitter connecting to itself? Loop vars: {i} {j} {k} Target coords: {targetX} {targetY} {targetZ}"); continue; } // There is a connectable logic node at the target location var targetNode = logicReciever.GetLogicNode(); if (_node.OutNodes[k] == targetNode) { continue; // The current node is the same, no changes needed } // The node is not the same, so remove the old node and connect to the new one. _node.DisconnectFromHead(k); if (!targetNode.IsInputActive(inputIndex)) { try { _node.ConnectToHead(k, targetNode, inputIndex); } catch (InputEdgeAlreadyActiveException ex) { Debug.LogWarning( $"Splitter attempted to connect to index that was already in use! Loop vars: {i} {j} {k}\n" + $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" + "\nException: " + ex); } } } else { // No connectable logic node at the target location, make sure we're disconnected _node.DisconnectFromHead(k); } } } }
private DigResult AttemptToDig(long checkX, long checkY, long checkZ) { mnCurrentDigSizeY = digArea.CurrentHeight; var segment = mFrustrum != null ? AttemptGetSegment(checkX, checkY, checkZ) : WorldScript.instance.GetSegment(checkX, checkY, checkZ); if (segment == null || !segment.mbInitialGenerationComplete || segment.mbDestroyed) { mrDigDelay = 1f; return(DigResult.Fail); } ushort cube = segment.GetCube(checkX, checkY, checkZ); if (cube == eCubeTypes.CentralPowerHub) { return(DigResult.Dig); } if (cube == mReplaceType) { return(DigResult.Skip); } if (CubeHelper.IsReinforced(cube) && eExcavateState != ExcavateState.ClearAll) { return(DigResult.Dig); } if (CubeHelper.HasEntity((int)cube) && eExcavateState != ExcavateState.ClearAll) { if (cube != eCubeTypes.AlienPlant && cube != eCubeTypes.ArachnidRock) { return(DigResult.Dig); } } if (TerrainData.GetHardness(cube, 0) > 500f) { return(DigResult.Dig); } if (eExcavateState == ExcavateState.ClearGarbage) { if (CubeHelper.IsOre(cube)) { return(DigResult.Dig); } } // Tranqs Creative Survival mod really breaks this call as nearly everything in the game is craftable. if (CraftingManager.IsCraftable(cube) && cube != eCubeTypes.Giger && eExcavateState != ExcavateState.ClearAll) { // ore should never ever be craftable if (!CubeHelper.IsOre(cube)) { return(DigResult.Dig); } } int num = (int)(checkX - segment.baseX); int num2 = (int)(checkY - segment.baseY); int num3 = (int)(checkZ - segment.baseZ); if (num == 0 && base.AttemptGetSegment(checkX - 1L, checkY, checkZ) == null) { return(DigResult.Fail); } if (num == 15 && base.AttemptGetSegment(checkX + 1L, checkY, checkZ) == null) { return(DigResult.Fail); } if (num2 == 0 && base.AttemptGetSegment(checkX, checkY - 1L, checkZ) == null) { return(DigResult.Fail); } if (num2 == 15 && base.AttemptGetSegment(checkX, checkY + 1L, checkZ) == null) { return(DigResult.Fail); } if (num3 == 0 && base.AttemptGetSegment(checkX, checkY, checkZ - 1L) == null) { return(DigResult.Fail); } if (num3 == 15 && base.AttemptGetSegment(checkX, checkY, checkZ + 1L) == null) { return(DigResult.Fail); } ushort mValue = segment.GetCubeData(checkX, checkY, checkZ).mValue; WorldScript.instance.BuildFromEntity(segment, checkX, checkY, checkZ, this.mReplaceType, TerrainData.GetDefaultValue(this.mReplaceType)); this.mrCurrentPower -= this.mrPowerRate; this.mbLocatedBlock = true; this.mnBlocksDestroyed++; if (segment.mbInLocalFrustrum) { if (eDropState == DropState.DropSome) { bool flag = true; if (CubeHelper.IsGarbage(cube) && this.mRand.Next(100) > 5) { flag = false; } if (flag) { Vector3 velocity = new Vector3((float)this.mRand.NextDouble() - 0.5f, 0f, (float)this.mRand.NextDouble() - 0.5f); velocity.x *= 5f; velocity.z *= 5f; ItemManager.DropNewCubeStack(cube, mValue, 1, checkX, checkY, checkZ, velocity); } } if (eDropState == DropState.DropAll) { Vector3 velocity = new Vector3((float)this.mRand.NextDouble() - 0.5f, 0f, (float)this.mRand.NextDouble() - 0.5f); velocity.x *= 5f; velocity.z *= 5f; ItemManager.DropNewCubeStack(cube, mValue, 1, checkX, checkY, checkZ, velocity); } if (eDropState == DropState.DropOre && CubeHelper.IsOre(cube)) { Vector3 velocity = new Vector3((float)this.mRand.NextDouble() - 0.5f, 0f, (float)this.mRand.NextDouble() - 0.5f); velocity.x *= 5f; velocity.z *= 5f; ItemManager.DropNewCubeStack(cube, mValue, 1, checkX, checkY, checkZ, velocity); } this.mrTimeSinceShoot = 0f; } return(DigResult.Dig); }