コード例 #1
0
        public static void ConcurrentConnectBuildings(int threadIndex, PastedEntity pastedEntity)
        {
            if (pastedEntity.sourceBuilding.altitude == 0)
            {
                return;
            }

            BuildPreview buildPreview = pastedEntity.buildPreview;

            buildPreview.input         = null;
            buildPreview.inputFromSlot = 0;
            buildPreview.inputToSlot   = 0;

            var pastedConnectedBuildingId = PASTE_INDEX_MULTIPLIER * pastedEntity.pasteIndex + pastedEntity.sourceBuilding.connectedBuildingId;

            if (pastedConnectedBuildingId != 0 &&
                BlueprintManager.pastedEntities.TryGetValue(pastedConnectedBuildingId, out PastedEntity otherPastedEntity) &&
                otherPastedEntity.type == EPastedType.BUILDING &&
                otherPastedEntity.status != EPastedStatus.REMOVE)
            {
                buildPreview.input         = otherPastedEntity.buildPreview;
                buildPreview.inputFromSlot = 15;
                buildPreview.inputToSlot   = 14;
            }
        }
コード例 #2
0
        public static PastedEntity ConcurrentPasteBelt(int threadIndex, BeltCopy belt, Vector2 targetSpr, float yaw, int pasteIndex)
        {
            var actionBuild = _abs[threadIndex];
            int pasteId     = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.originalId;

            if (!BlueprintManager.pastedEntities.TryGetValue(pasteId, out PastedEntity pastedEntity))
            {
                BuildPreview bp = BuildPreview.CreateSingle(belt.itemProto, belt.itemProto.prefabDesc, false);

                pastedEntity = new PastedEntity()
                {
                    pasteIndex   = pasteIndex,
                    pasteId      = pasteId,
                    status       = EPastedStatus.NEW,
                    type         = EPastedType.BELT,
                    sourceBelt   = belt,
                    buildPreview = bp,
                };

                BlueprintManager.pastedEntities.TryAdd(pasteId, pastedEntity);

                lock (actionBuild.buildPreviews)
                {
                    actionBuild.buildPreviews.Add(bp);
                }
            }
            else
            {
                pastedEntity.status = EPastedStatus.UPDATE;
            }

            Vector2 newRelative = belt.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, belt.originalSegmentCount);
            Vector2 sprPos      = newRelative + targetSpr;


            int   newSegmentCount = Util.GetSegmentsCount(sprPos);
            float sizeDeviation   = belt.originalSegmentCount / (float)newSegmentCount;

            sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr;

            Vector3 absoluteBeltPos = sprPos.SnapToGrid(belt.altitude * 1.3333333f / 2);

            // belts have always 0 yaw
            Quaternion absoluteBeltRot = Maths.SphericalRotation(absoluteBeltPos, 0f);


            Pose pose = new Pose(absoluteBeltPos, absoluteBeltRot);

            pastedEntity.objId = InserterPoses.AddOverride(pose, belt.itemProto);
            pastedEntity.pose  = pose;

            pastedEntity.buildPreview.lpos = absoluteBeltPos;
            pastedEntity.buildPreview.lrot = absoluteBeltRot;

            pastedEntity.buildPreview.condition = EBuildCondition.Ok;

            return(pastedEntity);
        }
