private static List<IPerson> GeneratePopulation(int id, ICivilization civilization, int popCount) { List<IPerson> population = new List<IPerson>(); for (int n = 0; n < popCount; n++) { //Thread.Sleep(_Random.Next(200, 700)); PersonHelper personHelper = new PersonHelper(); personHelper.Civilization = civilization; personHelper.Race = civilization.Race; personHelper.Mythology = civilization.Race.Mythos; // maybe we should check the population levels before starting the next loop? First thing in the for loop? IPopulationCenters popCenter = civilization.PopulationCenters.First(pc => pc.Population.Count < pc.MaxPopulation); personHelper.OriginatesFrom = popCenter; // WHAT HAPPENS WHEN WE RUN OUT OF CITIES!? personHelper.Father = new Person(); personHelper.Mother = new Person(); personHelper.Partner = new Person(); PersonGen personGen = new PersonGen(); IPerson person = personGen.GenerateSingle(personHelper); population.Add(person); popCenter.Population.Add(person); if (n < 9) person.SocialStatus = CoreEnums.Status.Highborne; WriteToConsole("ID: " + id + "Name: " + population.Last().Name + "; Race: " + population.Last().Race.Name); } return population; }
/// <summary> /// Generates a single Hamlet. /// </summary> /// <returns></returns> public IPopulationCenters GenerateSingle(ICivilization civilization) { IPopulationCenters center = null; if (!civilization.RegionsOwned.Last().CanSupportAdditionalPopulationCenters()) return center; // as long as the last region has available centers we can keep going center = new Hamlet(); // we start with a hamlet and move up as population increases return CreateCenter(civilization, center); }
public Player(ICivilization civilization, string name) { isDead = false; cities = new List<City>(); units = new List<Unit>(); this.civilization = civilization; Name = name; Head = null; OnPropertyChanged("CitiesCount"); OnPropertyChanged("Units"); }
public static void CreateGame(int difficulty, int competition, ICivilization tribe, string leaderName = null, string tribeName = null, string tribeNamePlural = null) { if (_instance != null) { Log("ERROR: Game instance already exists"); return; } _instance = new Game(difficulty, competition, tribe, leaderName, tribeName, tribeNamePlural); foreach (IUnit unit in _instance._units) { unit.Explore(); } }
public bool AreAtWar(ICivilization civOne, ICivilization civTwo) { if (civOne.Template.IsBarbaric || civTwo.Template.IsBarbaric) { return(true); } else { return(ActiveWars.Where(data => (data.Attacker == civOne && data.Defender == civTwo) || (data.Attacker == civTwo && data.Defender == civOne) ).Count() > 0); } }
private IOngoingDeal BuildOngoingDeal( ICivilization sender, ICivilization receiver, out Mock <IOngoingDeal> mock ) { mock = new Mock <IOngoingDeal>(); mock.SetupAllProperties(); mock.Setup(deal => deal.Sender).Returns(sender); mock.Setup(deal => deal.Receiver).Returns(receiver); var newDeal = mock.Object; return(newDeal); }
private IPlayer BuildPlayer(ICivilization controlledCiv, IPlayerBrain brain) { var mockPlayer = new Mock <IPlayer>(); mockPlayer.Setup(player => player.ControlledCiv).Returns(controlledCiv); mockPlayer.Setup(player => player.Brain).Returns(brain); mockPlayer.Setup(player => player.Name).Returns(controlledCiv.Template.Name); var newPlayer = mockPlayer.Object; AllPlayers.Add(newPlayer); return(newPlayer); }
private void InputLeaderName() { if (Common.HasScreenType <Input>()) { return; } ICivilization civ = _tribesAvailable[_tribe]; Input input = new Input(Palette, civ.Leader.Name, 6, 5, 11, OffsetX + 168, OffsetY + 105, 109, 10, 13); input.Accept += LeaderName_Accept; input.Cancel += LeaderName_Accept; Common.AddScreen(input); }
public YieldSummary GetYieldOfCell(IHexCell cell, ICivilization perspectiveCiv) { if (cell == null) { throw new ArgumentNullException("cell"); } YieldSummary retval = YieldSummary.Empty; ICity cityOwningCell = CellPossessionCanon.GetOwnerOfPossession(cell); retval += InherentYieldLogic.GetInherentCellYield(cell, false); var nodeAtLocation = NodePositionCanon.GetPossessionsOfOwner(cell).FirstOrDefault(); var visibleResources = TechCanon.GetResourcesVisibleToCiv(perspectiveCiv); var improvementOnCell = ImprovementLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault(); var discoveredTechs = TechCanon.GetTechsDiscoveredByCiv(perspectiveCiv); bool hasFreshWater = FreshWaterCanon.HasAccessToFreshWater(cell); if (cityOwningCell != null) { var buildingsOnCell = BuildingPossessionCanon.GetPossessionsOfOwner(cityOwningCell) .Select(building => building.Template); retval += BuildingYieldLogic.GetBonusCellYieldFromBuildings(cell, buildingsOnCell); } if (nodeAtLocation != null) { retval += NodeYieldLogic.GetYieldFromNode(nodeAtLocation, visibleResources, improvementOnCell); } if (improvementOnCell != null) { retval += ImprovementYieldLogic.GetYieldOfImprovement( improvementOnCell, nodeAtLocation, visibleResources, discoveredTechs, hasFreshWater ); } if (perspectiveCiv != null && GoldenAgeCanon.IsCivInGoldenAge(perspectiveCiv) && retval[YieldType.Gold] > 0f) { retval[YieldType.Gold] += CivConfig.GoldenAgeBonusGoldOnCells; } return(retval); }
private void DecomposeTechs(SerializableCivilizationData civData, ICivilization newCiv) { if (civData.TechQueue != null) { for (int i = 0; i < civData.TechQueue.Count; i++) { var techName = civData.TechQueue[i]; var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(techName)).FirstOrDefault(); if (techOfName == null) { throw new InvalidOperationException(string.Format("CivData.TechQueue had invalid tech name {0} in it", techName)); } newCiv.TechQueue.Enqueue(techOfName); } } if (civData.DiscoveredTechs != null) { foreach (var discoveredTechName in civData.DiscoveredTechs) { var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(discoveredTechName)).FirstOrDefault(); if (techOfName == null) { throw new InvalidOperationException( string.Format("CivData.DiscoveredTechs had invalid tech name {0} in it", discoveredTechName) ); } TechCanon.SetTechAsDiscoveredForCiv(techOfName, newCiv); } } if (civData.ProgressOnTechs != null) { foreach (var techInProgressName in civData.ProgressOnTechs.Keys) { var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(techInProgressName)).FirstOrDefault(); if (techOfName == null) { throw new InvalidOperationException( string.Format("CivData.ProgressOnTechs had invalid tech name {0} in it", techInProgressName) ); } TechCanon.SetProgressOnTechByCiv(techOfName, newCiv, civData.ProgressOnTechs[techInProgressName]); } } }
private bool HasDomesticPortCity(IHexCell cell, ICivilization domesticCiv) { var cityAtCell = CityLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault(); if (cityAtCell != null && CityPossessionCanon.GetOwnerOfPossession(cityAtCell) == domesticCiv) { var buildingsInCity = BuildingPossessionCanon.GetPossessionsOfOwner(cityAtCell); return(buildingsInCity.Any(building => building.Template.ProvidesOverseaConnection)); } else { return(false); } }
public YieldSummary GetYieldOfCellForCity(IHexCell cell, ICity city) { if (cell == null) { throw new ArgumentNullException("slot"); } else if (city == null) { throw new ArgumentNullException("city"); } ICivilization owner = CityPossessionCanon.GetOwnerOfPossession(city); return(CellYieldLogic.GetYieldOfCell(cell, owner) * GetMultiplier(city)); }
public IEnumerable <ISocialPolicyBonusesData> GetPolicyBonusesForCiv(ICivilization civ) { var retval = GetPoliciesUnlockedFor(civ).Select(policy => policy.Bonuses); retval = retval.Concat( GetTreesUnlockedFor(civ).Select(tree => tree.UnlockingBonuses) ); retval = retval.Concat( GetTreesUnlockedFor(civ).Where(tree => IsTreeCompletedByCiv(tree, civ)) .Select(tree => tree.CompletionBonuses) ); return(retval); }
private bool DoAllCitiesHaveTemplate(IBuildingTemplate template, ICivilization owner) { var allCities = CityPossessionCanon.GetPossessionsOfOwner(owner); foreach (var city in allCities) { var templatesOf = BuildingPossessionCanon.GetPossessionsOfOwner(city).Select(building => building.Template); if (!templatesOf.Contains(template)) { return(false); } } return(true); }
private IUnit BuildUnit(UnitPositionCanonTestData.UnitData unitData, ICivilization domesticCiv, ICivilization foreignCiv) { var mockUnit = new Mock <IUnit>(); mockUnit.Setup(unit => unit.Type).Returns(unitData.Type); mockUnit.Setup(unit => unit.MaxMovement).Returns(unitData.MaxMovement); mockUnit.Setup(unit => unit.MovementSummary).Returns(unitData.MovementSummary); var newUnit = mockUnit.Object; MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)) .Returns(unitData.BelongsToDomesticCiv ? domesticCiv : foreignCiv); return(newUnit); }
private void ExecuteLockingSequence( ResourceLockingCanon lockingCanon, List <LockingType> sequence, IResourceDefinition resource, ICivilization civ ) { foreach (var lockingOperation in sequence) { switch (lockingOperation) { case LockingType.Lock: lockingCanon.LockCopyOfResourceForCiv(resource, civ); break; case LockingType.Unlock: lockingCanon.UnlockCopyOfResourceForCiv(resource, civ); break; } } }
public void SetCellAsExploredByCiv(IHexCell cell, ICivilization civ) { HashSet <ICivilization> explorationData; if (!CivsHavingExploredCell.TryGetValue(cell, out explorationData)) { explorationData = new HashSet <ICivilization>(); CivsHavingExploredCell[cell] = explorationData; } if (explorationData.Add(civ)) { VisibilitySignals.CellBecameExploredByCiv.OnNext(new Tuple <IHexCell, ICivilization>(cell, civ)); } }
private IUnit BuildUnit(ICivilization owner, int hitpoints, UnitType type, out Mock <IUnit> unitMock) { unitMock = new Mock <IUnit>(); unitMock.SetupAllProperties(); unitMock.Setup(unit => unit.CurrentHitpoints).Returns(hitpoints); unitMock.Setup(unit => unit.Type).Returns(type); var newUnit = unitMock.Object; MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner); return(newUnit); }
private IUnit BuildUnit(IHexCell location, ICivilization owner, int currentMovement) { var mockUnit = new Mock <IUnit>(); mockUnit.SetupAllProperties(); var newUnit = mockUnit.Object; newUnit.CurrentMovement = currentMovement; MockUnitPositionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(location); MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner); return(newUnit); }
private IHexCell BuildHexCell( FocusedHexCellTestData testData, ICivilization domesticCiv, ICivilization foreignCiv ) { var newCell = new Mock <IHexCell>().Object; MockCivTerritoryLogic.Setup(logic => logic.GetCivClaimingCell(newCell)) .Returns(testData.OwnedByDomesticCiv ? domesticCiv : foreignCiv); if (testData.HasCity) { BuildCity(newCell); } return(newCell); }
public override IOngoingDiplomaticExchange ExecuteBetweenCivs(ICivilization fromCiv, ICivilization toCiv) { if (!CanExecuteBetweenCivs(fromCiv, toCiv)) { throw new InvalidOperationException("CanExecuteBetweenCivs must return true for the given arguments"); } var ongoingExchange = Container.Instantiate <ResourceOngoingDiplomaticExchange>(); ongoingExchange.ResourceInput = ResourceInput; ongoingExchange.IntegerInput = IntegerInput; ongoingExchange.Sender = fromCiv; ongoingExchange.Receiver = toCiv; return(ongoingExchange); }
private IUnit BuildUnit(ICivilization owner, int currentHipoints, int maxHitpoints, UnitType type) { var mockUnit = new Mock <IUnit>(); mockUnit.SetupAllProperties(); mockUnit.Setup(unit => unit.MaxHitpoints).Returns(maxHitpoints); mockUnit.Setup(unit => unit.Type).Returns(type); var newUnit = mockUnit.Object; newUnit.CurrentHitpoints = currentHipoints; MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner); return(newUnit); }
public IPopulationCenters Upgrade(ICivilization civilization, IPopulationCenters center) { IPopulationCenters upgrade = null; if (!civilization.RegionsOwned.Last().CanSupportAdditionalPopulationCenters()) return upgrade; // as long as the last region has available centers we can keep going if (!center.GetType().Name.ToLower().Equals("metropolis")) { upgrade = PopulationCenterFactory.Get(center.GetType().Name); } else // we have a metropolis. Generate a new Hamlet now. { return GenerateSingle(civilization); } return CreateCenter(civilization, upgrade); }
private IHexCell BuildCell(bool hasRoads, ICivilization owner, IEnumerable <IImprovement> improvements) { var mockCell = new Mock <IHexCell>(); mockCell.SetupAllProperties(); var newCell = mockCell.Object; newCell.HasRoads = hasRoads; MockImprovementLocationCanon.Setup(canon => canon.GetPossessionsOfOwner(newCell)).Returns(improvements); MockCivTerritoryLogic.Setup(logic => logic.GetCivClaimingCell(newCell)).Returns(owner); return(newCell); }
public int GetProgressOnTechByCiv(ITechDefinition tech, ICivilization civilization) { if (!ProgressByCivAndTech.ContainsKey(civilization)) { ProgressByCivAndTech[civilization] = new Dictionary <ITechDefinition, int>(); } var civProgressDict = ProgressByCivAndTech[civilization]; if (!civProgressDict.ContainsKey(tech)) { civProgressDict[tech] = 0; } return(civProgressDict[tech]); }
private ICity BuildCity(int population, ICivilization owner, List <IBuilding> buildings = null) { var mockCity = new Mock <ICity>(); mockCity.SetupAllProperties(); var newCity = mockCity.Object; newCity.Population = population; MockCityPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newCity)).Returns(owner); MockBuildingPossessionCanon.Setup(canon => canon.GetPossessionsOfOwner(newCity)).Returns(buildings); return(newCity); }
private void SetVisibility(IHexCell cell, ICivilization civ, int value) { Dictionary <ICivilization, int> visibilityDictForCell; if (!VisibilityOfCellToCiv.ContainsKey(cell)) { visibilityDictForCell = new Dictionary <ICivilization, int>(); VisibilityOfCellToCiv[cell] = visibilityDictForCell; } else { visibilityDictForCell = VisibilityOfCellToCiv[cell]; } visibilityDictForCell[civ] = value; }
public int GetUnhappinessOfCiv(ICivilization civ) { if (civ == null) { throw new ArgumentNullException("civ"); } int retval = 0; foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ)) { retval += CityHappinessLogic.GetUnhappinessOfCity(city); } return(retval); }
public ResourceTransfer ExportCopiesOfResource( IResourceDefinition resource, int copies, ICivilization exporter, ICivilization importer ) { if (!CanExportCopiesOfResource(resource, copies, exporter, importer)) { throw new InvalidOperationException("CanExportCopiesOfResource must return true on the given arguments"); } var newTransfer = new ResourceTransfer(exporter, importer, resource, copies); AllActiveTransfers.Add(newTransfer); return(newTransfer); }
public IEnumerable <IResourceDefinition> GetResourcesVisibleToCiv(ICivilization civilization) { var retval = new HashSet <IResourceDefinition>(AvailableResources); foreach (var tech in AvailableTechs) { if (!IsTechDiscoveredByCiv(tech, civilization)) { foreach (var resource in tech.RevealedResources) { retval.Remove(resource); } } } return(retval); }
public void SetTechAsUndiscoveredForCiv(ITechDefinition tech, ICivilization civilization) { if (tech == null) { throw new ArgumentNullException("tech"); } else if (civilization == null) { throw new ArgumentNullException("civilization"); } if (IsTechDiscoveredByCiv(tech, civilization)) { TechsResearchedByCiv[civilization].Remove(tech); CivSignals.CivUndiscoveredTech.OnNext(new System.Tuple <ICivilization, ITechDefinition>(civilization, tech)); } }
private ICity BuildCity(CityTestData cityData, IHexCell location, ICivilization owner) { var newCity = new Mock <ICity>().Object; MockBuildingPossessionCanon.Setup(canon => canon.GetPossessionsOfOwner(newCity)) .Returns(cityData.Buildings.Select(buildingData => BuildBuilding(buildingData))); MockCityLocationCanon.Setup(canon => canon.GetOwnerOfPossession(newCity)).Returns(location); MockCityLocationCanon.Setup(canon => canon.GetPossessionsOfOwner(location)).Returns(new List <ICity>() { newCity }); MockCityPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newCity)).Returns(owner); return(newCity); }
private void AddUnitProjects(ICivilization cityOwner) { foreach (var unitTemplate in TechCanon.GetResearchedUnits(cityOwner)) { var newRecord = BuildRecord(); newRecord.UnitTemplate = unitTemplate; newRecord.SelectionButton.interactable = UnitValidityLogic.IsTemplateValidForCity(unitTemplate, ObjectToDisplay); newRecord.SelectionButton.onClick.AddListener( () => ObjectToDisplay.ActiveProject = ProjectFactory.ConstructProject(unitTemplate) ); newRecord.Refresh(); InstantiatedProjectRecords.Add(newRecord); } }
private IHexCell BuildHexCell( NeighboringHexCellTestData testData, ICivilization domesticCiv, ICivilization foreignCiv ) { var newCell = new Mock <IHexCell>().Object; var unitsAt = new List <IUnit>(); foreach (var unitData in testData.UnitsAtCell) { unitsAt.Add(BuildUnit(unitData, newCell, unitData.BelongsToDomesticCiv ? domesticCiv : foreignCiv)); } MockUnitPositionCanon.Setup(canon => canon.GetPossessionsOfOwner(newCell)).Returns(unitsAt); return(newCell); }
private IPopulationCenters CreateCenter(ICivilization civilization, IPopulationCenters center) { center.Id = Random.Next(0, 423645245); center.Name = Names.SingleName(CoreEnums.Word.HumanPlace); // TODO: named according to race center.Description = "DESCRIPTION"; center.Civilization = civilization; center.Region = civilization.RegionsOwned.First(r => r.CanSupportAdditionalPopulationCenters()); center.Population = new List<IPerson>(); center.HasPort = false; // TODO: hard coded center.HasMarket = true; // TODO: hard coded return center; }