public GridPoint GetFreeGridPoint(int clearance, int attempts = 5)
    {
        if (attempts == -1)
        {
            return(null);
        }
        attempts--;
        GridPoint testPoint = GenRan.RandomFromList(FreePoints);

        for (int x = -clearance; x <= clearance; x++)
        {
            for (int z = -clearance; z <= clearance; z++)
            {
                Vec2i p = testPoint.GridPos + new Vec2i(x, z);
                if (GridPlacement.InGridBounds(p))
                {
                    GridPoint gp = GameGen.GridPlacement.GridPoints[p.x, p.z];
                    if (gp == null)
                    {
                        continue;
                    }
                    if (gp.HasNonSettlementStructure)
                    {
                        return(GetFreeGridPoint(clearance, attempts));
                    }
                }
            }
        }
        FreePoints.Remove(testPoint);
        testPoint.HasNonSettlementStructure = true;
        return(testPoint);
    }
Ejemplo n.º 2
0
 private void ScrollToMain(LogicalExtent scrollTo, GridPlacement placement)
 {
     _scrollToMain          = scrollTo;
     _scrollToMainPlacement = placement;
     SetScrollDeltaMain(0, false);
     InvalidateMeasure();
 }
Ejemplo n.º 3
0
        private RowPresenter ScrollByPage(GridPlacement placement)
        {
            UpdateLayout();
            if (ContainerViewList.Count == 0)
            {
                return(null);
            }

            if (CurrentContainerViewPlacement == CurrentContainerViewPlacement.BeforeList ||
                CurrentContainerViewPlacement == CurrentContainerViewPlacement.AfterList)
            {
                EnsureVisibleMain(CurrentRow.View);
                UpdateLayout();
            }

            Debug.Assert(CurrentContainerViewPlacement == CurrentContainerViewPlacement.WithinList);

            int currentContainerOrdinal = CurrentContainerView.ContainerOrdinal;
            var containerOrdinal        = GetContainerOrdinalByPage(placement, false);
            var scrolled = placement == GridPlacement.Head ? ScrollByPageUp(containerOrdinal) : ScrollByPageDown(containerOrdinal);

            if (scrolled)
            {
                UpdateLayout();
                containerOrdinal = GetContainerOrdinalByPage(placement, true);
            }

            return(GetRowPresenter(containerOrdinal));
        }
Ejemplo n.º 4
0
    public void Init(ChunkBase2[,] chunks, GridPlacement gp, List <WorldLocation> eventLocations)
    {
        Groups        = new Dictionary <Vec2i, List <EntityGroup> >();
        PathFinder    = new WorldEventPathFinder(chunks);
        GridPlacement = gp;
        ChunkBases    = chunks;

        WorldEventLocations = eventLocations;


        ThreadLock = new Object();
        GenRan     = new GenerationRandom(0);
    }
Ejemplo n.º 5
0
        private void AdjustScrollToMain()
        {
            if (_scrollDeltaMain != 0)
            {
                AdjustScrollToMain(true);
            }

            if (_scrollToMainPlacement == GridPlacement.Tail)
            {
                _scrollToMainPlacement = GridPlacement.Head;
                var delta = GridTracksMain.AvailableLength - FrozenTailLengthMain - FrozenHeadLengthMain;
                AdjustScrollToMain(-delta, true);
            }
        }
Ejemplo n.º 6
0
    public void GenerateWorld()
    {
        //We start by generating terrain
        //This generates all height map, ocean, lakes, and rivers
        //It also calculates biomes
        TerGen = new TerrainGenerator2(this, Seed);
        TerGen.Generate();
        GridPlacement = new GridPlacement(this);
        //We generate the initial grid points
        GridPlacement.GenerateInitialGridPoints();

        Debug.BeginDeepProfile("KingdomGen");
        KingdomGen = new KingdomGenerator2(this);
        //We decide the placement of each kingdom capital, and then claim territory
        KingdomGen.ClaimKingdomChunks();
        KingdomGen.GenerateKingdoms();
        Debug.EndDeepProfile("KingdomGen");


        Debug.BeginDeepProfile("SettleShellGen");
        SettlementGen = new SettlementGenerator2(this);
        SettlementGen.GenerateAllSettlementShells();
        SettlementGen.GenerateAllTacticalLocationShells();
        SettlementGen.CalculateTactialAndSettlementData();
        //SettlementGen.GenerateAllSettlements(KingdomGen.Kingdoms);
        Debug.EndDeepProfile("SettleShellGen");


        Debug.BeginDeepProfile("StructShellGen");

        StructureGen = new ChunkStructureGenerator2(this);
        StructureGen.GenerateAllShells();
        Debug.EndDeepProfile("StructShellGen");

        Debug.BeginDeepProfile("SetChunksGen");
        PreGeneratedChunks = SettlementGen.GenerateAllSettlementChunks();
        Debug.EndDeepProfile("SetChunksGen");

        EntityGenerator = new EntityGenerator(this, EntityManager.Instance);

        return;

        FillWorldEventLocations();
        World.ChunkBases2 = TerGen.ChunkBases;

        Debug.BeginDeepProfile("WorldEventInit");
        WorldEventManager.Instance.Init(TerGen.ChunkBases, GridPlacement, WorldEventLocations);
        Debug.EndDeepProfile("WorldEventInit");
    }
