protected int[] countClimateNeighbours(Province province) { int[] climate_count = new int[6] { 0, 0, 0, 0, 0, 0 }; SystemCoordinates coords = null; for (int i = 0; i < 8; i++) { coords = province.Coordinates.GetNeighbour(i); // ignore areas outside of the world. if (coords.isInTileGridBounds()) { switch (Program.State.ProvinceGrid[coords.X, coords.Y].LocalClimate) { case Climate.Arctic: climate_count[0] += 1; break; case Climate.SubArctic: climate_count[1] += 1; break; case Climate.Temperate: climate_count[2] += 1; break; case Climate.SubTropical: climate_count[3] += 1; break; case Climate.Tropical: climate_count[4] += 1; break; case Climate.Inferno: climate_count[5] += 1; break; default: break; } } } return(climate_count); }
private List <Province> newExpansionProvinces(Province province) { List <Province> target_provinces = new List <Province>(); for (int i = 0; i < 8; i++) { SystemCoordinates coords = province.Coordinates.GetNeighbour(i); if (coords.isInTileGridBounds()) { Province neighbour_province = Program.State.getProvince(coords); // Ignore this if it is already part of the territory. if (_commanded_nation.Territory.Contains(neighbour_province)) { continue; } // Do not duplicate provinces in this list. if (ExpansionTargetProvinces.Contains(neighbour_province)) { continue; } if (_commanded_nation.isNomadic) { target_provinces.Add(neighbour_province); } else if (!neighbour_province.hasOwner) { target_provinces.Add(neighbour_province); } } } return(target_provinces); }
public override int Effect(Deity creator) { // Create the river River river = new River(Program.GenerateNames.GetName("river_names"), SelectedProvince, creator); river.BiomeType = BiomeType.PermanentRiver; river.Spring = (MountainRange)SelectedProvince.PrimaryTerrainFeature; river.Riverbed.Add(river.Spring.Province); // the primary direction of the river. Array directions = Enum.GetValues(typeof(Direction)); Direction primary_direction = (Direction)directions.GetValue(rnd.Next(directions.Length)); Direction[] other_directions = new Direction[2]; switch (primary_direction) { case Direction.North: other_directions[0] = Direction.East; other_directions[1] = Direction.West; break; case Direction.East: other_directions[0] = Direction.South; other_directions[1] = Direction.North; break; case Direction.South: other_directions[0] = Direction.East; other_directions[1] = Direction.West; break; case Direction.West: other_directions[0] = Direction.North; other_directions[1] = Direction.South; break; } bool[] not_taken_other_direction = new bool[2] { true, true }; Province current_location = SelectedProvince; bool not_has_found_destination = true; while (not_has_found_destination) { // Check if there are any lakes and/or rivers in this area, then let this new river flow into a random one. if (current_location.SecondaryTerrainFeatures.Exists(x => x.GetType() == typeof(Lake)) || current_location.SecondaryTerrainFeatures.Exists(y => y.GetType() == typeof(River))) { List <TerrainFeatures> lakes_and_rivers = current_location.SecondaryTerrainFeatures.FindAll(x => x.GetType() == typeof(Lake) || x.GetType() == typeof(River)); TerrainFeatures destination = lakes_and_rivers[rnd.Next(lakes_and_rivers.Count)]; if (typeof(Lake) == destination.GetType()) { river.DestinationLake = (Lake)destination; ((Lake)destination).SourceRivers.Add(river); } else { river.DestinationRiver = (River)destination; ((River)destination).SourceRivers.Add(river); } not_has_found_destination = false; } else { // else go towards terrain... int chance = rnd.Next(100); Direction next_direction = Direction.North; // ...straight in primary direction if (chance < 50) { next_direction = primary_direction; not_taken_other_direction[0] = true; not_taken_other_direction[1] = true; } // ... turn clock-wise from primary direction else if (chance < 75 && not_taken_other_direction[0]) { next_direction = other_directions[0]; not_taken_other_direction[1] = false; } // ... turn counter-clock-wise from primary direction else if (chance < 100 && not_taken_other_direction[1]) { next_direction = other_directions[1]; not_taken_other_direction[0] = false; } SystemCoordinates coords = null; switch (next_direction) { case Direction.North: coords = current_location.Coordinates.North; break; case Direction.East: coords = current_location.Coordinates.East; break; case Direction.South: coords = current_location.Coordinates.South; break; case Direction.West: coords = current_location.Coordinates.West; break; } if (coords.isInTileGridBounds()) { // Assign next location current_location = Program.State.ProvinceGrid[coords.X, coords.Y]; } else { current_location = null; } if (current_location != null) { // if that new area is ocean the river ends here. if (current_location.Type == TerrainType.Ocean || current_location.Type == TerrainType.Island) { river.Riverbed.Add(current_location); river.Destination = current_location; not_has_found_destination = false; } // otherwise the river runs further. else { river.Riverbed.Add(current_location); } } else // if current location is null then the border of the map has been found and the river ends in unknown land. { river.Destination = new Province(null, null); river.Destination.Type = TerrainType.Unknown; river.Destination.Name = "Unknown Land"; river.Riverbed.Add(river.Destination); not_has_found_destination = false; } } } // Add river to terrains at the end in order to avoid the river ending in itself. foreach (Province province in river.Riverbed) { if (province.Type != TerrainType.Unknown) { province.SecondaryTerrainFeatures.Add(river); } } river.Modifiers.NaturalDefenceValue += 1; // Add river to deity list. creator.TerrainFeatures.Add(river); creator.LastCreation = river; Program.WorldHistory.AddRecord(river, river.printTerrainFeature); return(0); }
private List <WeightedObjects <Province> > candidate_provinces() { List <WeightedObjects <Province> > possible_locations = new List <WeightedObjects <Province> >(); foreach (Province province in _settling_area.Provinces) { WeightedObjects <Province> candidate_province = new WeightedObjects <Province>(province); if (province.SettledRaces.Contains(_commanded_race)) { continue; } // Aquatic, exclude all areas, which do not have water to live in. if (_commanded_race.Habitat == RacialHabitat.Aquatic) { if (!(province.Type == TerrainType.Ocean) && !(province.SecondaryTerrainFeatures.Exists(x => x.GetType() == typeof(Lake)))) { continue; } } // Subterranean, exlude all areas, which do not have an underworld or caves. if (_commanded_race.Habitat == RacialHabitat.Subterranean) { if (!province.SecondaryTerrainFeatures.Exists(x => x.GetType() == typeof(Cave))) { continue; } } // Terranean, exclude all areas which do not include a landmass to live on if (_commanded_race.Habitat == RacialHabitat.Terranean) { if (province.Type == TerrainType.Ocean) { continue; } } // Settle in areas close by. for (int i = 0; i < 8; i++) { SystemCoordinates coords = province.Coordinates.GetNeighbour(i); if (coords.isInTileGridBounds()) { if (Program.State.getProvince(coords).SettledRaces.Contains(_commanded_race)) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } } } foreach (RacialPreferredHabitatTerrain terrain in _commanded_race.PreferredTerrain) { switch (terrain) { case RacialPreferredHabitatTerrain.CaveDwellers: if (province.SecondaryTerrainFeatures.FindAll(x => x.GetType() == typeof(Cave)).Count > 0) { candidate_province.Weight += province.SecondaryTerrainFeatures.FindAll(x => x.GetType() == typeof(Cave)).Count * 10; } break; case RacialPreferredHabitatTerrain.DesertDwellers: if (province.PrimaryTerrainFeature.GetType() == typeof(Desert)) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case RacialPreferredHabitatTerrain.ForestDwellers: if (province.PrimaryTerrainFeature.GetType() == typeof(Forest)) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case RacialPreferredHabitatTerrain.HillDwellers: if (province.Type == TerrainType.HillRange) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case RacialPreferredHabitatTerrain.MountainDwellers: if (province.Type == TerrainType.MountainRange) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case RacialPreferredHabitatTerrain.PlainDwellers: if (province.Type == TerrainType.Plain) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; } } foreach (RacialPreferredHabitatClimate climate in _commanded_race.PreferredClimate) { switch (climate) { case RacialPreferredHabitatClimate.Arctic: if (province.LocalClimate == Climate.Arctic) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } break; case RacialPreferredHabitatClimate.Subarctic: if (province.LocalClimate == Climate.SubArctic) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } break; case RacialPreferredHabitatClimate.Tropical: if (province.LocalClimate == Climate.Tropical) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } break; case RacialPreferredHabitatClimate.Subtropical: if (province.LocalClimate == Climate.SubTropical) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } break; case RacialPreferredHabitatClimate.Temperate: if (province.LocalClimate == Climate.Temperate) { candidate_province.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } break; } } if (candidate_province.Weight > 0) { possible_locations.Add(candidate_province); } } return(possible_locations); }
protected Province selectProvince() { List <WeightedObjects <Province> > weighted_provinces = new List <WeightedObjects <Province> >(); List <Province> obsolete_provinces = new List <Province>(); foreach (Province province in PotentialProvinces) { bool add_province = true; add_province = selectionModifier(province); // Do not change the primary terrain feature more than once. if (!province.isDefault && isPrimary) { add_province = false; obsolete_provinces.Add(province); } foreach (Modifier modifier in province.ProvincialModifiers) { if (modifier.Forbids != null) { for (int i = 0; i < modifier.Forbids.Length; i++) { if (Tags.Contains(modifier.Forbids[i])) { add_province = false; } } } } if (add_province) { weighted_provinces.Add(new WeightedObjects <Province>(province)); } } foreach (Province province in obsolete_provinces) { PotentialProvinces.Remove(province); } foreach (WeightedObjects <Province> weighted_province in weighted_provinces) { weighted_province.Weight += 5; foreach (Modifier modifier in weighted_province.Object.ProvincialModifiers) { if (modifier.IncreasesWeight != null) { for (int i = 0; i < modifier.IncreasesWeight.Length; i++) { if (Tags.Contains(modifier.IncreasesWeight[i])) { weighted_province.Weight += WeightChange; } } } } // Primary terrain features are more likely to appear next to each other. if (isPrimary) { for (int i = 0; i < 8; i++) { SystemCoordinates coords = weighted_province.Object.Coordinates; coords = coords.GetNeighbour(i); if (coords.isInTileGridBounds()) { if (Program.State.ProvinceGrid[coords.X, coords.Y].PrimaryTerrainFeature.GetType() == weighted_province.Object.PrimaryTerrainFeature.GetType()) { weighted_province.Weight += WeightChange; } } } } } return(WeightedObjects <Province> .ChooseRandomObject(weighted_provinces, rnd)); }