Esempio n. 1
0
        private AppendNodeInfo CalcNextValues(AppendNodeInfo currentAppendInfo, float chanceForLevelTurn, int currentNodeIndex)
        {
            var currentNode = mazeNodes[currentNodeIndex];
            //copy current append info (struct)
            AppendNodeInfo nextAppendInfo = currentAppendInfo;

            nextAppendInfo.DungeonNode = mazeNodes[currentNodeIndex + 1];
            DungeonNode sizeProvider = currentAppendInfo.DungeonNode;


            if (currentNode.Secret)
            {
                if (currentNode.NodeIndex == 0)
                {
                    nextAppendInfo.side = GetRandSide();
                }
                else
                {
                    if (info != null && info.ForcedNextRoomSide != null)
                    {
                        nextAppendInfo.side = info.ForcedNextRoomSide.Value;
                    }
                    else
                    {
                        if (currentAppendInfo.side == EntranceSide.Bottom)
                        {
                            nextAppendInfo.side = EntranceSide.Right;
                        }
                        else if (currentAppendInfo.side == EntranceSide.Right)
                        {
                            nextAppendInfo.side = EntranceSide.Bottom;
                        }
                    }
                }
                if (lastNonSecretNode != null)
                {
                    sizeProvider            = lastNonSecretNode;
                    nextAppendInfo.Position = appendNodeInfos[lastNonSecretNode].Position;
                }
            }
            else
            {
                //if (currentNodeIndex == 0)
                //  nextAppendInfo.side = EntranceSide.Bottom;
                //else
                nextAppendInfo.side = CalcSide(currentAppendInfo.side, nextAppendInfo.side, chanceForLevelTurn);
            }

            var pt = nextAppendInfo.Position;

            if (nextAppendInfo.side == EntranceSide.Bottom)
            {
                pt.Y += sizeProvider.Height - 1 + nodesPadding;
            }
            else if (nextAppendInfo.side == EntranceSide.Right)
            {
                pt.X += sizeProvider.Width - 1;
            }
            nextAppendInfo.Position = pt;

            return(nextAppendInfo);
        }
Esempio n. 2
0
        protected virtual void LayoutNodes(DungeonNode level, List <DungeonNode> mazeNodes)
        {
            this.mazeNodes = mazeNodes;
            var info = new AppendNodeInfo(mazeNodes[0]);

            info.side = EntranceSide.Right;

            float        chanceForLevelTurn = 0.5f;
            EntranceSide?prevEntranceSide   = null;
            var          secretRoomIndex    = mazeNodes.FindIndex(i => i.Secret);

            for (int currentNodeIndex = 0; currentNodeIndex < mazeNodes.Count; currentNodeIndex++)
            {
                appendNodeInfos.Add(mazeNodes[currentNodeIndex], info);

                var currentNode = mazeNodes[currentNodeIndex];
                currentNode.Reveal(options.RevealAllNodes, true);
                if (!currentNode.Secret)
                {
                    lastNonSecretNode = currentNode;
                }


                bool           shallBreak = currentNodeIndex == mazeNodes.Count - 1;
                AppendNodeInfo infoNext   = new AppendNodeInfo();

                if (!shallBreak)
                {
                    infoNext = CalcNextValues(info, chanceForLevelTurn, currentNodeIndex);

                    if (currentNodeIndex < mazeNodes.Count - 1 && generateLayoutDoors)
                    {
                        var nextMaze   = mazeNodes[currentNodeIndex + 1];
                        var secretRoom = currentNodeIndex == 0 ? currentNode.Secret : nextMaze.Secret;
                        if (!secretRoom)
                        {
                            secretRoom = nextMaze.Secret;
                        }

                        //this call must be done before AppendMaze because AppendMaze changes tiles x,y
                        List <Tiles.IDoor> doors = null;
                        if (!currentNode.Secret || currentNode.NodeIndex == 0)
                        {
                            doors = currentNode.GenerateLayoutDoors(infoNext.side, nextMaze.NodeIndex, secretRoom);
                        }
                        if (currentNode.Secret)
                        {
                            if (currentNode.NodeIndex == 0)
                            {
                                (doors[0]).CustomDungeonNodeIndex = 1;//to make them revealed ?
                            }
                        }

                        if (nextMaze.Secret && mazeNodes.Count > currentNodeIndex + 2)
                        {
                            doors = currentNode.GenerateLayoutDoors(infoNext.side == EntranceSide.Bottom ? EntranceSide.Right : EntranceSide.Bottom, nextMaze.NodeIndex, false, true);
                        }
                    }
                }

                EntranceSide?entranceSideToSkip = null;
                if (secretRoomIndex == 0 && currentNodeIndex == 1)
                {
                    entranceSideToSkip = null;
                }
                else
                {
                    entranceSideToSkip = null;
                    if (currentNodeIndex > 0)
                    {
                        entranceSideToSkip = info.side == EntranceSide.Bottom ? EntranceSide.Top : EntranceSide.Left;
                    }
                }

                level.AppendMaze
                (
                    currentNode,
                    info.Position,
                    null,
                    false,
                    entranceSideToSkip,
                    currentNodeIndex > 0 ? mazeNodes[currentNodeIndex - 1] : null
                );

                if (shallBreak)
                {
                    break;
                }
                entranceSideToSkip = null;
                prevEntranceSide   = infoNext.side;
                info = infoNext;
            }
        }