public ProportionValues(ProportionItem[] proportionItems) { this.proportionItems = proportionItems; weightTotal = 0; foreach (ProportionItem item in proportionItems) { weightTotal += item.Weight; } }
private void InitBuildings(List<Tile> buildableTiles) { ProportionItem clubSpawn = new ProportionItem("Club", 10); ProportionItem policeSpawn = new ProportionItem("Police", 2); ProportionItem houseSpawn = new ProportionItem("House", 10); // Might get converted to Villa, based on property value ProportionItem villaSpawn = new ProportionItem("Villa", 1); ProportionItem emptyTile = new ProportionItem("Empty", 48); // Might get converted to House, based on property value ProportionValues buildingSpawnChances = new ProportionValues(new ProportionItem[] { clubSpawn, policeSpawn, houseSpawn, villaSpawn, emptyTile }); foreach (Tile tile in buildableTiles) { var randomChoice = buildingSpawnChances.RandomChoice(); if (randomChoice.Name == "Club") AddBuilding(new ClubBuilding(), tile); else if (randomChoice.Name == "Police") AddBuilding(new PoliceBuilding(), tile); else if (randomChoice.Name == "House") { double villaChance = (Convert.ToDouble(tile.propertyValue) - Settings.Tile_BasePropertyValue) * 100 / Settings.Tile_MaxPropertyValueGainableFromHighPoint; if (Utils.PercentageRoll(villaChance)) AddBuilding(new VillaBuilding(), tile); else AddBuilding(new HouseBuilding(), tile); } else { var propertyValueHouseChance = (Convert.ToDouble(tile.propertyValue) - Settings.Tile_BasePropertyValue) * 100 / Settings.Tile_MaxPropertyValueGainableFromHighPoint; if (Utils.PercentageRoll(propertyValueHouseChance)) AddBuilding(new HouseBuilding(), tile); } } LogBuildingTypes(); Utils.Shuffle(buildings); // For customer spawning purposes Debug.LogFormat("Created {0} buildings at model level.", buildings.Count); }