public override int Effect(Deity creator) { List <WeightedObjects <Province> > possible_target_province = candidate_provinces(); int number_of_settled_provinces = Constants.BASE_TILES_SETTLED_BY_RACE; if (_commanded_race.SocialCulturalCharacteristics.Contains(SocialCulturalCharacteristic.Nomadic)) { number_of_settled_provinces += 1; } if (_commanded_race.SocialCulturalCharacteristics.Contains(SocialCulturalCharacteristic.Sedentary)) { number_of_settled_provinces -= 1; } if (number_of_settled_provinces > possible_target_province.Count) { number_of_settled_provinces = possible_target_province.Count; } List <Province> target_provinces = WeightedObjects <Province> .ChooseXHeaviestObjects(possible_target_province, number_of_settled_provinces); foreach (Province province in target_provinces) { province.SettledRaces.Add(_commanded_race); _commanded_race.SettledProvinces.Add(province); } return(0); }
public override int Effect(Deity creator) { List <WeightedObjects <Province> > provinces = candidate_provinces(); _chosen_location = WeightedObjects <Province> .ChooseRandomObject(provinces, rnd); // change climate. switch (_chosen_location.LocalClimate) { case Climate.Arctic: _chosen_location.LocalClimate = Climate.SubArctic; break; case Climate.SubArctic: _chosen_location.LocalClimate = Climate.Temperate; break; case Climate.Temperate: _chosen_location.LocalClimate = Climate.SubTropical; break; case Climate.SubTropical: _chosen_location.LocalClimate = Climate.Tropical; break; } adjustTerrainFeatureBiomes(); return(0); }
public override int Effect(Deity creator) { TerrainFeatures terrain = WeightedObjects <TerrainFeatures> .ChooseRandomObject(potential_construction_sites(), rnd); Building building = new Building(null, creator, _type); building.Terrain = terrain; building.Effect(); terrain.Buildings.Add(building); return(0); }
public override int Effect(Deity creator) { possible_target_armies(); Army target_army = WeightedObjects <Army> .ChooseRandomObject(_possible_targets, rnd); Army attacker_army = WeightedObjects <Army> .ChooseRandomObject(_possible_attackers, rnd); // Move the armies into the same terrain. if (!target_army.Location.Equals(attacker_army.Location)) { attacker_army.Location = target_army.Location; } Battle battle = new Battle(attacker_army.Name + " vs. " + target_army.Name, creator, attacker_army, target_army, target_army.Location, _war); battle.Fight(); creator.LastCreation = null; return(0); }
private void chooseBattleLocation() { List <WeightedObjects <TerrainFeatures> > possible_battle_locations = new List <WeightedObjects <TerrainFeatures> >(); possible_battle_locations.Add(new WeightedObjects <TerrainFeatures>(Province.PrimaryTerrainFeature)); foreach (TerrainFeatures terrain in Province.SecondaryTerrainFeatures) { possible_battle_locations.Add(new WeightedObjects <TerrainFeatures>(terrain)); } foreach (WeightedObjects <TerrainFeatures> terrain in possible_battle_locations) { terrain.Weight += terrain.Object.Modifiers.NaturalDefenceValue * 10; if (Province.Owner == InvolvedArmies[1].Owner) { terrain.Weight += terrain.Object.Modifiers.FortificationDefenceValue * 10; } } Location = WeightedObjects <TerrainFeatures> .ChooseXHeaviestObjects(possible_battle_locations, 1)[0]; }
public override int Effect(Deity creator) { List <WeightedObjects <Province> > possible_locations = new List <WeightedObjects <Province> >(); foreach (Province province in _commanded_race.SettledProvinces) { if (!province.hasOwner) { possible_locations.Add(new WeightedObjects <Province>(province)); } } foreach (WeightedObjects <Province> weighted_feature in possible_locations) { weighted_feature.Weight += 5; // considers the biome of the terrain feature. switch (weighted_feature.Object.PrimaryTerrainFeature.BiomeType) { case BiomeType.BorealForest: case BiomeType.TemperateDeciduousForest: case BiomeType.TropicalDryForest: case BiomeType.TropicalRainforest: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.ForestDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case BiomeType.ColdDesert: case BiomeType.HotDesert: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.DesertDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case BiomeType.TemperateGrassland: case BiomeType.Tundra: case BiomeType.TropicalGrassland: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.GrasslandDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case BiomeType.Subterranean: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.CaveDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; } // Considers the generall type of the terrain. switch (weighted_feature.Object.Type) { case TerrainType.HillRange: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.HillDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case TerrainType.MountainRange: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.MountainDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; case TerrainType.Plain: if (_commanded_race.PreferredTerrain.Exists(x => x == RacialPreferredHabitatTerrain.PlainDwellers)) { weighted_feature.Weight += Constants.WEIGHT_STANDARD_CHANGE; } break; } } if (possible_locations.Count == 0) { return(1); } Province location = WeightedObjects <Province> .ChooseRandomObject(possible_locations, rnd); Civilisation founded_civilisation = new Civilisation("Nation of " + _commanded_race.Name, creator); founded_civilisation.PoliticalOrganisation = _polity; founded_civilisation.InhabitantRaces.Add(_commanded_race); // Nomadic? switch (founded_civilisation.PoliticalOrganisation.Organisation) { case SocialOrganisation.BandSociety: switch (founded_civilisation.PoliticalOrganisation.Form) { case PolityForm.Band: case PolityForm.Herd: case PolityForm.Pack: founded_civilisation.isNomadic = true; break; case PolityForm.Brood: founded_civilisation.isNomadic = false; break; } break; case SocialOrganisation.TribalSociety: int _dice = rnd.Next(50); if (_dice < 25) { founded_civilisation.isNomadic = true; } else { founded_civilisation.isNomadic = false; } break; } // Diplomacy if (_commanded_race.Type == SpeciesType.Beasts) { founded_civilisation.hasDiplomacy = false; } else { founded_civilisation.hasDiplomacy = true; foreach (Civilisation nation in Program.State.Civilizations) { nation.Relationships.Add(new Relations(founded_civilisation)); founded_civilisation.Relationships.Add(new Relations(nation)); } } // Cities // Nomadic civilisations do not have cities if (founded_civilisation.isNomadic) { founded_civilisation.hasCities = false; } else { founded_civilisation.hasCities = true; founded_civilisation.Cities.Add(new City("Capital City of " + founded_civilisation.Name, creator)); founded_civilisation.CapitalCity.TerrainFeature = location.PrimaryTerrainFeature; founded_civilisation.CapitalCity.Owner = founded_civilisation; location.PrimaryTerrainFeature.City = founded_civilisation.CapitalCity; } // Territory founded_civilisation.Territory.Add(location); if (founded_civilisation.isNomadic) { location.NomadicPresence.Add(founded_civilisation); } else { location.Owner = founded_civilisation; } // Add origin order -> church. This church is needed to be able to command this nation. Order founder_origin_order = new Order(Program.GenerateNames.GetName(), creator, OrderType.Church, OrderPurpose.FounderWorship); founder_origin_order.OrderNation = founded_civilisation; founder_origin_order.OrderRace = null; founded_civilisation.NationalOrders.Add(founder_origin_order); creator.CreatedOrders.Add(founder_origin_order); // Possible War Goals WarGoal war_goal; List <WarGoal> war_goals = new List <WarGoal>(); switch (founded_civilisation.PoliticalOrganisation.Organisation) { case SocialOrganisation.BandSociety: break; case SocialOrganisation.TribalSociety: break; case SocialOrganisation.Chiefdom: break; case SocialOrganisation.State: break; } founded_civilisation.PossibleWarGoals.AddRange(war_goals); // Add nation to the creator and Powers related to this nation. creator.FoundedNations.Add(founded_civilisation); Program.State.Civilizations.Add(founded_civilisation); creator.CreatedOrders.Add(founded_civilisation.OriginOrder); if (founded_civilisation.hasCities) { creator.Powers.Add(new CreateCity(founded_civilisation)); creator.FoundedCities.Add(founded_civilisation.CapitalCity); Program.State.Cities.Add(founded_civilisation.CapitalCity); } if (founded_civilisation.hasDiplomacy) { creator.Powers.Add(new ExpandTerritory(founded_civilisation)); creator.Powers.Add(new EstablishContact(founded_civilisation)); creator.Powers.Add(new FormAlliance(founded_civilisation)); creator.Powers.Add(new DeclareWar(founded_civilisation)); } foreach (Deity deity in Program.State.Deities) { // Add avatars foreach (AvatarType type in Enum.GetValues(typeof(AvatarType))) { deity.Powers.Add(new CreateAvatar(type, founded_civilisation.FoundingRace, founded_civilisation, null)); } // Add Events deity.Powers.Add(new VastGoldMineEstablised(founded_civilisation)); deity.Powers.Add(new VastGoldMineDepleted(founded_civilisation)); } foreach (Deity deity in Program.State.Deities) { if (!(deity == creator)) { deity.Powers.Add(new CreateOrder(OrderType.Church, OrderPurpose.FounderWorship, founded_civilisation, null)); } } creator.LastCreation = founded_civilisation; return(0); }
public override int Effect(Deity creator) { Civilisation war_target = candidate_nations[rnd.Next(candidate_nations.Count)]; // The war to be declared. War declared_war = new War("War of " + _commanded_nation.Name + " vs. " + war_target.Name, creator); declared_war.Attackers.Add(_commanded_nation); declared_war.Defenders.Add(war_target); // Add allies to the war. The order is important as all nations which are allied to both nations will side with the defender. foreach (Relations relation in war_target.Relationships) { if (relation.Status == RelationStatus.Allied) { declared_war.Defenders.Add(relation.Target); } } foreach (Relations relation in _commanded_nation.Relationships) { if (relation.Status == RelationStatus.Allied) { if (!declared_war.Defenders.Contains(relation.Target)) { declared_war.Attackers.Add(relation.Target); } } } List <WeightedObjects <WarGoal> >[] war_goals = new List <WeightedObjects <WarGoal> > [2]; for (int i = 0; i < 2; i++) { war_goals[i] = new List <WeightedObjects <WarGoal> >(); foreach (WarGoal war_goal in war_target.PossibleWarGoals) { war_goals[i].Add(new WeightedObjects <WarGoal>(war_goal)); } // determine the weights of each war goal. Certain types of polities can only take certain types of war goals. foreach (WeightedObjects <WarGoal> weighted_war_goal in war_goals[i]) { Civilisation taker, target; if (i == 0) { taker = _commanded_nation; target = war_target; } else { taker = war_target; target = _commanded_nation; } weighted_war_goal.Object.Winner = taker; if (taker.isNomadic) { if (target.isNomadic) { if (weighted_war_goal.Object.Type == WarGoalType.Conquest) { weighted_war_goal.Weight += Constants.WEIGHT_STANDARD_CHANGE; } else if (weighted_war_goal.Object.Type == WarGoalType.VassalizeCity) { weighted_war_goal.Weight += Constants.WEIGHT_STANDARD_CHANGE; } } } else { if (target.isNomadic) { if (weighted_war_goal.Object.Type == WarGoalType.RemoveNomadicPresence) { weighted_war_goal.Weight += Constants.WEIGHT_STANDARD_CHANGE; } } else { if (weighted_war_goal.Object.Type == WarGoalType.CityConquest) { weighted_war_goal.Weight += Constants.WEIGHT_STANDARD_CHANGE * 2; } if (weighted_war_goal.Object.Type == WarGoalType.Conquest) { weighted_war_goal.Weight += Constants.WEIGHT_STANDARD_CHANGE; } } } } } List <WarGoal> weighted_war_goals = WeightedObjects <WarGoal> .ChooseHeaviestObjects(war_goals[0]); declared_war.WarGoalAttackers = weighted_war_goals[rnd.Next(weighted_war_goals.Count)]; weighted_war_goals = WeightedObjects <WarGoal> .ChooseHeaviestObjects(war_goals[1]); declared_war.WarGoalDefenders = weighted_war_goals[rnd.Next(weighted_war_goals.Count)]; // Add war to the list of ongoing conflicts. Program.State.OngoingWars.Add(declared_war); declared_war.Begin = Simulation.Time.Shuffle; // Add powers related to the war to connected deities. // attacker related // Only the war leader can surrender as only he stands to lose anything, all other participants can only white peace. creator.Powers.Add(new SurrenderWar(_commanded_nation, declared_war)); foreach (Civilisation attacker in declared_war.Attackers) { creator.Powers.Add(new WhitePeace(attacker, declared_war)); foreach (Civilisation defender in declared_war.Defenders) { creator.Powers.Add(new AttackNation(attacker, defender, declared_war)); } } // defender related declared_war.Defenders[0].Creator.Powers.Add(new SurrenderWar(declared_war.Defenders[0], declared_war)); foreach (Civilisation defender in declared_war.Defenders) { defender.Creator.Powers.Add(new WhitePeace(defender, declared_war)); foreach (Civilisation attacker in declared_war.Defenders) { creator.Powers.Add(new AttackNation(defender, attacker, declared_war)); } } creator.LastCreation = declared_war; Program.WorldHistory.AddRecord(RecordType.WarReport, declared_war, War.printWar); 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)); }