Exemplo n.º 1
0
        public override bool TryPlaceFeatureAtLocation(
            IHexCell cell, Vector3 location, int locationIndex, HexHash hash
            )
        {
            var nodeOnCell = ResourceNodeLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            if (nodeOnCell == null ||
                (hash.A >= Config.ResourceAppearanceChance && locationIndex % Config.GuaranteedResourceModulo != 0) ||
                !VisibilityCanon.IsResourceVisible(nodeOnCell.Resource)
                )
            {
                return(false);
            }

            AddFeature(nodeOnCell.Resource.AppearancePrefab, location, hash);
            return(true);
        }
Exemplo n.º 2
0
        private void GetUVPatch(
            HexHash hash, FarmQuad quad
            )
        {
            if (hash.A <= 0.5f)
            {
                quad.BottomLeftUV  = new Vector2(0f, 0f);
                quad.BottomRightUV = new Vector2(1f, 0f);
                quad.TopLeftUV     = new Vector2(0f, 1f);
                quad.TopRightUV    = new Vector2(1f, 1f);
            }
            else
            {
                quad.BottomLeftUV  = new Vector2(0f, 0f);
                quad.BottomRightUV = new Vector2(0f, 1f);
                quad.TopLeftUV     = new Vector2(1f, 0f);
                quad.TopRightUV    = new Vector2(1f, 1f);
            }

            quad.Color = RenderConfig.FarmColors[Mathf.FloorToInt(hash.C * RenderConfig.FarmColors.Count)];
        }
 public abstract bool TryPlaceFeatureAtLocation(
     IHexCell cell, Vector3 location, int locationIndex, HexHash hash
     );
 private HexDirection GetBestDirection(HexDirection startDirection, List <HexDirection> otherDirections, HexHash hash)
 {
     if (otherDirections.Contains(startDirection.Opposite()))
     {
         return(startDirection.Opposite());
     }
     else if (otherDirections.Contains(startDirection.Next2()))
     {
         return(startDirection.Next2());
     }
     else if (otherDirections.Contains(startDirection.Previous2()))
     {
         return(startDirection.Previous2());
     }
     else
     {
         return(otherDirections[Mathf.FloorToInt(hash.A * otherDirections.Count)]);
     }
 }
Exemplo n.º 5
0
        public override bool TryPlaceFeatureAtLocation(IHexCell cell, Vector3 location, int locationIndex, HexHash hash)
        {
            var encampmentOnCell = EncampmentLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            if (encampmentOnCell == null || (hash.A >= Config.EncampmentAppearanceChance && locationIndex % Config.GuaranteedEncampmentModulo != 0))
            {
                return(false);
            }

            int encampmentIndex = (int)(hash.C * Config.EncampmentPrefabs.Count);

            AddFeature(Config.EncampmentPrefabs[encampmentIndex], location, hash);

            return(true);
        }
Exemplo n.º 6
0
        /* The intention here is to find the AABB of the blob
         * and then draw another quad that contains the AABB but
         * is aligned to the edges of the hexagons rather than
         * world axes. We then use that box's edges to draw lines
         * that go across the hex diagonally.
         */
        private void DrawLines(
            List <IHexCell> farmBlob, out List <FarmLine> toNortheastLines, out List <FarmLine> toNorthwestLines
            )
        {
            if (RenderConfig.FarmPatchMaxWidth <= 0f)
            {
                throw new InvalidOperationException("RenderConfig.FarmPatchMaxWidth must be greater than zero");
            }

            toNortheastLines = new List <FarmLine>();
            toNorthwestLines = new List <FarmLine>();

            Rect boundingRect = GetBlobRect(farmBlob);

            Vector2 aabbBottomLeft  = new Vector2(boundingRect.xMin, boundingRect.yMin);
            Vector2 aabbBottomRight = new Vector2(boundingRect.xMax, boundingRect.yMin);
            Vector2 aabbTopLeft     = new Vector2(boundingRect.xMin, boundingRect.yMax);
            Vector2 aabbTopRight    = new Vector2(boundingRect.xMax, boundingRect.yMax);

            Vector2 toNortheastDirection = RenderConfig.GetEdgeMidpointXZ(HexDirection.NE).normalized;

            Vector2 toNorthwestDirection = new Vector2(toNortheastDirection.y, -toNortheastDirection.x).normalized;

            Vector2 eastPoint, southPoint, westPoint;

            Geometry2D.ClosestPointsOnTwoLines(
                aabbBottomRight, toNortheastDirection,
                aabbTopRight, toNorthwestDirection,
                out eastPoint, out eastPoint
                );

            Geometry2D.ClosestPointsOnTwoLines(
                aabbBottomLeft, toNorthwestDirection,
                aabbBottomRight, toNortheastDirection,
                out southPoint, out southPoint
                );

            Geometry2D.ClosestPointsOnTwoLines(
                aabbBottomLeft, toNorthwestDirection,
                aabbTopLeft, toNortheastDirection,
                out westPoint, out westPoint
                );

            float southToWestDistance = (southPoint - westPoint).magnitude;
            float southToEastDistance = (southPoint - eastPoint).magnitude;

            //Draws the line segments going northeast
            for (float t = 0; t <= 1f;)
            {
                Vector2 start = Vector2.Lerp(southPoint, westPoint, t);

                toNortheastLines.Add(new FarmLine(start, toNortheastDirection));

                HexHash hash = NoiseGenerator.SampleHashGrid(start);

                t += Mathf.Lerp(RenderConfig.FarmPatchMinWidth, RenderConfig.FarmPatchMaxWidth, hash.A) / southToWestDistance;
            }

            //Draws the line segments going northwest
            for (float t = 0; t <= 1f;)
            {
                Vector2 start = Vector2.Lerp(southPoint, eastPoint, t);

                toNorthwestLines.Add(new FarmLine(start, toNorthwestDirection));

                HexHash hash = NoiseGenerator.SampleHashGrid(start);

                t += Mathf.Lerp(RenderConfig.FarmPatchMinWidth, RenderConfig.FarmPatchMaxWidth, hash.A) / southToEastDistance;
            }
        }
Exemplo n.º 7
0
        public override bool TryPlaceFeatureAtLocation(IHexCell cell, Vector3 location, int locationIndex, HexHash hash)
        {
            if (cell.Feature != CellFeature.CityRuins ||
                (hash.A >= Config.RuinsAppearanceChance) && locationIndex % Config.GuaranteedRuinsModulo != 0
                )
            {
                return(false);
            }

            int ruinIndex = (int)(hash.C * Config.RuinsPrefabs.Count);

            AddFeature(Config.RuinsPrefabs[ruinIndex], location, hash);

            return(true);
        }
Exemplo n.º 8
0
        public override bool TryPlaceFeatureAtLocation(IHexCell cell, Vector3 location, int locationIndex, HexHash hash)
        {
            var cityOnCell = CityLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            if (cityOnCell == null || (hash.A >= Config.BuildingAppearanceChance && locationIndex % Config.GuaranteedBuildingModulo != 0))
            {
                return(false);
            }

            int buildingIndex = (int)(hash.C * Config.BuildingPrefabs.Count);

            AddFeature(Config.BuildingPrefabs[buildingIndex], location, hash);

            return(true);
        }