public Biome GetBiomeAt(Coords coords) { return(GetHexAt(coords).HexBiome); }
/** * <summary> * Returns the Color of the Hex at the specified Coords. * Color here is based on the HumidityLevel of that Hex. * </summary> * <param name="coords">Coords of the Hex to be queried.</param> * <returns>The humidity-based Color of the Hex at <paramref name="coords"/>.</returns> */ public Color HumidityColorAt(Coords coords) { return(_map[coords.x, coords.y].GetHumidityColor()); }
public Tuple <Hex.TemperatureLevel, Hex.HumidityLevel> GetTemperatureAndHumidityAt(Coords coords) { Hex hex = GetHexAt(coords); Tuple <Hex.TemperatureLevel, Hex.HumidityLevel> rv = new Tuple <Hex.TemperatureLevel, Hex.HumidityLevel>(hex.Temperature, hex.Humidity); return(rv); }
/** <summary> * Get a list of all coords adjacent to the given coords, filtered such that: * - All returned coords are contained in the valid hex list * - All returned coords can be expanded to, per implementation of CanExpandTo() * </summary> * <param name="coords">Coords for which to find valid adjacent hexes.</param> * <returns>A dictionary of valid coordinates adjacent to <paramref name="coords"/>, keyed by which * side of the hex at the given coords they are adjacent to.</returns> */ private Dictionary <Hex.Side, Coords> GetFilteredAdjacency(Coords coords) { return(_map.GetFilteredAdjacency(coords, (x => _validHexes.Contains(x) && CanExpandTo(x)))); }
/** * <summary> * Returns the Color of the Hex at the specified Coords. * Color here is based on the TemperatureLevel of that Hex. * </summary> * <param name="coords">Coords of the Hex to be queried.</param> * <returns>The temperature-based Color of the Hex at <paramref name="coords"/>.</returns> */ public Color TemperatureColorAt(Coords coords) { return(_map[coords.x, coords.y].GetTemperatureColor()); }
/** * <summary> * Sets whether the Hex at given Coords is placeable; that is, whether * the Hex can be made a land Hex or not. * </summary> * <param name="coords">The Coords of the Hex to update.</param> * <param name="placeable">True if the Hex can be made into a land Hex, false if not.</param> */ public void SetPlaceable(Coords coords, bool placeable) { Hex hex = GetHexAt(coords); hex.CanPlace = placeable; }
/** * <summary> * Predicate to determine whether two Coords are adjacent on this HexMap. * </summary> * <remarks> * Takes wraparound into account. * </remarks> * <param name="a">First of the Coords to check.</param> * <param name="b">Second of the Coords to check.</param> * <returns> * True if the Coords <paramref name="a"/> and <paramref name="b"/> are * adjacent, false otherwise. * </returns> */ public bool IsAdjacent(Coords a, Coords b) { var allAdj = GetAllAdjacentCoords(a); return(allAdj.ContainsValue(b)); }
public bool CoordsWrap(Coords a, Coords b) { return((a.x == (_world.Width - 1) && b.x == 0) || (b.x == (_world.Width - 1) && a.x == 0)); }
/** * <summary> * Copy constructor copies x and y, as well as validity flag. * </summary> * <param name="other">The Coords object to copy.</param> */ public Coords(Coords other) { this.x = other.x; this.y = other.y; this.invalid = other.invalid; }
/** <summary> * Expand the given property in the map, within a set of coords predetermined * to point to hexes valid for expansion. * </summary> * <param name="validHexes">List of all coords containing hexes which are valid to expand to.</param> * <param name="size">The number of hexes to expand.</param> * <return>The list of all coords whose corresponding hexes were modified by this expansion.</return> */ public List <Coords> Expand(List <Coords> validHexes, int size) { int width = _map.Width; int height = _map.Height; _totalHexes = _remainingHexes = size; _validHexes = validHexes; // list of coords to be expanded out from, but which have not been expanded from yet List <Coords> unexpanded = new List <Coords>(); // list of coords to expand from again List <Coords> expandAgain = new List <Coords>(); List <Coords> rv = new List <Coords>(); // Select a valid hex at random to start from bool placedSeed = false; int attempts = 0; int totalValidHexes = validHexes.Count; while (!placedSeed && (attempts < totalValidHexes)) { int i = _rand.GenerateInt(totalValidHexes); Coords seedCoords = validHexes[i]; if (CanExpandFirst(seedCoords)) { placedSeed = ModHex(seedCoords); if (placedSeed) { _remainingHexes--; rv.Add(seedCoords); unexpanded.Add(seedCoords); continue; } } attempts++; } while ((_remainingHexes > 0) && !_finalizeEarly) { if (unexpanded.Count == 0) { if (AllowsReexpansion && (expandAgain.Count() > 0)) { unexpanded = expandAgain; } else { break; } } // Pick a hex to expand at random from the unexpanded list Coords startPoint = unexpanded[_rand.GenerateInt(unexpanded.Count)]; Dictionary <Hex.Side, Coords> adj = GetFilteredAdjacency(startPoint); // Determine at random how many hexes will be affected in this expansion // (i.e. how many adjacent hexes we'll attempt to modify in this round) int roll = RollBaseExpansion(adj.Count + 1) + RollModifier(); List <Hex.Side> contigs = FindNContiguousValidSides(startPoint, roll); if (contigs.Count > 0) { Hex.Side placeSide = contigs[_rand.GenerateInt(contigs.Count)]; int count = 0; // Try to modify as many contiguous hexes as we randomly determined we would while (count < roll) { if (adj.ContainsKey(placeSide)) { Coords placeLoc = adj[placeSide]; bool placed = ModHex(placeLoc); if (placed) { rv.Add(placeLoc); _remainingHexes--; unexpanded.Add(placeLoc); } } placeSide = Hex.RotateSideClockwise(placeSide); count++; } } // We've now expanded from these coords; remove them from the unexpanded list unexpanded.Remove(startPoint); // But if there are more adjacent hexes to expand to than we expanded into this round, // we can add this hex into the expand-again list if (roll < adj.Count) { expandAgain.Add(startPoint); } } // Go through all remaining Coords that were not expanded from, and do something with // their adjacent hexes, depending on the implementation of FinishAdjacentUnexpanded(). foreach (Coords remainder in unexpanded) { Dictionary <Hex.Side, Coords> toGo = GetFilteredAdjacency(remainder); foreach (Coords toGoInstance in toGo.Values) { FinishAdjacentUnexpanded(toGoInstance); } } return(rv); }
/** * <summary> * Hex modification method for HumidityExpander attempts to lower the * HumidityLevel of the Hex at given Coords by one step. See * <see cref="HexMap.Aridify(Coords)"/>. * </summary> * <param name="coords">Coords of the Hex to raise.</param> */ protected override bool LayeredModHex(Coords coords) { return(_map.Aridify(coords)); }
/** <summary> * Method called on all hexes adjacent to hexes that were not expanded from * (i.e. hexes that could have been expanded from, but we hit some end condition, * like reaching the total number of desired hexes, before that happened). * </summary> * <param name="coords">Coords of a hex adjacent to some unexpanded hex.</param> */ protected abstract void FinishAdjacentUnexpanded(Coords coords);
/** <summary> * Attempt to modify the given hex in accordance with whatever this * expansion is trying to do (e.g. change the elevation). * </summary> * <param name="coords">Coords for which the corresponding hex will be possibly modified.</param> * <returns>True if the hex at coords was successfully modified, false otherwise.</returns> */ protected abstract bool ModHex(Coords coords);
// ------------ Abstract methods ------------ // These methods must be overridden to dictate the rules of expansion. /** <summary> * Determines the criteria that constitutes a valid or invalid destination * or expansion. * </summary> * <param name="coords">Coords for which to check validity of expansion.</param> * <returns>True if coords are valid to expand to, false otherwise.</returns> */ protected abstract bool CanExpandTo(Coords coords);
public void SetBiomeAt(Biome biome, Coords coords) { Hex hex = GetHexAt(coords); hex.HexBiome = biome; }
/** * <summary> * Equality comparison for two Coords objects. Two Coords instances are considered * equal if the x and y values are both equal. * </summary> * <param name="other">The other Coords object with which to check equality.</param> * <returns>True if the Coords have equal x and y, false otherwise.</returns> */ public bool Equals(Coords other) { return(Equals(other, this)); }
public Color BiomeColorAt(Coords coords) { return(GetHexAt(coords).GetBiomeColor()); }
/** * <summary> * Returns the base Color of the Hex at the specified Coords. * Color is Specific to the broad type of hex (e.g. land, ocean). * </summary> * <param name="coords">The Coords for the Hex to be queried.</param> * <returns>The Color of the Hex at the specified Coords.</returns> */ public Color BaseColorAt(Coords coords) { return(_map[coords.x, coords.y].GetBaseColor()); }
/** * <summary> * Sets the TemperatureLevel of the Hex at the given Coords to the specified level. * </summary> * <param name="coords">Coords of the Hex to update.</param> * <param name="temperature">New temperature for the Hex at <paramref name="coords"/>.</param> */ public void SetTemperatureAt(Coords coords, Hex.TemperatureLevel temperature) { Hex hex = GetHexAt(coords); hex.Temperature = temperature; }
/** * <summary> * Returns the Color of the Hex at the specified Coords. * This Color should be based on the ElevationLevel of that Hex. * </summary> * <param name="coords">The Coords of the Hex to be queried.</param> * <returns>The elevation-based Color of the Hex at the specified coordinates.</returns> */ public Color ElevationColorAt(Coords coords) { return(_map[coords.x, coords.y].GetElevationColor()); }
/** * <summary> * Given some Coords and a Hex.Side, returns the Coords of the Hex that * is adjacent to the Hex at the given Coords on that side. * </summary> * <param name="coords">Coords of the central Hex to check.</param> * <param name="side">Side on which to determine adjacency.</param> * <returns> * Coords of the Hex adjacent to the hex at * <paramref name="coords"/> on <paramref name="side"/>. * </returns> */ public Coords GetAdjacentCoords(Coords coords, Hex.Side side) { int x = coords.x; int y = coords.y; int upShift = 0; int downShift = 0; if (x % 2 != 0) { downShift = 1; } else { upShift = -1; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x > (Width - 1)) { x = (Width - 1); } if (y > (Height - 1)) { y = (Height - 1); } Coords rv = new Coords(); switch (side) { case Hex.Side.North: rv.x = x; rv.y = y - 1; break; case Hex.Side.Northwest: rv.x = x - 1; rv.y = y + upShift; break; case Hex.Side.Northeast: rv.x = x + 1; rv.y = y + upShift; break; case Hex.Side.South: rv.x = x; rv.y = y + 1; break; case Hex.Side.Southwest: rv.x = x - 1; rv.y = y + downShift; break; case Hex.Side.Southeast: rv.x = x + 1; rv.y = y + downShift; break; default: break; } if (rv.y < 0 || rv.y > (Height - 1)) { rv.invalid = true; } if (rv.x < 0) { rv.x = (Width - 1); } else if (rv.x > (Width - 1)) { rv.x = 0; } return(rv); }
/** <summary> * Determines if a first modification in an expansion is valid. * Similar to CanExpandTo(), except that method is for expansions after the first, * and this is for the initial placement. * </summary> * <param name="coords">Coords to check for validity.</param> * <returns>True if <paramref name="coords"/> are okay for first expansion, false otherwise.</returns> */ protected virtual bool CanExpandFirst(Coords coords) { return(true); }