예제 #1
0
    void DrawRiverHorizontal(IntegerPair start, IntegerPair end, System.Random generator)
    {
        if (end.X - start.X > 0)
        {
            DrawRiver(new IntegerPair(start.X + 1, start.Y), end, generator);
        }

        else if (end.X - start.X < 0)
        {
            DrawRiver(new IntegerPair(start.X - 1, start.Y), end, generator);
        }

        else
        {
            if (generator.Next(2) == 1)
            {
                DrawRiver(new IntegerPair(start.X + 1, start.Y), end, generator);
            }

            else
            {
                DrawRiver(new IntegerPair(start.X - 1, start.Y), end, generator);
            }
        }
    }
예제 #2
0
    void DrawRiverVertical(IntegerPair start, IntegerPair end, System.Random generator)
    {
        if (end.Y - start.Y > 0)
        {
            DrawRiver(new IntegerPair(start.X, start.Y + 1), end, generator);
        }

        else if (end.Y - start.Y < 0)
        {
            DrawRiver(new IntegerPair(start.X, start.Y - 1), end, generator);
        }

        else
        {
            if (generator.Next(2) == 1)
            {
                DrawRiver(new IntegerPair(start.X, start.Y + 1), end, generator);
            }

            else
            {
                DrawRiver(new IntegerPair(start.X, start.Y - 1), end, generator);
            }
        }
    }
        /// <summary>places it.
        /// Creates instance of an entity, attached to the given chunk, and at the given chunk indices and adds it to entity data.
        /// </summary>
        /// <param name="prefabName">Name of prefab to instance for entity</param>
        /// <param name="chunk">Map chunk to spawn entity</param>
        /// <param name="tileIndices">Tile indices in the chunk to spawn entity</param>
        /// <returns>Entity component of new instance.</returns>
        internal Entity Spawn(string prefabName, Chunk chunk, IntegerPair tileIndices)
        {
            GameObject prefab = prefabDictionary[prefabName];
            GameObject gOEntity;

            gOEntity = Instantiate(
                prefab,
                screenManager.GetScreenPositionAt(new Coordinates(chunk.lowerLeft.InWorld.X + tileIndices.I, chunk.lowerLeft.InWorld.Y + tileIndices.J)),
                Quaternion.identity
                );

            EntityMember entityMember = gOEntity.GetComponent <EntityMember>();

            if (entityMember)
            {
                if (!Place(entityMember, chunk, tileIndices))
                {
                    Destroy(entityMember.gameObject);
                    return(null);
                }
                return(entityMember);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Updates the entity location data, to the given chunk and it's tile indices
        /// </summary>
        /// <param name="entityMember">An entity component.</param>
        /// <param name="chunk">Chunk to place entity.</param>
        /// <param name="tileIndices">Tile indices in chunk to place entity.</param>
        /// <returns></returns>
        internal bool Place(EntityMember entityMember, Chunk chunk, IntegerPair tileIndices)
        {
            if (entityMember && chunk != null)
            {
                if (!IsOccupied(new Coordinates(chunk, tileIndices), entityMember.Type))
                {
                    entityMember.SetLocation(chunk, tileIndices);

                    if (entityMember.Type == "Player" && !playerCollection.Contains(entityMember))
                    {
                        playerCollection.Add(entityMember);
                    }
                    else if (entityMember.Type == "Mob" && !mobCollection.Contains(entityMember))
                    {
                        mobCollection.Add(entityMember);
                    }
                    //else if other types

                    entityMember.Placed = true;
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Returns world map coordinates from given tile position in the current tile array, with position (0,0) being lower left corner
        /// </summary>
        /// <param name="tileArrayIndices">Tile position in tile array of type IntegerPair</param>
        /// <returns>Coordinates holding world map location</returns>
        public Coordinates GetCoordinates(IntegerPair tileArrayIndices)
        {
            long x = tileArrayIndices.I - centerIndices.I + Focus.InWorld.X;
            long y = tileArrayIndices.J - centerIndices.J + Focus.InWorld.Y;

            return(new Coordinates(x, y));
        }
예제 #6
0
 /// <summary>
 /// Initialise a mount coordinate with Ra/Dec strings and axis positions in radians.
 /// </summary>
 /// <param name="altAz">The AltAzimuth coordinate for the mount</param>
 /// <param name="suggested">The suggested position for the axes (e.g. via a star catalogue lookup)</param>
 /// <param name="localTime">The local time of the observation</param>
 public MountCoordinate(string ra, string dec, IntegerPair axisPosition, Transform transform, double localJulianTimeUTC) : this(new EquatorialCoordinate(ra, dec))
 {
     _Equatorial        = new EquatorialCoordinate(ra, dec);
     _AltAzimuth        = this.GetAltAzimuth(transform, localJulianTimeUTC);
     _AxesPosition      = axisPosition;
     _AxisJulianTimeUTC = localJulianTimeUTC;
     _MasterCoordinate  = MasterCoordinateEnum.Equatorial;
 }
예제 #7
0
        public void Refresh(EquatorialCoordinate equatorial, IntegerPair axisPosition, Transform transform, double localJulianTimeUTC)
        {
            _Equatorial.RightAscension.Value = equatorial.RightAscension.Value;
            _Equatorial.Declination.Value    = equatorial.Declination.Value;
            _AxesPosition = axisPosition;

            _LocalJulianTimeUTC = localJulianTimeUTC;
            RefreshAltAzimuth(transform, localJulianTimeUTC);
            _MasterCoordinate = MasterCoordinateEnum.Equatorial;
        }
        protected override void Start()
        {
            base.Start();

            viewableTileDimensions = new IntegerPair();
            centerIndices          = new IntegerPair();
            centerPosition         = new Vector2(centerPositionX, centerPositionY);
            UpdateDimensions(screenManager.OrthographicSize);
            tileMap = tileMapComponent;
            ShowMap(false);
            tileMap.Position = centerPosition;
        }
예제 #9
0
 public void AddSource(IntegerPair start, IntegerPair end)
 {
     if (sourceCount < MAX_SOURCE_BRANCHES)
     {
         sources[sourceCount].Create(start, end);
         sourceCount++;
     }
     else
     {
         Debug.Log("Number of source branches already at max. No action taken.");
     }
 }
예제 #10
0
    /// <summary>
    ///  Returns the number of adjacent nodes that are true around one node on the binary map
    /// </summary>
    /// <param name="indices"></param>
    /// <returns></returns>
    int CountAdjacentTrue(IntegerPair indices)
    {
        int count = 0;

        for (Direction direction = Direction.North; direction <= Direction.Northwest; direction++)
        {
            if (AdjacentIsTrue(indices, direction))
            {
                count++;
            }
        }

        return(count);
    }
예제 #11
0
        /* METHODS */

        internal Chunk GetLoadedChunk(Coordinates coordinates)
        {
            if (!LoadedChunksContainCoordinates(coordinates))
            {
                return(null);
            }

            IntegerPair indices = new IntegerPair(
                (int)(coordinates.InChunks.X - world.LoadedChunks.lowerLeft.InChunks.X),
                (int)(coordinates.InChunks.Y - world.LoadedChunks.lowerLeft.InChunks.Y)
                );

            return(world.LoadedChunks.chunkArray[indices.I, indices.J]);
        }
예제 #12
0
    /// <summary>
    /// Looks at the node on the binary map that is adjacent to another node, given by indices, and checks if it's true. The adjacent node checked is given by
    /// a direction where 0 is north, 1 is north-east, 2 is east, ... etc
    /// </summary>
    /// <param name="indices">An IntegerPair that are the indices of the node to check on the binary map</param>
    /// <param name="direction">In</param>
    /// <returns></returns>
    bool AdjacentIsTrue(IntegerPair indices, Direction direction)
    {
        if (direction == Direction.North && indices.J < binaryMatrix.GetLength(1) - 1)
        {
            return(binaryMatrix[indices.I, indices.J + 1]);
        }

        else if (direction == Direction.Northeast && indices.J < binaryMatrix.GetLength(1) - 1 && indices.I < binaryMatrix.GetLength(0) - 1)
        {
            return(binaryMatrix[indices.I + 1, indices.J + 1]);
        }

        else if (direction == Direction.East && indices.I < binaryMatrix.GetLength(0) - 1)
        {
            return(binaryMatrix[indices.I + 1, indices.J]);
        }

        else if (direction == Direction.Southeast && indices.I < binaryMatrix.GetLength(0) - 1 && indices.J > 0)
        {
            return(binaryMatrix[indices.I + 1, indices.J - 1]);
        }

        else if (direction == Direction.South && indices.J > 0)
        {
            return(binaryMatrix[indices.I, indices.J - 1]);
        }

        else if (direction == Direction.Southwest && indices.J > 0 && indices.I > 0)
        {
            return(binaryMatrix[indices.I - 1, indices.J - 1]);
        }

        else if (direction == Direction.West && indices.I > 0)
        {
            return(binaryMatrix[indices.I - 1, indices.J]);
        }

        else if (direction == Direction.Northwest && indices.J < binaryMatrix.GetLength(1) - 1 && indices.I > 0)
        {
            return(binaryMatrix[indices.I - 1, indices.J + 1]);
        }

        else
        {
            return(false);
        }
    }
예제 #13
0
        public void SetLocation(Chunk newChunk, IntegerPair newIndices)
        {
            if (ParentCollection)
            {
                ParentCollection.UpdateLocation(this, new Coordinates(newChunk, newIndices));
            }

            if (newChunk != chunk)
            {
                if (chunk != null)
                {
                    chunk.entitySet.Remove(this);
                }
                chunk = newChunk;
                chunk.entitySet.Add(this);
            }

            tileIndices = newIndices;
        }
        internal void Populate(Chunk chunk)
        {
            if (chunk == null)
            {
                return;
            }

            int population = randomizer.Next(10);

            for (int i = 0; i < population; i++)
            {
                IntegerPair indices = new IntegerPair(randomizer.Next(Chunk.chunkTileWidth), randomizer.Next(Chunk.chunkTileWidth));

                Spawn("Cow", chunk, indices);
            }

            // START DEBUG CODE
            //if (chunk.lowerLeft.InChunks == new Coordinates(0, 0).InChunks)
            //{
            //    Spawn("Cow", chunk, new IntegerPair(randomizer.Next(Chunk.chunkTileWidth), randomizer.Next(Chunk.chunkTileWidth)));
            //}
            // END DEBUG CODE
        }
예제 #15
0
    private void DrawRiver(IntegerPair start, IntegerPair end, System.Random generator)
    {
        if (start.X == end.X && start.Y == end.Y)
        {
            binaryMatrix[start.X, start.Y] = true;
            return;
        }

        if (start.X >= 0 && start.Y >= 0 && start.X < binaryMatrix.GetLength(0) && start.Y < binaryMatrix.GetLength(1))
        {
            binaryMatrix[start.X, start.Y] = true;
        }

        if (generator.Next(2) == 1)
        {
            DrawRiverHorizontal(start, end, generator);
        }

        else
        {
            DrawRiverVertical(start, end, generator);
        }
    }
예제 #16
0
 public void Create(IntegerPair start, IntegerPair end)
 {
     this.start = start;
     this.end   = end;
     exists     = true;
 }
예제 #17
0
 public void AddMain(IntegerPair start, IntegerPair end)
 {
     main.Create(start, end);
 }
예제 #18
0
 public ChunkElevation()
 {
     mean  = 0;
     slope = new IntegerPair();
 }
예제 #19
0
 public ChunkElevation(int mean, IntegerPair slope)
 {
     this.mean  = mean;
     this.slope = slope;
 }
예제 #20
0
        /// <summary>
        /// Loads up chunks around a new world location. Currently just generates new chunks. Eventually will load chunks from
        /// procedual generation code with changes recorded in a list of locations.
        /// </summary>
        /// <param name="center"></param>
        internal void LoadChunksAt(Coordinates center)
        {
            Chunk[,] chunkArray = new Chunk[world.LoadedChunkWidth, world.LoadedChunkWidth];
            HashSet <Chunk> chunkSet = new HashSet <Chunk>();

            Coordinates loadedLowerLeft = new Coordinates(
                center.InChunks.X - world.loadedChunkDistance,
                center.InChunks.Y - world.loadedChunkDistance, 0, 0);

            IntegerPair offset = new IntegerPair(
                (int)(loadedLowerLeft.InChunks.X - world.LoadedChunks.lowerLeft.InChunks.X),
                (int)(loadedLowerLeft.InChunks.Y - world.LoadedChunks.lowerLeft.InChunks.Y)
                );

            for (int i = 0; i < world.LoadedChunkWidth; i++)
            {
                for (int j = 0; j < world.LoadedChunkWidth; j++)
                {
                    Coordinates chunkLowerLeft = new Coordinates(loadedLowerLeft.InChunks.X + i, loadedLowerLeft.InChunks.Y + j, 0, 0);

                    // If this chunk's coordinates are already contained in loaded chunks and still the same world seed,
                    // copy it over to the new chunk array in it's new position.
                    if (LoadedChunksContainCoordinates(chunkLowerLeft) && !newSeed)
                    {
                        // if (world.loadedChunks.chunkArray[i + offset.i, j + offset.j] != null) // Think I meant the following check:
                        if (world.LoadedChunks.chunkArray != null)
                        {
                            chunkArray[i, j] = world.LoadedChunks.chunkArray[i + offset.I, j + offset.J];
                        }
                        else
                        {
                            chunkArray[i, j] = LoadChunk(chunkLowerLeft);
                        }
                    }

                    // Else load the new chunk
                    else
                    {
                        chunkArray[i, j] = LoadChunk(chunkLowerLeft);
                    }

                    // Connect our chunks with references to the adjacent chunks for easy navigation
                    if (i > 0)                                             // Not in the first column
                    {
                        chunkArray[i, j].south     = chunkArray[i - 1, j]; // chunk in the column to left
                        chunkArray[i - 1, j].north = chunkArray[i, j];
                    }
                    if (j > 0)                                            // Not in the bottom row
                    {
                        chunkArray[i, j].west     = chunkArray[i, j - 1]; // chunk in the row below
                        chunkArray[i, j - 1].east = chunkArray[i, j];
                    }

                    chunkSet.Add(chunkArray[i, j]);
                }
            }

            // Unload all chunks not included in new chunk set
            for (int i = 0; i < world.LoadedChunkWidth; i++)
            {
                for (int j = 0; j < world.LoadedChunkWidth; j++)
                {
                    if (!chunkSet.Contains(world.LoadedChunks.chunkArray[i, j]))
                    {
                        UnloadChunk(world.LoadedChunks.chunkArray[i, j]);
                    }
                }
            }

            // Set the world's loadedchunks to the new chunks
            world.LoadedChunks.lowerLeft  = loadedLowerLeft;
            world.LoadedChunks.chunkArray = chunkArray;
            world.LoadedChunks.chunkSet   = chunkSet;
            world.LoadedChunks.hasLoaded  = true;
            newSeed = false;
        }
예제 #21
0
 public void SetObservedAxis(IntegerPair axisPosition, double observationTime)
 {
     _AxesPosition      = axisPosition;
     _AxisJulianTimeUTC = observationTime;
 }
예제 #22
0
 public Coordinates(Chunk chunk, IntegerPair tileIndices)
 {
     world      = new WorldCoordinates(chunk.lowerLeft.InChunks.X * Chunk.chunkTileWidth + tileIndices.I, chunk.lowerLeft.InChunks.Y * Chunk.chunkTileWidth + tileIndices.J);
     this.chunk = new ChunkCoordinates(world);
 }
예제 #23
0
    void GenerateRiverValleys(GameObject[,] chunkMap)
    {
        ClearBinaryMatrix();

        for (int i = 0; i < elevationMap.GetLength(0); i++)
        {
            for (int j = 0; j < elevationMap.GetLength(1); j++)
            {
                RiverValley          riverValley;
                ChunkElevation       centerElevation;
                ChunkElevation       northElevation;
                ChunkElevation       eastElevation;
                ChunkElevation       southElevation;
                ChunkElevation       westElevation;
                OrderedElevationList adjacentRiverValleys = new OrderedElevationList();

                centerElevation = elevationMap[i, j];

                if (j < elevationMap.GetLength(1) - 1)
                {
                    northElevation = elevationMap[i, j + 1];
                    if (northElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(northElevation);
                    }
                }
                else
                {
                    northElevation = new ChunkElevation();
                }

                if (i < elevationMap.GetLength(0) - 1)
                {
                    eastElevation = elevationMap[i + 1, j];
                    if (eastElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(eastElevation);
                    }
                }
                else
                {
                    eastElevation = new ChunkElevation();
                }

                if (j > 0)
                {
                    southElevation = elevationMap[i, j - 1];
                    if (southElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(southElevation);
                    }
                }
                else
                {
                    southElevation = new ChunkElevation();
                }

                if (i > 0)
                {
                    westElevation = elevationMap[i - 1, j];
                    if (westElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(westElevation);
                    }
                }
                else
                {
                    westElevation = new ChunkElevation();
                }

                // if below elevation threshold and there's adjacent river valleys, assume center chunk has a river valley
                if (centerElevation.Mean < mapGenerationData.valleyElevationMaximum && adjacentRiverValleys.Count != 0)
                {
                    IntegerPair    start;
                    IntegerPair    end;
                    ChunkElevation lowest;


                    riverValley = new RiverValley(true);


                    //if center lowest
                    //  main.end = center.slope
                    //  main.start = toward lowest edge.slope
                    //  branch.end = center.slope
                    //  branch.start = toward branch edge.slope
                    //
                    //if center highest ie. multiple main starts
                    //
                    //  main.end = toward lowest edge.slope
                    //  main.start = toward centre.slope
                    //  branch.start = toward center.slope
                    //  branch.end = toward branch edge.slope
                    //
                    //if no adjacent river valleys
                    //  nothing
                    //
                    //if one adjacent lower valley
                    //  either center lowest or highest for main
                    //  no branches
                    //
                    //multiple adjacent valleys
                    //  main.end = toward lowest edge.slope
                    //  main.start = toward second lowest edge.slope
                    //  branch.end = center.slope
                    //  branch.start = toward branch edge.slope

                    lowest = adjacentRiverValleys.PickLowest;

                    if (centerElevation.Mean <= lowest.Mean)
                    {
                        if (lowest == northElevation)
                        {
                            start = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), chunkTileWidth - 1);
                        }
                        else if (lowest == eastElevation)
                        {
                            start = new IntegerPair(chunkTileWidth - 1, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else if (lowest == southElevation)
                        {
                            start = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), 0);
                        }
                        else if (lowest == westElevation)
                        {
                            start = new IntegerPair(0, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else
                        {
                            Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                            start = new IntegerPair();
                        }
                        end = centerElevation.Slope;
                    }
                    else
                    {
                        if (lowest == northElevation)
                        {
                            end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), chunkTileWidth - 1);
                        }
                        else if (lowest == eastElevation)
                        {
                            end = new IntegerPair(chunkTileWidth - 1, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else if (lowest == southElevation)
                        {
                            end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), 0);
                        }
                        else if (lowest == westElevation)
                        {
                            end = new IntegerPair(0, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else
                        {
                            Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                            end = new IntegerPair();
                        }
                        start = centerElevation.Slope;
                    }

                    riverValley.AddMain(start, end);

                    while (adjacentRiverValleys.Count > 0)
                    {
                        lowest = adjacentRiverValleys.PickLowest;

                        if (centerElevation.Mean <= lowest.Mean)
                        {
                            if (lowest == northElevation)
                            {
                                start = new IntegerPair(
                                    Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2),
                                    chunkTileWidth - 1);
                            }
                            else if (lowest == eastElevation)
                            {
                                start = new IntegerPair(
                                    chunkTileWidth - 1,
                                    Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else if (lowest == southElevation)
                            {
                                start = new IntegerPair(
                                    Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2),
                                    0);
                            }
                            else if (lowest == westElevation)
                            {
                                start = new IntegerPair(
                                    0,
                                    Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else
                            {
                                Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                                start = new IntegerPair();
                            }
                            end = centerElevation.Slope;
                        }
                        else
                        {
                            if (lowest == northElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + chunkTileWidth - 1) / 2));
                            }
                            else if (lowest == eastElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + chunkTileWidth - 1) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else if (lowest == southElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y) / 2));
                            }
                            else if (lowest == westElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else
                            {
                                Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                                end = new IntegerPair();
                            }
                            start = centerElevation.Slope;
                        }
                        riverValley.AddSource(start, end);
                    }
                }
                else
                {
                    riverValley = new RiverValley(false);
                }

                if (riverValley.Exists)
                {
                    if (riverValley.Main.Exists)
                    {
                        //Draw Main Branch
                        DrawRiver(
                            new IntegerPair(chunkTileWidth * i + riverValley.Main.Start.X, chunkTileWidth * j + riverValley.Main.Start.Y),
                            new IntegerPair(chunkTileWidth * i + riverValley.Main.End.X, chunkTileWidth * j + riverValley.Main.End.Y),
                            generatorMatrix[i, j]);
                    }
                    for (int source = 0; source < riverValley.SourceCount; source++)
                    {
                        DrawRiver(
                            new IntegerPair(chunkTileWidth * i + riverValley.Source(source).Start.X, chunkTileWidth * j + riverValley.Source(source).Start.Y),
                            new IntegerPair(chunkTileWidth * i + riverValley.Source(source).End.X, chunkTileWidth * j + riverValley.Source(source).End.Y),
                            generatorMatrix[i, j]);
                    }
                }
            }
        }

        //SmoothShapeEdges();
        ApplyBinaryMatrixToMap(chunkMap, mapGenerationData.waterTilePrefab);
    }