Ejemplo n.º 7
0
        private void VerifyGridExtent(int gridExtent, string gridExtentParamName,
                                      GridPlacement placement, string placementParamName, int maxGridExtent)
        {
            VerifyGridExtent(gridExtent, gridExtentParamName, maxGridExtent);

            if (gridExtent == 0 && placement == GridPlacement.Tail)
            {
                throw new ArgumentException(DiagnosticMessages.GridPlacement_InvalidTailValue, placementParamName);
            }

            if (gridExtent == maxGridExtent && placement == GridPlacement.Head)
            {
                throw new ArgumentException(DiagnosticMessages.GridPlacement_InvalidHeadValue, placementParamName);
            }
        }
Ejemplo n.º 8
0
 protected void ScrollToMain(int gridExtent, double fraction, GridPlacement placement, bool virtualizeAll)
 {
     VerifyLogicalExtent(gridExtent, fraction, MaxGridExtentMain);
     if (_scrollToMain.GridExtent == gridExtent && _scrollToMain.Fraction.IsClose(fraction) &&
         _scrollToMainPlacement == placement &&
         _scrollDeltaMain == 0)
     {
         return;
     }
     ScrollToMain(new LogicalExtent(gridExtent, fraction), placement);
     if (virtualizeAll)
     {
         ContainerViewList.VirtualizeAll();
     }
 }
Ejemplo n.º 9
0
    void Start()
    {
        gridPlacement = this.GetComponent <GridPlacement>();

        foreach (RTSPrefab rtsP in gridPlacement.prefabs)
        {
            nameDimensionMap.Add(rtsP.Name, rtsP.Dimensions);
        }

        for (int i = 0; i < gridWidth; ++i)
        {
            for (int k = 0; k < gridHeight; ++k)
            {
                discreteGrid.Add(new Vector2(i, k), null);
            }
        }
    }
