Example #1
0
    public void AddSpecialFeature(HexCell_Script cell, Vector3 position)
    {
        Transform instance = Instantiate(specials[cell.SpecialIndex - 1]);

        instance.localPosition = HexMetrics_Script.Perturb(position);
        HexHash hash = HexMetrics_Script.SampleHashGrid(position);

        instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f);
        instance.SetParent(container, false);
    }
Example #2
0
    public void AddFeature(HexCell_Script cell, Vector3 position)
    {
        if (cell.IsSpecial)
        {
            return;
        }

        HexHash hash = HexMetrics_Script.SampleHashGrid(position);
        //if (hash.a >= cell.UrbanLevel*0.25f)
        //    return;
        //Transform instance = Instantiate(urbanPrefabs[cell.UrbanLevel-1]);
        Transform prefab      = PickPrefab(urbanPrefabs, cell.UrbanLevel, hash.a, hash.d);
        Transform otherprefab = PickPrefab(farmPrefabs, cell.FarmLevel, hash.b, hash.d);

        float usedHash = hash.a;

        if (prefab)
        {
            if (otherprefab && hash.b < hash.a)
            {
                prefab   = otherprefab;
                usedHash = hash.b;
            }
        }
        else if (otherprefab)
        {
            prefab   = otherprefab;
            usedHash = hash.b;
        }
        otherprefab = PickPrefab(plantPrefabs, cell.PlantLevel, hash.c, hash.d);
        if (prefab)
        {
            if (otherprefab && hash.c < usedHash)
            {
                prefab = otherprefab;
            }
        }
        else if (otherprefab)
        {
            prefab = otherprefab;
        }
        else
        {
            return;
        }

        Transform instance = Instantiate(prefab);

        position.y            += instance.localScale.y * 0.5f;
        instance.localPosition = HexMetrics_Script.Perturb(position);
        instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f);
        instance.SetParent(container, false);
    }
Example #3
0
    void AddWallSegment(Vector3 pivot, HexCell_Script pivotCell,
                        Vector3 left, HexCell_Script leftCell,
                        Vector3 right, HexCell_Script rightCell)
    {
        if (pivotCell.IsUnderwater)
        {
            return;
        }

        bool hasLeftWall = !leftCell.IsUnderwater &&
                           pivotCell.GetEdgeType(leftCell) != HexEdgeType.Cliff;
        bool hasRightWall = !rightCell.IsUnderwater &&
                            pivotCell.GetEdgeType(rightCell) != HexEdgeType.Cliff;


        if (hasLeftWall)
        {
            if (hasRightWall)
            {
                bool hasTower = false;
                if (leftCell.Elevation == rightCell.Elevation)
                {
                    HexHash hash = HexMetrics_Script.SampleHashGrid((pivot + left + right) * (1f / 3f));

                    hasTower = hash.e < HexMetrics_Script.wallTowerTreshold;
                }
                AddWallSegment(pivot, left, pivot, right, hasTower);
            }
            else if (leftCell.Elevation < rightCell.Elevation)
            {
                AddWallWedge(pivot, left, right);
            }
            else
            {
                AddWallCap(pivot, left);
            }
        }
        else if (hasRightWall)
        {
            if (rightCell.Elevation < leftCell.Elevation)
            {
                AddWallWedge(right, pivot, left);
            }
            else
            {
                AddWallCap(right, pivot);
            }
        }
    }