示例#1
0
    public static Room CreateMinRoom(ref FloorType[,] blocks, BlueprintNode blueprint, VecInt2 doorPos, Direction doorDir)
    {
        Room room = new Room(doorPos, blueprint.type, FakeRandom.Range(blueprint.sizeMin, blueprint.sizeMax));

        room.range = GetRange(doorPos, blueprint.edgeLenghtMin, blueprint.edgeLenghtMin, doorDir);
        room.dir   = doorDir;
        Array2DTool.SetRange(blocks, room.range, blueprint.type);
        Array2DTool.SetOne(blocks, room.doorPos.x, room.doorPos.y, doorType[(int)room.dir]);
        return(room);
    }
示例#2
0
    public static BlueprintNode GetRoomLink(HouseType type)
    {
        BlueprintNode livingRoom = new BlueprintNode(FloorType.LivingRoom, 100, 200, 8);

        livingRoom.children.Add(new BlueprintNode(FloorType.BedRoom0, 60, 100, 6));
        livingRoom.children.Add(new BlueprintNode(FloorType.BedRoom1, 60, 100, 6));
        livingRoom.children.Add(new BlueprintNode(FloorType.Bathroom, 40, 60, 4));
        livingRoom.children.Add(new BlueprintNode(FloorType.Kitchen, 40, 60, 4));
        return(livingRoom);
    }
示例#3
0
    private void TryClickBlueprintNodes()
    {
        BlueprintNode blueprintNode = GetClickedBlueprintNode();

        if (blueprintNode != null)
        {
            blueprintNode.ClickedByPlayer(gameManager.GetCrew());
        }

        SelectSlotIndex(selectedSlotIndex);
    }
示例#4
0
 public bool IsConstructed()
 {
     //checks if all BlueprintNodes are completed.
     foreach (GameObject child in ParentChildFunctions.GetAllChildren(gameObject))
     {
         BlueprintNode node = child.GetComponent <BlueprintNode> ();
         if (node != null && !node.IsConstructed())
         {
             return(false);
         }
     }
     return(true);
 }
    //Adds the specified blueprint node to the blueprint at the specified position
    public void AddBlueprintNode(BlueprintNode blueprintNode, Vector2 position)
    {
        //Add the specified blueprint node to the blueprint
        blueprintNodes.Add(blueprintNode);

        //Set the blueprint nodes ID
        blueprintNodes[blueprintNodes.Count - 1].nodeID = blueprintNodes.Count - 1;

        //Set the blueprint nodes position to the specified position
        blueprintNodes[blueprintNodes.Count - 1].Translate(position);

        //Initialize the blueprint node
        blueprintNodes[blueprintNodes.Count - 1].Initialize();
    }
示例#6
0
    private void AdjustToMinimumTerrainHeight(GameObject nodeGameObject)
    {
        //this takes the coordinates of nodeGameObject and makes sure they are never below the terrain, plus half
        //the height of the nodeGameObject render.
        BlueprintNode bn            = nodeGameObject.GetComponent <BlueprintNode> ();
        float         terrainHeight = terrainManager.GetHeightAtPoint(nodeGameObject.transform.position);
        float         minimumHeight = terrainHeight + bn.GetThingGameObject().GetComponent <Renderer> ().bounds.size.y / 2;

        if (terrainHeight < minimumHeight)
        {
            nodeGameObject.transform.position = new Vector3(nodeGameObject.transform.position.x,
                                                            minimumHeight, nodeGameObject.transform.position.z);
        }
    }
示例#7
0
    //Returns a flag indicating whether the specified blueprint nodes match
    public static bool BlueprintNodesMatch(BlueprintNode blueprintNodeA, BlueprintNode blueprintNodeB)
    {
        //If the blueprint nodes are not the same type
        if (blueprintNodeA.GetType() != blueprintNodeB.GetType())
        {
            //The blueprint nodes do not match
            return(false);
        }

        //If the blueprint nodes input execution connections do not match
        if (!BlueprintConnectionsMatch(blueprintNodeA.inputExecutionConnection, blueprintNodeB.inputExecutionConnection))
        {
            //The blueprint nodes do not match
            return(false);
        }

        //If the blueprint nodes output execution connections do not match
        if (!BlueprintConnectionsMatch(blueprintNodeA.outputExecutionConnection, blueprintNodeB.outputExecutionConnection))
        {
            //The blueprint nodes do not match
            return(false);
        }

        //If the blueprint nodes do not have the same number of blueprint connections
        if (blueprintNodeA.connections.Count != blueprintNodeB.connections.Count)
        {
            //The blueprint nodes do not match
            return(false);
        }

        //For each blueprint connection in the blueprint nodes
        for (int blueprintConnectionIndex = 0; blueprintConnectionIndex < blueprintNodeA.connections.Count; blueprintConnectionIndex++)
        {
            //If the blueprint connections do not match
            if (!BlueprintConnectionsMatch(blueprintNodeA.connections[blueprintConnectionIndex], blueprintNodeB.connections[blueprintConnectionIndex]))
            {
                //The blueprint nodes do not match
                return(false);
            }
        }

        //The blueprint nodes match
        return(true);
    }
    //Destroys the specified blueprint node
    public void DestroyBlueprintNode(BlueprintNode blueprintNode)
    {
        //For each blueprint node
        for (int blueprintNodeIndex = 0; blueprintNodeIndex < blueprintNodes.Count; blueprintNodeIndex++)
        {
            //If the blueprint node matches the specified blueprint node
            if (blueprintNodes[blueprintNodeIndex].nodeID == blueprintNode.nodeID)
            {
                //Destroy the blueprint node
                blueprintNodes[blueprintNodeIndex] = null;

                //Optimize the blueprint data
                Optimize();

                //Return from the function
                return;
            }
        }
    }
