/// <summary> /// Load a building from Config /// </summary> /// <param name="config"></param> /// <returns></returns> private BuildingData LoadBuilding(Config config, string key) { // Create the building data BuildingData data = new BuildingData(); data.Key = key; data.Name = config.GetStringValue(key, "title", ""); data.Type = DataType.Building; data.InToolbox = config.GetBoolValue(key, "toolbox", false); data.ImageName = config.GetStringValue(key, "image", ""); data.IconImageName = config.GetStringValue(key, "icon", null); data.FootprintImageName = config.GetStringValue(key, "footprint", ""); data.ImageOffsetY = config.GetIntValue(key, "imageOffsetY", 0); data.ImageOffsetX = config.GetIntValue(key, "imageOffsetX", 0); data.FootprintOffsetY = config.GetIntValue(key, "footprintOffsetY", 0); data.FootprintOffsetX = config.GetIntValue(key, "footprintOffsetX", 0); data.Cost = config.GetIntValue(key, "cost", 0); data.Specs = new Dictionary <BuildingStat, int>(); // Load the specs into an enum and int pair var specsString = config.GetStringValue(key, "specs", ""); if (!string.IsNullOrEmpty(specsString)) { var specs = specsString.Split(';'); foreach (var spec in specs) { var nameValue = spec.Split(','); if (nameValue.Length != 2) { string msg = string.Format("Invalid Catalog.ini file. Element {0} ({1}) did not have a name and value.", key, spec); Logger.Log(LogLevel.Error, "LoadingCatalog", msg); throw new Exception(msg); } try { BuildingStat stat = (BuildingStat)Enum.Parse(typeof(BuildingStat), nameValue[0]); int value = Int32.Parse(nameValue[1]); data.Specs.Add(stat, value); } catch (Exception e) { var msg = string.Format("Invalid Catalog.ini file. Element {0} ({1}) was an unrecognized BuildingStat-Int pair. ex: {2}", e.Message); Logger.Log(LogLevel.Error, "LoadingCatalog", msg); throw new Exception(msg); } } } return(data); }
public float GetBuildingStatValue(BuildingStat buildingStat) { float statValue = 0; switch (buildingStat.statType) { case BuildingStat.StatType.energyConsumption: { statValue = (int)energyConsumption; break; } case BuildingStat.StatType.damagePower: { if (gameObject.GetComponent <Turret>() != null) { statValue = gameObject.GetComponent <Turret>().power; } else if (gameObject.GetComponent <ShockSatellite>() != null) { statValue = gameObject.GetComponent <ShockSatellite>().damagePower; } else if (gameObject.GetComponent <StormSatellite>() != null) { statValue = gameObject.GetComponent <StormSatellite>().damagePower; } break; } case BuildingStat.StatType.range: { statValue = (int)range; break; } case BuildingStat.StatType.energyProduction: { if (gameObject.GetComponent <PowerPlant>() != null) { statValue = (int)gameObject.GetComponent <PowerPlant>().effectiveEnergyProduction; // Changed from base to effectiveEnergyProduction, to take population bonus into account } break; } case BuildingStat.StatType.freezingPower: { if (gameObject.GetComponent <FreezingTurret>() != null) { statValue = gameObject.GetComponent <FreezingTurret>().freezingSpeed; } break; } case BuildingStat.StatType.healingPower: { if (gameObject.GetComponent <HealingTurret>() != null) { statValue = gameObject.GetComponent <HealingTurret>().healingPower; } break; } case BuildingStat.StatType.miningSpeed: { if (gameObject.GetComponent <MineBuilding>() != null) { statValue = gameObject.GetComponent <MineBuilding>().productionDelay; } break; } } return(statValue); }