Ejemplo n.º 10
0
        protected void ScrollToCross(int gridExtent, double fraction, GridPlacement placement)
        {
            VerifyLogicalExtent(gridExtent, fraction, MaxGridExtentCross);
            var logicalTrack = GetLogicalCrossTrack(gridExtent);

            Debug.Assert(!logicalTrack.IsEof);
            if (placement == GridPlacement.Head)
            {
                var extent = logicalTrack.StartExtent + logicalTrack.GridTrack.MeasuredLength * fraction;
                InternalScrollBy(0, extent - FrozenHeadLengthCross - ScrollOffsetCross);
            }
            else
            {
                var position = logicalTrack.EndPosition - logicalTrack.GridTrack.MeasuredLength * (1 - fraction);
                InternalScrollBy(0, position - (ViewportCross - FrozenTailLengthCross));
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// We generate all grid points for the world
 /// Each is equally spaced
 /// </summary>
 public void GenerateInitialGridPoints()
 {
     for (int x = 0; x < GridSize; x++)
     {
         for (int z = 0; z < GridSize; z++)
         {
             /* Vec2i cPos = new Vec2i(Mathf.Clamp(x * GridPointSize + (int)GenRan.GaussianFloat(0, GridPointSize/6), 0, World.WorldSize-1),
              *                      Mathf.Clamp(z * GridPointSize + (int)GenRan.GaussianFloat(0, GridPointSize/6), 0, World.WorldSize - 1));*/
             Vec2i cPos = new Vec2i(x * GridPointSize, z * GridPointSize);
             GridPoints[x, z] = new GridPoint(new Vec2i(x, z), cPos);
             if (GameGen.TerGen.ChunkBases[cPos.x, cPos.z].Biome != ChunkBiome.ocean)
             {
                 GridPoints[x, z].IsValid = true;
             }
             else
             {
                 GridPoints[x, z].IsValid = false;
             }
         }
     }
     for (int x = 0; x < GridSize; x++)
     {
         for (int z = 0; z < GridSize; z++)
         {
             if (GridPoints[x, z] != null)
             {
                 //We iterate all nearest neighbors of this grid point
                 for (int i = 0; i < WorldEventPathFinder.DIRS.Length; i++)
                 {
                     int   x_ = x + WorldEventPathFinder.DIRS[i].x;
                     int   z_ = z + WorldEventPathFinder.DIRS[i].z;
                     Vec2i p  = new Vec2i(x_, z_);
                     //Check this neighbor is in bounds, and is a valid grid point
                     if (GridPlacement.InGridBounds(p) && GridPoints[p.x, p.z] != null && GridPoints[p.x, p.z].IsValid)
                     {
                         GridPoints[x, z].NearestNeighbors.Add(p);
                     }
                 }
             }
         }
     }
     CalculateEnclosedBiomes();
 }
Ejemplo n.º 12
0
 public sealed override void ScrollToX(int gridExtent, double fraction, GridPlacement placement)
 {
     ScrollToCross(gridExtent, fraction, placement);
 }
    /// <summary>
    /// Iterates through all grid points and checks for valid ones (on land, no settlement or tactloc).
    /// We then add them to a weighted random list, with locations surrounded by settlements having a lower weighting
    /// we then return this list for use
    /// </summary>
    /// <returns></returns>
    private WeightedRandomList <GridPoint> FindFreeGridPoints()
    {
        WeightedRandomList <GridPoint> gridPoints = new WeightedRandomList <GridPoint>();

        int radius = 2;

        for (int x = 0; x < GridPlacement.GridSize; x++)
        {
            for (int z = 0; z < GridPlacement.GridSize; z++)
            {
                GridPoint gp = GameGen.GridPlacement.GridPoints[x, z];
                if (!gp.IsValid)
                {
                    continue;
                }

                if (gp.ChunkPos.QuickDistance(GameGen.TerGen.EvilDragonMountainPeak) < 100 * 100)
                {
                    continue;
                }

                if (gp.ChunkPos.QuickDistance(GameGen.TerGen.GoodDragonMountainPeak) < 60 * 60)
                {
                    continue;
                }

                float weight = 10;

                //If there is something here, then we ignore this point
                if (gp.Shell != null)
                {
                    continue;
                }
                Debug.Log("No shell");
                for (int rx = -radius; rx <= radius; rx++)
                {
                    if (weight <= 0)
                    {
                        break;
                    }
                    for (int rz = -radius; rz <= radius; rz++)
                    {
                        Vec2i testPos = new Vec2i(x + rx, z + rz);
                        //Distance from gridpoint to this point
                        float dist = Mathf.Sqrt(rx * rx + rz * rz);
                        if (GridPlacement.InGridBounds(testPos))
                        {
                            //Get near point
                            GridPoint gp2 = GameGen.GridPlacement.GridPoints[testPos.x, testPos.z];
                            if (gp2.Shell != null)
                            {
                                //If too close, then point not valid
                                if (dist <= 1)
                                {
                                    weight -= 5;
                                }
                                else
                                {
                                    weight -= 3f / dist;
                                }
                            }
                        }
                    }
                }
                if (weight > 0)
                {
                    gridPoints.AddElement(gp, weight);
                }
            }
        }

        return(gridPoints);
    }
Ejemplo n.º 14
0
 public abstract void ScrollToY(int gridExtent, double fraction, GridPlacement placement);
Ejemplo n.º 15
0
 void Start()
 {
     gridPlacement = this.GetComponent<GridPlacement>();
 }
Ejemplo n.º 16
0
 protected double GetPositionCross(int gridExtent, GridPlacement placement)
 {
     return(placement == GridPlacement.Tail
         ? GetLogicalCrossTrack(gridExtent - 1).EndPosition
         : GetLogicalCrossTrack(gridExtent).StartPosition);
 }
Ejemplo n.º 17
0
 protected abstract double GetPositionYCore(int gridExtentY, GridPlacement placement);
Ejemplo n.º 18
0
 public double GetPositionY(int gridExtentY, GridPlacement placement)
 {
     VerifyGridExtent(gridExtentY, nameof(gridExtentY), placement, nameof(placement), MaxGridExtentY);
     return(GetPositionYCore(gridExtentY, placement));
 }
Ejemplo n.º 19
0
 public double GetPositionX(int gridExtentX, GridPlacement placement)
 {
     VerifyGridExtent(gridExtentX, nameof(gridExtentX), placement, nameof(placement), MaxGridExtentX);
     return(GetPositionXCore(gridExtentX, placement));
 }
Ejemplo n.º 20
0
 private int GetContainerOrdinalByPage(GridPlacement placement, bool enforceCurrent)
 {
     return(placement == GridPlacement.Head ? GetPageHeadContainerOrdinal(enforceCurrent) : GetPageTailContainerOrdinal(enforceCurrent));
 }
Ejemplo n.º 21
0
    void Start()
    {
        gridPlacement = this.GetComponent<GridPlacement>();

        foreach (RTSPrefab rtsP in gridPlacement.prefabs)
        {
            nameDimensionMap.Add(rtsP.Name, rtsP.Dimensions);
        }

        for (int i = 0; i < gridWidth; ++i)
        {
            for (int k = 0; k < gridHeight; ++k)
            {
                discreteGrid.Add(new Vector2(i, k), null);
            }
        }
    }
Ejemplo n.º 22
0
 void Start()
 {
     gridPlacement = this.GetComponent <GridPlacement>();
 }
Ejemplo n.º 23
0
 public GridPathFinder(GridPlacement gp)
 {
     GridPlacement = gp;
 }
Ejemplo n.º 24
0
 protected sealed override double GetPositionYCore(int gridExtentY, GridPlacement placement)
 {
     return(GetPositionMain(gridExtentY, placement));
 }
Ejemplo n.º 25
0
 protected sealed override double GetPositionXCore(int gridExtentX, GridPlacement placement)
 {
     return(GetPositionCross(gridExtentX, placement));
 }
Ejemplo n.º 26
0
 public sealed override void ScrollToY(int gridExtent, double fraction, GridPlacement placement)
 {
     ScrollToMain(gridExtent, fraction, placement, true);
 }
Ejemplo n.º 27
0
    /// <summary>
    ///  Calculates the location data for the supplied shell
    /// </summary>
    /// <param name="shell">The shell to generate and store data to</param>
    private void GenerateLocationData(Shell shell)
    {
        GridPoint gp = shell.GridPoint;

        bool onBorder = false;
        bool onRiver  = false;
        bool onCoast  = false;
        bool onLake   = false;
        //Get the chunk this grid point is on
        ChunkBase2 cb = GameGen.TerGen.ChunkBases[gp.ChunkPos.x, gp.ChunkPos.z];

        int kingdomID = cb.KingdomID;

        if (kingdomID == -1)
        {
            Debug.Error("Shell " + shell + " lays on unclaimed territory - not valid");
        }
        //iterate away from search point
        for (int i = 1; i < GridPlacement.GridPointSize; i++)
        {
            //Search in 4 directions
            foreach (Vec2i v in Vec2i.OCT_DIRDIR)
            {
                //Find the point in this direction
                Vec2i p = cb.Pos + v * i;
                //Ensure in world bounds
                if (GameGenerator2.InBounds(p))
                {
                    //Get chunk here
                    ChunkBase2 cb_p = GameGen.TerGen.ChunkBases[p.x, p.z];
                    if (cb_p.Biome == ChunkBiome.ocean)
                    {
                        onCoast = true;
                    }
                    if (cb_p.KingdomID != -1 && cb_p.KingdomID != kingdomID)
                    {
                        onBorder = true;
                    }
                    if (cb_p.ChunkFeature is ChunkRiverNode)
                    {
                        onRiver = true;
                    }
                }
            }
        }
        //Define entraces
        bool[] entrances = new bool[8];
        for (int i = 0; i < 8; i++)
        {
            foreach (Vec2i v in Vec2i.OCT_DIRDIR)
            {
                Vec2i p = gp.GridPos + v;
                if (GridPlacement.InGridBounds(p))
                {
                    GridPoint gp2 = GameGen.GridPlacement.GridPoints[p.x, p.z];
                    if (gp2.HasRoad)
                    {
                        entrances[i] = true;
                    }
                    else
                    {
                        entrances[i] = false;
                    }
                }
            }
        }
        LocationData ld = new LocationData()
        {
            OnCoast = onCoast, OnLake = onLake, OnRiver = onRiver, OnBorder = onBorder, EntranceDirections = entrances
        };

        shell.SetLocationData(ld);
        Vec2i size = shell.GetSize();

        ChunkBase2[,] bases = new ChunkBase2[size.x, size.z];
        //Iterate chunk bases that belong to this shell, add them to the array
        for (int x = 0; x < size.x; x++)
        {
            for (int z = 0; z < size.z; z++)
            {
                bases[x, z] = GameGen.TerGen.ChunkBases[x, z];
            }
        }
        //Set bases
        shell.SetChunkBases(bases);
    }