Esempio n. 1
0
    public void CreatePathBetweenNodes(SettlementPathNode firstNode, int secondNodeDirection, int width, int length = -1)
    {
        SettlementPathNode second = firstNode.Connected[secondNodeDirection];

        if (second == null)
        {
            Debug.Error("Paths are not connected");
            return;
        }

        Vec2i pathDiff         = second.Position - firstNode.Position; //Find the vector that describes first->second
        int   pathDiffLen      = pathDiff.x + pathDiff.z;              //Vector should have only 1 component, so total length can be written as sum
        int   startPointOffset = pathDiffLen / 4;
        int   startPoint       = MiscMaths.RandomRange(startPointOffset, pathDiffLen - startPointOffset);

        //Generate node between two existing nodes
        SettlementPathNode interPathNode = new SettlementPathNode(firstNode.Position + SettlementPathNode.GetDirection(secondNodeDirection) * startPoint);
        int oppositeDir = SettlementPathNode.OppositeDirection(secondNodeDirection);

        //TestNodes.Add(interPathNode);
        //Update connections
        firstNode.AddConnection(secondNodeDirection, interPathNode);
        interPathNode.AddConnection(oppositeDir, firstNode);
        second.AddConnection(oppositeDir, interPathNode);
        interPathNode.AddConnection(secondNodeDirection, second);
        CreatePathFromNode(interPathNode, width, length: length);
    }
Esempio n. 2
0
    public void GenerateKingdomSettlementBases(Kingdom kingdom)
    {
        KingdomSettlements[kingdom] = new List <SettlementBase>(100);
        AddSettlementBaseToKingdom(kingdom, new SettlementBase(kingdom.CapitalChunk, 8, SettlementType.CAPITAL));

        int kingdomSize = KingdomChunks[kingdom].Count;
        //int cityCount = 1;
        //int townCount = 1;
        //int villageCount = 1;
        int cityCount    = MiscMaths.RandomRange(2, 3);
        int townCount    = MiscMaths.RandomRange(7, 9);
        int villageCount = MiscMaths.RandomRange(18, 25);

        if (kingdomSize > 400)
        {
            //   cityCount++;
            //   townCount += MiscMaths.RandomRange(1, 3);
            //  villageCount += MiscMaths.RandomRange(1, 8);
        }
        int distMult = 4;

        for (int i = 0; i < cityCount; i++)
        {
            Vec2i c = FindSpace(kingdom, 6 * distMult);
            if (c == null)
            {
                continue;
            }
            AddSettlementBaseToKingdom(kingdom, new SettlementBase(c, 6, SettlementType.CITY));
        }
        for (int i = 0; i < townCount; i++)
        {
            Vec2i c = FindSpace(kingdom, 4 * distMult);
            if (c == null)
            {
                continue;
            }
            AddSettlementBaseToKingdom(kingdom, new SettlementBase(c, 4, SettlementType.TOWN));
        }
        for (int i = 0; i < villageCount; i++)
        {
            Vec2i c = FindSpace(kingdom, 3 * distMult);
            if (c == null)
            {
                continue;
            }
            AddSettlementBaseToKingdom(kingdom, new SettlementBase(c, 3, SettlementType.VILLAGE));
        }

        /*
         * Vec2i city1 = FindSpace(kingdom, 12);
         * AddSettlementBaseToKingdom(kingdom, new SettlementBase(city1, 6, SettlementType.CITY));
         * Vec2i city2 = FindSpace(kingdom, 12);
         * AddSettlementBaseToKingdom(kingdom, new SettlementBase(city2, 6, SettlementType.CITY));*/
    }
Esempio n. 3
0
    public static Vec2i AddEntrance(Building b, int entranceSide, int disp = -1)
    {
        if (disp == -1)
        {
            //If entrance is facing z axis, displacement in in x
            if (entranceSide == NORTH_ENTRANCE || entranceSide == SOUTH_ENTRANCE)
            {
                disp = MiscMaths.RandomRange(1, b.Width - 1);
            }
            else
            {
                disp = MiscMaths.RandomRange(1, b.Height - 1);
            }
        }

        Vec2i entrance = null;

        if (entranceSide == NORTH_ENTRANCE)
        {
            entrance = new Vec2i(disp, b.Height - 1);
        }
        else if (entranceSide == SOUTH_ENTRANCE)
        {
            entrance = new Vec2i(disp, 0);
        }
        else if (entranceSide == EAST_ENTRANCE)
        {
            entrance = new Vec2i(b.Width - 1, disp);
        }
        else if (entranceSide == WEST_ENTRANCE)
        {
            entrance = new Vec2i(0, disp);
        }
        b.BuildingObjects[entrance.x, entrance.z] = null; //TODO - Set to door of correct type

        return(entrance);
    }