示例#9
0
    void CreateNewNode(BlueprintNode bpNode)
    {
        BeeHiveNode node = ScriptableObject.CreateInstance <BeeHiveNode>();

        Vector2 position = new Vector2(bpNode.xPos, bpNode.yPos);

        node.methodName = string.Copy(bpNode.methodName);

        if (bpNode.nodeType == E_NodeType.selector)
        {
            node.BuildNode(new BH_Selector(), position);
        }
        else if (bpNode.nodeType == E_NodeType.sequencer)
        {
            node.BuildNode(new BH_Sequence(), position);
        }
        else if (bpNode.nodeType == E_NodeType.inverter)
        {
            node.BuildNode(new BH_Inverter(), position);
        }
        else if (bpNode.nodeType == E_NodeType.succeder)
        {
            node.BuildNode(new BH_Succeeder(), position);
        }
        else if (bpNode.nodeType == E_NodeType.repeater)
        {
            node.BuildNode(new BH_Repeater(), position);
        }
        else if (bpNode.nodeType == E_NodeType.repeatTilFail)
        {
            node.BuildNode(new BH_RepeatUntilFail(), position);
        }
        else if (bpNode.nodeType == E_NodeType.leaf)
        {
            node.BuildNode(new BH_Leaf(), position);
        }



        nodes.Add(node);

        node.bottonConnectorClick += OnBottonConnectorClicked;
    }
示例#10
0
    private void TryHoldClickBlueprintNodes()
    {
        BlueprintNode blueprintNode = GetClickedBlueprintNode();

        if (blueprintNode == null)
        {
            if (lastClickedBlueprintNode != null)
            {
                lastClickedBlueprintNode.UnholdClick();
            }
        }
        else
        {
            lastClickedBlueprintNode = blueprintNode;
            blueprintNode.HoldClickedByPlayer(selectedThing, gameManager.GetCrew());
        }

        SelectSlotIndex(selectedSlotIndex);
    }
示例#11
0
    public static FloorType[,] CreateHouse(HouseType type, Direction dir)
    {
        int           mapW      = 50;
        int           mapH      = 50;
        BlueprintNode blueprint = GetRoomLink(type);

        FloorType[,] blocks = new FloorType[mapW, mapH];
        Room livingRoom = CreateMinRoom(ref blocks, blueprint, new VecInt2(mapW / 2, mapH / 2), dir);

        while (livingRoom.GetCurrentSize() < livingRoom.targetSize)
        {
            bool bExtendOk = Extend(ref blocks, livingRoom);
            if (!bExtendOk)
            {
                break;
            }
        }
        livingRoom.children = CreateChildren(ref blocks, livingRoom, blueprint);
        return(blocks);
    }
示例#12
0
    public static List <Room> CreateChildren(ref FloorType[,] blocks, Room room, BlueprintNode blueprint)
    {
        List <Room> children = new List <Room>();

        for (int i = 0; i < blueprint.children.Count; i++)
        {
            BlueprintNode childBlueprint = blueprint.children[i];
            VecInt2       childDoorPos   = new VecInt2(0, 0);
            Direction     childDoorDir   = Direction.Left;
            bool          bValid         = false;
            Direction[]   dirs           = GetExtendDirections(room.dir); //得到可以产生门的方向
            dirs = RandomSort(dirs, FakeRandom.Range(0, 10000));          //打乱顺序
            foreach (Direction d in dirs)
            {
                for (int t = 0; t < 5; t++)
                {
                    childDoorPos = GetRandomChildDoorPos(room.range, d);//在随机位置生生成一个门
                    childDoorDir = d;
                    RectInt childMinRange = GetRange(childDoorPos, childBlueprint.edgeLenghtMin, childBlueprint.edgeLenghtMin, d);
                    if (Array2DTool.RangeIsAll(blocks, childMinRange, FloorType.Out)) //如果是空地
                    {
                        bValid = true;                                                //则找到了一个有效位置
                        break;
                    }
                }
                if (bValid)
                {
                    break;
                }
            }
            if (bValid)                                                                                 //如果找到了一个有效的位置
            {
                Room childRoom = CreateMinRoom(ref blocks, childBlueprint, childDoorPos, childDoorDir); //在此位置生成一个最小房间
                if (childRoom != null)
                {
                    childRoom.blueprint = childBlueprint;
                    children.Add(childRoom);
                }
            }
        }

        while (true)
        {
            bool bExtendOne = false;
            for (int i = 0; i < children.Count; i++)
            {
                if (children[i].GetCurrentSize() < children[i].targetSize) //如果房间大小还没到期望值
                {
                    bool bExtendOk = Extend(ref blocks, children[i]);      //则往随机方向扩大一格
                    bExtendOne |= bExtendOk;
                }
            }
            if (!bExtendOne)  //如果没有任何房间被扩大过,则退出循环
            {
                break;
            }
        }

        //给扩展过的子房间产生下一级房间
        for (int i = 0; i < children.Count; i++)
        {
            children[i].children = CreateChildren(ref blocks, children[i], children[i].blueprint);
        }

        return(children);
    }