コード例 #3
0
        public static void ConcurrentConnectBelt(int threadIndex, PastedEntity pastedEntity)
        {
            var actionBuild = _abs[threadIndex];
            var pasteIndex  = pastedEntity.pasteIndex;
            var belt        = pastedEntity.sourceBelt;

            BuildPreview buildPreview = pastedEntity.buildPreview;

            buildPreview.output         = null;
            buildPreview.outputToSlot   = -1;
            buildPreview.outputFromSlot = 0;
            buildPreview.outputOffset   = 0;

            buildPreview.input         = null;
            buildPreview.inputFromSlot = -1;
            buildPreview.inputToSlot   = 1;
            buildPreview.inputOffset   = 0;

            buildPreview.coverObjId     = 0;
            buildPreview.ignoreCollider = false;
            buildPreview.willCover      = false;

            var pastedBackInputId         = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.backInputId;
            var pastedLeftInputId         = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.leftInputId;
            var pastedRightInputId        = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.rightInputId;
            var pastedOutputId            = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.outputId;
            var pastedConnectedBuildingId = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.connectedBuildingId;

            PastedEntity otherPastedEntity;

            if (pastedOutputId != 0 &&
                BlueprintManager.pastedEntities.TryGetValue(pastedOutputId, out otherPastedEntity) &&
                otherPastedEntity.type == EPastedType.BELT &&
                otherPastedEntity.status != EPastedStatus.REMOVE &&
                Vector3.Distance(buildPreview.lpos, otherPastedEntity.buildPreview.lpos) < 10) // if the belts are too far apart ignore connection
            {
                buildPreview.output = otherPastedEntity.buildPreview;
                var otherBelt = otherPastedEntity.sourceBelt;

                if (otherBelt.backInputId == belt.originalId)
                {
                    buildPreview.outputToSlot = 1;
                }
                if (otherBelt.leftInputId == belt.originalId)
                {
                    buildPreview.outputToSlot = 2;
                }
                if (otherBelt.rightInputId == belt.originalId)
                {
                    buildPreview.outputToSlot = 3;
                }
            }

            if (pastedConnectedBuildingId != 0 &&
                BlueprintManager.pastedEntities.TryGetValue(pastedConnectedBuildingId, out otherPastedEntity) &&
                otherPastedEntity.type == EPastedType.BUILDING &&
                otherPastedEntity.status != EPastedStatus.REMOVE)
            {
                if (belt.connectedBuildingIsOutput)
                {
                    buildPreview.output       = otherPastedEntity.buildPreview;
                    buildPreview.outputToSlot = belt.connectedBuildingSlot;
                }
                else
                {
                    buildPreview.input         = otherPastedEntity.buildPreview;
                    buildPreview.inputFromSlot = belt.connectedBuildingSlot;
                }
                otherPastedEntity.connectedEntities.TryAdd(pastedEntity.pasteId, pastedEntity);
                //pastedEntity.connectedEntities.Add(otherPastedEntity);
            }

            bool beltHasInput  = BlueprintManager.pastedEntities.ContainsKey(pastedBackInputId) || BlueprintManager.pastedEntities.ContainsKey(pastedLeftInputId) || BlueprintManager.pastedEntities.ContainsKey(pastedRightInputId);
            bool beltHasOutput = BlueprintManager.pastedEntities.ContainsKey(pastedOutputId);

            if (!beltHasInput || !beltHasOutput)
            {
                var nearObjId = _nearObjectIds[threadIndex];
                int found     = actionBuild.nearcdLogic.GetBuildingsInAreaNonAlloc(buildPreview.lpos, 0.34f, nearObjId, false);
                for (int x = 0; x < found; x++)
                {
                    int overlappingEntityId = nearObjId[x];

                    if (overlappingEntityId <= 0)
                    {
                        continue;
                    }

                    EntityData overlappingEntityData = actionBuild.factory.entityPool[overlappingEntityId];

                    if (overlappingEntityData.beltId <= 0)
                    {
                        continue;
                    }

                    BeltComponent overlappingBelt = actionBuild.factory.cargoTraffic.beltPool[overlappingEntityData.beltId];

                    bool overlappingBeltHasInput  = (overlappingBelt.backInputId + overlappingBelt.leftInputId + overlappingBelt.rightInputId) != 0;
                    bool overlappingBeltHasOutput = overlappingBelt.outputId != 0;

                    if ((beltHasOutput && !overlappingBeltHasOutput) || (beltHasInput && !overlappingBeltHasInput))
                    {
                        // found overlapping belt that can be 'replaced' to connect to existing belts
                        buildPreview.coverObjId     = overlappingEntityId;
                        buildPreview.ignoreCollider = true;
                        buildPreview.willCover      = true;
                    }
                }
            }
        }
