public PlacesEditorF(HouseEntry entry) : this() { customFlatButtonAdd.Enabled = false; textDescription.Text = entry.Description; textX.Text = entry.Location.X.ToString(); textY.Text = entry.Location.Y.ToString(); ComboBoxFacet.SelectedIndex = entry.Map; textDescription.TextChanged += (sender, e) => { customFlatButtonAdd.Enabled = entry.Description != textDescription.Text; }; textX.TextChanged += (sender, e) => { customFlatButtonAdd.Enabled = entry.Location.X.ToString() != textX.Text; }; textY.TextChanged += (sender, e) => { customFlatButtonAdd.Enabled = entry.Location.Y.ToString() != textY.Text; }; ComboBoxFacet.SelectedIndexChanged += (sender, e) => { customFlatButtonAdd.Enabled = ComboBoxFacet.SelectedIndex != entry.Map; }; checkBoxShoNameEver.Enabled = false; ComboBoxCategory.Enabled = false; customFlatButtonAdd.Tag = entry; }
public HouseObject(HouseEntry entry) : base(entry.Description) { Entry = entry; UpdatePosition(entry.Location); IsVisible = true; }
private void AddHouse(object sender, RoutedEventArgs e) { var house = new HouseEntry(); AddElement(house); }
public void GenerateSettlementPreview([NotNull] Simulator sim, [NotNull] SettlementTemplate template) { if (Math.Abs(template.HousePercentage - 1) > Constants.Ebsilon) { throw new DataIntegrityException( "The house size distribution doesn't add up to 100%. It is right now " + template.HousePercentage * 100 + "%"); } if (Math.Abs(template.HouseholdPercentage - 1) > Constants.Ebsilon) { throw new DataIntegrityException( "The household size distribution doesn't add up to 100%. It is right now " + template.HouseholdPercentage * 100 + "%"); } if (template.DesiredHHCount == 0) { throw new DataIntegrityException("Can't make a settlement with 0 households."); } var resultinghouseholds = new List <ICalcObject>(); var r = new Random(); MakeHouseholdDistribution(sim.ModularHouseholds.It, sim, resultinghouseholds, r, template); // find a house distribution iteratively by increasing the numbers of each house type. InitializeHouseSizes(template); var previewEntries = new List <HouseEntry>(); // make the basic assignment var housecount = 1; foreach (var stHouseSize in template.HouseSizes) { for (var i = 0; i < stHouseSize.HouseCount; i++) { var span = stHouseSize.MaximumHouseSize - stHouseSize.MinimumHouseSize; var housesize = stHouseSize.MinimumHouseSize + r.Next(span); var he = new HouseEntry(housesize, stHouseSize.MaximumHouseSize, housecount++, EnergyIntensityType.AsOriginal); previewEntries.Add(he); for (var j = 0; j < housesize && resultinghouseholds.Count > 0; j++) { var householdIndex = r.Next(resultinghouseholds.Count); he.Households.Add(resultinghouseholds[householdIndex]); resultinghouseholds.RemoveAt(householdIndex); } } } // assign the leftovers var loopcount = 0; while (resultinghouseholds.Count > 0) { foreach (var houseEntry in previewEntries) { if (houseEntry.Households.Count <= houseEntry.MaximumHouseSize && resultinghouseholds.Count > 0) { var householdIndex = r.Next(resultinghouseholds.Count); houseEntry.Households.Add(resultinghouseholds[householdIndex]); resultinghouseholds.RemoveAt(householdIndex); } } loopcount++; if (loopcount > 300) { throw new LPGException("Could not assign all households to houses. " + resultinghouseholds.Count + " was left over. Please fix somehow."); } } var filteredEntries = previewEntries.Where(x => x.Households.Count > 0).ToList(); // assign the housetypes foreach (var houseEntry in filteredEntries) { var validHouseTypes = template.HouseTypes .Where(x => houseEntry.Households.Count >= x.HouseType?.MinimumHouseholdCount && houseEntry.Households.Count <= x.HouseType?.MaximumHouseholdCount) .Select(x => x.HouseType).ToList(); if (validHouseTypes.Count == 0) { throw new DataIntegrityException("It was not possible to find a house type for a house with " + houseEntry.Households.Count + " households. Please adjust either the house sizes, add more house types " + "or adjust the existing house types to accept a wider range of household counts."); } var idx = r.Next(validHouseTypes.Count); houseEntry.HouseType = validHouseTypes[idx]; } Logger.Get().SafeExecuteWithWait(() => _previewHouseEntries.SynchronizeWithList(filteredEntries)); }