Esempio n. 4
0
    /// <summary>
    /// Takes a building plan and generates a full building from it.
    /// TODO - Currently messy, fix
    /// </summary>
    /// <param name="plan"></param>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="entrance"></param>
    /// <returns></returns>
    public static Building CreateBuilding(BuildingPlan plan, int width = -1, int height = -1, int entrance = 0)
    {
        if (width == -1)
        {
            width = MiscMaths.RandomRange(plan.MinSize, plan.MaxSize);
        }
        else if (width < plan.MinSize)
        {
            width = plan.MinSize;
        }
        else if (width > plan.MaxSize)
        {
            width = plan.MaxSize;
        }

        if (height == -1)
        {
            height = MiscMaths.RandomRange(plan.MinSize, plan.MaxSize);
        }
        else if (height < plan.MinSize)
        {
            height = plan.MinSize;
        }
        else if (height > plan.MaxSize)
        {
            height = plan.MaxSize;
        }

        Tile[,] buildingBase = new Tile[width, height];
        WorldObjectData[,] buildingObjects = new WorldObjectData[width, height];

        if (plan == Building.HOUSE)
        {
            House h = new House(width, height);
            h.SetBuilding(buildingBase, buildingObjects);
            return(GenerateHouse(h, BuildingStyle.stone));
        }
        if (plan == Building.BLACKSMITH)
        {
            Blacksmith b = new Blacksmith(width, height);
            b.SetBuilding(buildingBase, buildingObjects);
            return(GenerateBlacksmith(b, BuildingStyle.stone));
        }
        if (plan == Building.MARKET)
        {
            MarketPlace market = new MarketPlace(width, height);
            market.SetBuilding(buildingBase, buildingObjects);
            return(GenerateMarket(market, BuildingStyle.stone));
        }
        if (plan == Building.BARACKS)
        {
            Baracks baracks = new Baracks(width, height);
            baracks.SetBuilding(buildingBase, buildingObjects);
            return(GenerateBaracks(baracks));
        }

        /*
         * if(plan == Building.MARKET)
         * {
         *  MarketPlace market = new MarketPlace(width, height);
         *  market.SetBuilding(buildingBase, buildingObjects);
         *  return GenerateMarket(market, BuildingStyle.stone);
         * }
         * if(plan == Building.BARACKSCITY)
         * {
         *  Baracks bar = new Baracks(width, height);
         *  bar.SetBuilding(buildingBase, buildingObjects);
         *  return GenerateCityBaracks(bar);
         * }
         * if (plan == Building.BARACKSCITY || plan == Building.BARACKSTOWN)
         * {
         *
         * }*/

        //Default for now
        House ht = new House(width, height);

        ht.SetBuilding(buildingBase, buildingObjects);
        return(GenerateHouse(ht, BuildingStyle.stone));
    }
Esempio n. 5
0
    /// <summary>
    /// Generates the basic walls, floor, and entrance for any building.
    /// Picks the exact position of entrance, and returns it
    /// </summary>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="buildingObjects">Building objects to be filled with walls</param>
    /// <param name="buildTiles"></param>
    /// <param name="entranceID"></param>
    /// <param name="style"></param>
    /// <returns></returns>
    public static Vec2i GenerateWallsFloorAndEntrance(int width, int height, WorldObjectData[,] buildingObjects,
                                                      Tile[,] buildTiles, int entranceID, BuildingStyle style, int entraceDis = -1, WorldObjectData wallType = null, Tile tileType = null)
    {
        int entWidth = 2;

        if (entraceDis == -1)
        {
            if (entranceID == NORTH_ENTRANCE || entranceID == SOUTH_ENTRANCE)
            {
                entraceDis = MiscMaths.RandomRange(1, width - 1);
            }
            else
            {
                entraceDis = MiscMaths.RandomRange(1, height - 1);
            }
        }

        //Decide the position of the entrance
        Vec2i entrance = null;

        if (entranceID == NORTH_ENTRANCE)
        {
            entrance = new Vec2i(entraceDis, height - 1);
        }
        else if (entranceID == SOUTH_ENTRANCE)
        {
            entrance = new Vec2i(entraceDis, 0);
        }
        else if (entranceID == EAST_ENTRANCE)
        {
            entrance = new Vec2i(width - 1, entraceDis);
        }
        else if (entranceID == WEST_ENTRANCE)
        {
            entrance = new Vec2i(0, entraceDis);
        }


        //Assign correct wall type if none given
        if (wallType == null)
        {
            switch (style)
            {
            case BuildingStyle.stone:
                wallType = new BrickWall(new Vec2i(0, 0));
                break;

            case BuildingStyle.wood:
                //TODO - Add
                wallType = new BrickWall(new Vec2i(0, 0));
                break;
            }
        }//Asign correct tile type if none given
        if (tileType == null)
        {
            switch (style)
            {
            case BuildingStyle.stone:
                tileType = Tile.STONE_FLOOR;
                break;

            case BuildingStyle.wood:
                tileType = Tile.WOOD_FLOOR;
                break;
            }
        }
        //Iterate all points
        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < height; z++)
            {
                //Asign tile
                buildTiles[x, z] = tileType;
                if (x == 0 || x == width - 1 || z == 0 || z == height - 1)
                {
                    //Asign wall if no entrance
                    if (!(entrance.x == x & entrance.z == z))
                    {
                        if (x == 3)
                        {
                            buildingObjects[x, z] = new BuildingWall(new Vec2i(0, 0), "brick", 5,
                                                                     new GlassWindow(new Vec2i(0, 0), new Vec2i(0, 1)), 2);
                        }
                        else
                        {
                            buildingObjects[x, z] = new BuildingWall(new Vec2i(0, -1), "brick", 5);
                        }
                    }
                }
            }
        }
        //(buildingObjects[0, 0] as BuildingWall).AddRoof(new Roof(new Vec2i(0, 0), new Vec2i(width, height)));

        return(entrance);
    }