コード例 #4
0
        public static PastedEntity ConcurrentPasteInserter(int threadIndex, InserterCopy inserter, float yaw, int pasteIndex, bool connectToPasted = false)
        {
            var actionBuild = _abs[threadIndex];
            int pasteId     = PASTE_INDEX_MULTIPLIER * pasteIndex + inserter.originalId;

            if (!BlueprintManager.pastedEntities.TryGetValue(pasteId, out PastedEntity pastedEntity))
            {
                BuildPreview bp = BuildPreview.CreateSingle(inserter.itemProto, inserter.itemProto.prefabDesc, true);

                pastedEntity = new PastedEntity()
                {
                    pasteIndex     = pasteIndex,
                    pasteId        = pasteId,
                    status         = EPastedStatus.NEW,
                    type           = EPastedType.INSERTER,
                    sourceInserter = inserter,
                    buildPreview   = bp,
                };

                bp.filterId       = inserter.filterId;
                bp.inputToSlot    = 1;
                bp.outputFromSlot = 0;

                BlueprintManager.pastedEntities.TryAdd(pasteId, pastedEntity);

                lock (actionBuild.buildPreviews)
                {
                    actionBuild.buildPreviews.Add(bp);
                }
            }
            else
            {
                pastedEntity.status = EPastedStatus.UPDATE;
            }

            InserterPosition positionData = InserterPoses.GetPositions(actionBuild, inserter, yaw * Mathf.Deg2Rad, pasteIndex, connectToPasted);

            pastedEntity.buildPreview.lpos  = positionData.absoluteInserterPos;
            pastedEntity.buildPreview.lpos2 = positionData.absoluteInserterPos2;

            pastedEntity.buildPreview.lrot  = positionData.absoluteInserterRot;
            pastedEntity.buildPreview.lrot2 = positionData.absoluteInserterRot2;

            pastedEntity.buildPreview.inputOffset   = positionData.pickOffset;
            pastedEntity.buildPreview.outputOffset  = positionData.insertOffset;
            pastedEntity.buildPreview.outputToSlot  = positionData.endSlot;
            pastedEntity.buildPreview.inputFromSlot = positionData.startSlot;

            pastedEntity.buildPreview.condition = positionData.condition;

            pastedEntity.buildPreview.input       = null;
            pastedEntity.buildPreview.inputObjId  = 0;
            pastedEntity.buildPreview.output      = null;
            pastedEntity.buildPreview.outputObjId = 0;

            if (BlueprintManager.pastedEntities.TryGetValue(positionData.inputPastedId, out PastedEntity inputPastedEntity))
            {
                pastedEntity.buildPreview.input = inputPastedEntity.buildPreview;
            }
            else
            {
                pastedEntity.buildPreview.inputObjId = positionData.inputEntityId;
            }

            if (BlueprintManager.pastedEntities.TryGetValue(positionData.outputPastedId, out PastedEntity outputPastedEntity))
            {
                pastedEntity.buildPreview.output = outputPastedEntity.buildPreview;
            }
            else
            {
                pastedEntity.buildPreview.outputObjId = positionData.outputEntityId;
            }

            return(pastedEntity);
        }
コード例 #5
0
        public static PastedEntity ConcurrentPasteBuilding(int threadIndex, BuildingCopy building, Vector2 targetSpr, float yaw, int pasteIndex)
        {
            var actionBuild = _abs[threadIndex];
            int pasteId     = PASTE_INDEX_MULTIPLIER * pasteIndex + building.originalId;

            if (!BlueprintManager.pastedEntities.TryGetValue(pasteId, out PastedEntity pastedEntity))
            {
                PrefabDesc   desc = BlueprintManager.GetPrefabDesc(building);
                BuildPreview bp   = BuildPreview.CreateSingle(building.itemProto, desc, true);
                bp.ResetInfos();
                bp.desc     = desc;
                bp.item     = building.itemProto;
                bp.recipeId = building.recipeId;

                pastedEntity = new PastedEntity()
                {
                    pasteIndex     = pasteIndex,
                    pasteId        = pasteId,
                    status         = EPastedStatus.NEW,
                    type           = EPastedType.BUILDING,
                    sourceBuilding = building,
                    buildPreview   = bp,
                };

                BlueprintManager.pastedEntities.TryAdd(pasteId, pastedEntity);

                lock (actionBuild.buildPreviews)
                {
                    actionBuild.buildPreviews.Add(bp);
                }
            }
            else
            {
                pastedEntity.status = EPastedStatus.UPDATE;
            }

            Vector2 newRelative = building.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, building.originalSegmentCount);
            Vector2 sprPos      = newRelative + targetSpr;

            int newSegmentCount = Util.GetSegmentsCount(sprPos);

            float sizeDeviation = building.originalSegmentCount / (float)newSegmentCount;

            sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr;

            Vector3    absoluteBuildingPos = sprPos.SnapToGrid();
            Quaternion absoluteBuildingRot = Maths.SphericalRotation(absoluteBuildingPos, yaw + building.cursorRelativeYaw);

            absoluteBuildingPos += absoluteBuildingRot * (building.altitude * pastedEntity.buildPreview.desc.lapJoint);

            Pose pose = new Pose(absoluteBuildingPos, absoluteBuildingRot);

            pastedEntity.objId = InserterPoses.AddOverride(pose, building.itemProto);
            pastedEntity.pose  = pose;

            pastedEntity.buildPreview.lpos      = absoluteBuildingPos;
            pastedEntity.buildPreview.lrot      = absoluteBuildingRot;
            pastedEntity.buildPreview.condition = EBuildCondition.Ok;

            pastedEntity.connectedEntities.Clear();

            return(pastedEntity);
        }